Git Product home page Git Product logo

touchprice's Introduction

Shioaji touch order extension

PyPI - Status PyPI - Python Version PyPI - Downloads codecov Build - Status

Touchprice is an extension feature of Shioaji. Using the conditions to trigger placing order.

Installation

pip install touchprice

Quickstarts

Just import our API library like other popular python library and adding Shioaji to start using the feature of touchprice.

import touchprice as tp
import shioaji as sj

api = sj.Shioaji()
api.login("YOUR_API_KEY", "YOUR_SECRET_KEY")
api.activate_ca(CA_PATH, CA_USERID, CA_PASSWORD)
touch = tp.TouchOrderExecutor(api)

Condition

TouchOrderCond contains touch condition and order condition.

Set touch condition

touch_cmd = 
    tp.TouchCmd(
        code="2890", 
        close = tp.Price(price=11.0, trend="Up")
    )

TouchCmd arg:

  • code: str,
  • close: condition.Price = None,
  • buy_price: condition.Price = None,
  • sell_price: condition.Price = None,
  • high: condition.Price = None,
  • low: condition.Price = None,
  • volume: condition.Qty = None,
  • total_volume: condition.Qty = None,
  • ask_volume: condition.Qty = None,
  • bid_volume: condition.Qty = None,

Price arg

  • price: float = 0.0,
  • trend: constant.Trend = 'Equal' ('Up', 'Down', 'Equal')
  • price_type: constant.PriceType = 'LimitPrice' ('LimitPrice', 'LimitUp', 'Unchanged', 'LimitDown ')

Qty arg

  • qty: int,
  • trend: constant.Trend = 'Equal' ('Up', 'Down', 'Equal')

Set order condition

order_cmd = tp.OrderCmd(
    code="2890",
    order = sj.Order(
        action="Buy",
        price=10,
        quantity=1,
        order_type="ROD",
        price_type="LMT",)
    )

OrderCmd arg

  • code: str
  • order: shioaji.order.Order

Add condition to order

condition = tp.TouchOrderCond(
                touch_cmd = touch_cmd, 
                order_cmd = order_cmd
            )
touch.add_condition(condition)

Delete condition

touch.delete_condition(condition)

Show condition

If not set code can show all conditions, else just show coditions of code.

touch.show_condition(code)

Disclaimer

The package are used at your own risk.

touchprice's People

Contributors

ssallylin avatar yvictor avatar

Stargazers

Smartkao avatar  avatar duckfly-tw avatar arthurzllu avatar  avatar  avatar  avatar  avatar Yingyu Chen avatar  avatar Yoshi Huang avatar Keanu Pang avatar LU WEI-CHIEH avatar David Liao avatar Scott Cheng avatar  avatar YJ Wang avatar  avatar hp.huang avatar CT Ling avatar Tzu-Hua avatar Johnny Sung avatar Chaos Cat avatar  avatar  avatar  avatar  avatar Po Chien Yang avatar Arthur Hung avatar TWGD avatar 賴祺清 avatar lin sam avatar

Watchers

James Cloos avatar  avatar  avatar  avatar Yingyu Chen avatar

touchprice's Issues

執行範例程式 TypeError: 'NoneType' object is not iterable

環境如下
python:3.8.16
shioaji:1.1.2
touchprice:0.1.5
OS:windows10

您好 我照著範例程式執行

touch_cmd = tp.TouchCmd(
code="2890",
close = tp.Price(price=10.0, trend="Up")
)
order_cmd = tp.OrderCmd(
code="2890",
order = sj.Order(
action="Buy",
price=10,
quantity=1,
order_type="ROD",
price_type="LMT",)
)

condition = tp.TouchOrderCond(
touch_cmd = touch_cmd,
order_cmd = order_cmd
)
touch.add_condition(condition)

會出現錯誤
Cell In[4], line 19
5 order_cmd = tp.OrderCmd(
6 code="2890",
7 order = sj.Order(
(...)
12 price_type="LMT",)
13 )
15 condition = tp.TouchOrderCond(
16 touch_cmd = touch_cmd,
17 order_cmd = order_cmd
18 )
---> 19 touch.add_condition(condition)

File d:\anaconda3\envs\FinLab\lib\site-packages\touchprice\touch_price.py:84, in TouchOrderExecutor.add_condition(self, condition)
82 touch_contract = self.contracts[code]
83 self.update_snapshot(touch_contract)
---> 84 store_condition = self.adjust_condition(condition, touch_contract)
85 if store_condition:
86 if code in self.conditions.keys():

File d:\anaconda3\envs\FinLab\lib\site-packages\touchprice\touch_price.py:65, in TouchOrderExecutor.adjust_condition(self, condition, contract)
62 def adjust_condition(
63 self, condition: TouchOrderCond, contract: sj.contracts.Contract
...
67 }
68 if tconds_dict:
69 for key, value in tconds_dict.items():

TypeError: 'NoneType' object is not iterable

請問該如何解決

ubuntu 安裝後導致無法 import shioaji

2021-02-09_15-24

ubuntu 安裝後導致無法 import shioaji
系統報錯如圖
研判應該是有在相對應的 init.py 有加入下面這兩行 for windows的路徑修正
linux based os 應該用不到才對?

if sys.version_info.major == 3 and sys.version_info.minor >= 8:
    os.add_dll_directory(libs_path.as_posix())

目前把報錯的兩個 init.py 的上兩行註解掉可以正常登入
但不知道後續是否會有其他問題
/lib/python3.8/site-packages/pysolace/init.py
/lib/python3.8/site-packages/shioaji/init.py

說明檔錯誤百出

真心建議作者將自己說明檔的程式碼複製到空的文本,然後執行看看。
錯誤實在太多,根本無法執行,我以下僅簡單舉出兩個錯誤,實際上錯更多,請自行檢查...

  1. 函式已改
    tp.TouchOrder(api) (錯誤)
    tp.TouchOrderExecutor(api) (正確)

  2. 少括號
    order_cmd = tp.OrderCmd(
    code="2890",
    order = sj.Order(
    action="Buy",
    price=10,
    quantity=1,
    order_type="ROD",
    price_type="LMT",
    )
    )

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.