Giter VIP home page Giter VIP logo

sjtrade's Introduction

sjtrade

PyPI Code style: black Test and Deploy codecov Telegram Open Tutorial In Colab

shioaji day trading demo package

Install

pip install sjtrade

Get started

Init Shioaji and SjTrader

import shioaji as sj
import sjtrade

api = sj.Shioaji()
accounts = api.login(**login_kws)
sjtrader = sjtrade.SJTrader(api)

Set Position Filepath and Preview Position

sjtrader.position_filepath = "position.txt"
sjtrade.io.file.read_position(sjtrader.position_filepath)

Set Custom Position FileReader

from sjtrade.io.file import read_csv_position
sjtrader.read_position_func = read_csv_position
sjtrader.position_filepath = "position.csv"
sjtrader.read_position_func(sjtrader.position_filepath)

Set entry_pct stop_profit_pct stop_loss_pct

sjtrader.entry_pct = 0.05
sjtrader.stop_profit_pct = 0.095
sjtrader.stop_loss_pct = 0.09

Start sjtrader

sjtrader.start()

What do sjtrader start actually do

sjtrader.start??
Signature: sjtrader.start()
Source:   
    def start(self):
        positions = read_position(self._position_filepath)
        self.api.set_order_callback(self.order_deal_handler)
        sleep_until(8, 45)
        self.place_entry_order(positions, self.entry_pct)
        sleep_until(8, 54, 59)
        self.api.quote.set_on_tick_stk_v1_callback(self.cancel_preorder_handler)
        sleep_until(8, 59, 55)
        self.api.quote.set_on_tick_stk_v1_callback(self.intraday_handler)
        sleep_until(13, 25, 59)
        self.open_position_cover()
File:      ~/.pyenv/versions/miniconda3-latest/lib/python3.7/site-packages/sjtrade/trader.py
Type:      method

Simulation

all order will be place as success and deal when price touch

api = sj.Shioaji()
accounts = api.login(**login_kws)
sjtrader = sjtrade.SJTrader(api, simulation=True)
sjtrader.position_filepath = "position.txt"
sjtrade.io.file.read_position(sjtrader.position_filepath)
sjtrader.entry_pct = 0.05
sjtrader.stop_profit_pct = 0.095
sjtrader.stop_loss_pct = 0.09
sjtrader.start()

Notifications

pip install notifiers

Check notifiers

from notifiers import get_notifier
notifier = get_notifier("telegram")
TELECHATID = ""
TELEBOT_TOKEN = ""
PARAMS = {"chat_id": TELECHATID, "token": TELEBOT_TOKEN}
notifier.notify(message="test", **PARAMS)

Check logger

from loguru import logger
from notifiers.logging import NotificationHandler
handler = NotificationHandler("telegram", defaults=PARAMS)
logger.add(handler, level="INFO")
logger.info("logger test")

Developer's guide

flit install -s

sjtrade's People

Contributors

ypochien avatar yvictor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.