sinotrade / shioaji Goto Github PK
View Code? Open in Web Editor NEWShioaji all new cross platform api for trading ( 跨平台證券交易API )
Home Page: https://sinotrade.github.io/
Shioaji all new cross platform api for trading ( 跨平台證券交易API )
Home Page: https://sinotrade.github.io/
as title
通常成交明細不外乎包含:內盤價、外盤價、成交價、成交時間、成交單量
但是使用 api.quote.subscribe(api.Contracts.Stocks["2890"], quote_type='tick')
MKT/redisrd/TSE/2330 {'Close': [239.5], 'Time': '11:11:42.624718', 'VolSum': [12206], 'Volume': [5]}
只有 成交價、時間、單量、總量,缺乏內盤價跟外盤價
建議可以補上
操作
trade = api.place_order(code, new_order)
得到下面的錯誤, 會是什麼問題呢?
`
File "shioaji\backend\utils.pyx", line 95, in shioaji.backend.utils.auth.wrapper_auth
File "shioaji\backend\utils.pyx", line 31, in shioaji.backend.utils.record.wrapper_record
File "shioaji\backend\http\main.pyx", line 58, in shioaji.backend.http.main.HttpApi.place_order
File "shioaji\backend\http\order.pyx", line 76, in shioaji.backend.http.order.place_order
UnboundLocalError: local variable 'resp' referenced before assignment
`
api.active_ca(r'D:\Program Files\eleader\Cert\SinoPac.pfx','xxxxxx','myID')
只要密碼正確,ID隨便打都會顯示
Ca Initial Done. 0
應該是沒確認到憑證內id?
請問有辦法取得Account的即時股票庫存資訊嗎?
In [43]: ?api.place_order
Signature:
api.place_order(
contract:shioaji.contracts.Contract,
order:shioaji.order.Order,
timeout:int=5000,
cb:Callable[[shioaji.order.Trade], NoneType]=None,
) -> shioaji.order.Trade
Docstring:
placing order
Args:
contract (:obj:Shioaji.Contract):
order (:obj:Shioaji.Order):
pass Shioaji.Order object to place order
File: ~/code/shioaji/shioaji/shioaji.py
Type: method
In [44]: def f(trade):
...: assert False
...:
In [45]: trade = api.place_order(c, o, cb=f)
但 AssertError 並沒有出現
0.0.5dev7 正常 login 沒問題
0.0.6.dev3
login 之後遇到這個
~/venv/shioaji/lib/python3.7/site-packages/shioaji/shioaji.py in login(self, person_id, passwd)
79 if self._socket:
80 self._socket.login(person_id, passwd, self.quote)
---> 81 stock_account, future_account = self._http.login(person_id, passwd)
shioaji/backend/utils.pyx in shioaji.backend.utils.subscribe.wrapper_check()
shioaji/backend/http/main.pyx in shioaji.backend.http.main.HttpApi.login()
shioaji/backend/http/client.pyx in shioaji.backend.http.client.Client.login()
IndexError: list index out of range
The APIs are friendly for Stocks and Futures, but not for Options.
I use the APIs to do Option quoting and encounter the error response "Max Num Subscriptions Exceeded".
I think that "Is there a method to subscribe the big title like "TXO201904" or "TXO201904W4" which tag does not include the details (like TXO201904W4C10100,TXO201904W4P10100,TXO201904W4C10200,TXO201904W4P10200)?"
Thanks.
閒置一段時間(隔日)後會發生如下錯誤:
Exception in callback _SelectorTransport._call_connection_lost(ConnectionRes..., 10054, None)) handle: <Handle _SelectorTransport._call_connection_lost(ConnectionRes..., 10054, None))> Traceback (most recent call last): File "d:\ide\Python\Python36_x64\lib\asyncio\events.py", line 127, in _run self._callback(*self._args) File "d:\ide\Python\Python36_x64\lib\asyncio\selector_events.py", line 663, in _call_connection_lost self._protocol.connection_lost(exc) File "shioaji\backend\socket\connect.pyx", line 251, in shioaji.backend.socket.connect.Socket.connection_lost AttributeError: 'Socket' object has no attribute '_logger'
login at 8:30 nearby,can't got any stock contract list.
Hi,
我在試臺指選的時候遇到了點問題:
In [67]: c = api.Contracts.Options.TX1.TX1202007011650P
In [68]: order = api.Order(
...: action=sj.constant.Action.Buy,
...: price=10,
...: quantity=1,
...: order_type=sj.constant.ORDER_TYPE_ROD,
...: price_type='LMT',
...: octype='Auto',
...: account=api.futopt_account
...: )
In [69]: trade = api.place_order(c, order)
OrderState.FOrder {'operation': {'op_type': 'New', 'op_code': '99S2', 'op_msg': '交易商品不存在/下市(FTTM)'}, ...}
目前大都的雲端都是linux
請問一下,能否在linux主機運行?
如題 不知是否有計劃支援? 謝謝
我等入以後,透過api.list_accounts()可以看到有一個期貨帳戶跟一個股票帳戶
再來我透過api.set_default_account(api.stock_account)將股票帳戶設為預設
但設定完後,在api.Contracts還是沒有股票商品的資訊
Contracts(Stocks=(), Futures=(BRF, EXF, GDF, MXF, RHF, RTF, SPF, TGF, TXF, UDF, XAF, XBF, XEF, XJF), Options=(TXO))
同時api.get_account_margin()回傳的也是期貨帳戶的資訊
請問我有任何辦法可以解決該問題,取得股票商品的Contracts資訊嗎?
api.update_status() Traceback (most recent call last): File "<stdin>", line 1, in <module> File "d:\ide\workspace_python\xxx\lib\site-packages\shioaji\shioaji.py", line 330, in update_status self._api.update_status() File "shioaji\backend\http\main.pyx", line 117, in shioaji.backend.http.main.HttpApi.update_status File "shioaji\backend\http\order.pyx", line 104, in shioaji.backend.http.order.update_status File "shioaji\backend\http\stock\order.pyx", line 259, in shioaji.backend.http.stock.order.query_stock_order File "shioaji\backend\http\stock\order.pyx", line 240, in shioaji.backend.http.stock.order._query_stock_order AttributeError: 'NoneType' object has no attribute 'broker_id'
相較於台指,海期大多商品需要再FND前換倉,如果能提供這個日期會更方便!
建議新增
1.加權指數即時資訊
ex:大盤預估量、委買委賣、成交筆數等
2.個股財報 (綜合損益表、資產負債表、現金流量表、股利政策表、除權除息結果表、月營收表)
Thanks!
申購部分,我們會列入功能開發.
Originally posted by @ypochien in #4 (comment)
api.OrderProps.Future.action.Buy
以及 api.OrderProps.Future.action.Sell
似乎分別改成了 "Buy"
與 "Sell"
,而不是原本字串 "B"
或 "S"
。這個和 doc string 描述的不一致。在 limit_order 舉例的部分: sample_limit_order = api.LimitOrder('B', 9700, 5)
sample_limit_order
LimitOrder(action='B', order_type='ROD', price=9700, quantity=5)
現在也不能使用 "B"
或 "S"
作為 api.LimitOrder
的參數了。
api.OrderProps.Future
這個命名指的應該是期貨? 所以應該是 api.OrderProps.Futures
?希望能夠確認一下,謝謝。请问, trade = api.place_order(self.TradedTarget, Buy_order)
trade.status.status 回传讯息只有“PendingSubmit” ,“Submitted”?
已成交会回传什么? 已撮合未成交会回传什么?
可否提供回传讯息的明细
請問要進行股票的先賣後買時,api.Order()的參數該怎麼設定?
您好,請問目前有小道瓊期貨(YMM20.IF)的即時資料嗎?謝謝
Hi Shioaji team,
請問有支援交割銀行(永豐銀行)餘額抓取嗎?
謝謝。
請問近期會支援興櫃股票下單嗎?
如果有預計是何時呢?
THX~
Log:
~/python$ ./sub.py
Response Code: 0 | Event Code: 0 | Info: host '203.66.91.161:80', IP 203.66.91.161:80 (host 1 of 1) (host connection attempt 1 of 1) (total connection attempt 1 of 1) | Event: Session up
Ca Initial Done.
Traceback (most recent call last):
File "./sub.py", line 13, in
api.quote.subscribe(api.Contracts.Stocks["2614"], quote_type=sj.constant.QuoteType.Tick)
File "shioaji/backend/solace/api.pyx", line 658, in shioaji.backend.solace.api.SolaceAPI.subscribe
File "shioaji/backend/solace/api.pyx", line 39, in shioaji.backend.solace.api.contract2topic
AttributeError: 'NoneType' object has no attribute 'code'
Sentry is attempting to send 0 pending error messages
Waiting up to 2 seconds
Press Ctrl-C to quit
只有照sample code(login的部分正確確) 做以上的subscribe:
api.quote.subscribe(api.Contracts.Stocks["2614"], quote_type=sj.constant.QuoteType.Tick)
環境:
ubuntu 16.04
python3 3.5.2
請問可以查詢個股的歷史股價嗎?
有無範例可以提供?
My sample code is as followed:
contract = api.Contracts.Options.TXO.TXO20200409800C
order = api.Order(action="Buy",
price=1,
quantity=1,
order_type="ROD",
price_type="LMT",
octype="Auto",
account=api.futopt_account)
trade = api.place_order(contract, order)
I just tried the order api on TXF and TXO. It seems working properly on TXF. However, the order price that comes out for TXO is absolutely making no sense.
Please help to check it. Thanks.
爬資料幾個月來第一次發生, len(TickType|DiffType)=20, len(其他)=19, 會導致 dict 不能直接給 pd 丟 dataframe (其實更在意的是資料品質是否有問題)
--- cut ---
L/TFE/MXFC0 {"Amount": [11795.0, 23584.0, 23584.0, 23584.0, 23584.0, 23584.0, 23584.0, 23584.0, 23584.0, 23584.0, 23584.0, 23584.0, 23584.0, 23584.0, 23584.0, 23584.0, 23584.0, 23584.0, 23584.0], "AmountSum": [1674890.0, 1698474.0, 1722058.0, 1745642.0, 1769226.0, 1792810.0, 1816394.0, 1839978.0, 1863562.0, 1887146.0, 1910730.0, 1934314.0, 1957898.0, 1981482.0, 2005066.0, 2028650.0, 2052234.0, 2075818.0, 2099402.0], "AvgPrice": [11795.0, 11794.958333333334, 11794.917808219177, 11794.878378378378, 11794.84, 11794.802631578947, 11794.766233766233, 11794.73076923077, 11794.696202531646, 11794.6625, 11794.62962962963, 11794.59756097561, 11794.56626506024, 11794.535714285714, 11794.505882352942, 11794.476744186046, 11794.448275862069, 11794.420454545454, 11794.393258426966], "Close": [11795.0, 11792.0, 11792.0, 11792.0, 11792.0, 11792.0, 11792.0, 11792.0, 11792.0, 11792.0, 11792.0, 11792.0, 11792.0, 11792.0, 11792.0, 11792.0, 11792.0, 11792.0, 11792.0], "Code": "MXFC0", "Date": "2020/01/30", "DiffPrice": [-300.0, -303.0, -303.0, -303.0, -303.0, -303.0, -303.0, -303.0, -303.0, -303.0, -303.0, -303.0, -303.0, -303.0, -303.0, -303.0, -303.0, -303.0, -303.0], "DiffRate": [-2.4803637866887143, -2.5051674245556015, -2.5051674245556015, -2.5051674245556015, -2.5051674245556015, -2.5051674245556015, -2.5051674245556015, -2.5051674245556015, -2.5051674245556015, -2.5051674245556015, -2.5051674245556015, -2.5051674245556015, -2.5051674245556015, -2.5051674245556015, -2.5051674245556015, -2.5051674245556015, -2.5051674245556015, -2.5051674245556015, -2.5051674245556015], "DiffType": [4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4], "High": [11795.0, 11795.0, 11795.0, 11795.0, 11795.0, 11795.0, 11795.0, 11795.0, 11795.0, 11795.0, 11795.0, 11795.0, 11795.0, 11795.0, 11795.0, 11795.0, 11795.0, 11795.0, 11795.0], "Low": [11764.0, 11764.0, 11764.0, 11764.0, 11764.0, 11764.0, 11764.0, 11764.0, 11764.0, 11764.0, 11764.0, 11764.0, 11764.0, 11764.0, 11764.0, 11764.0, 11764.0, 11764.0, 11764.0], "Open": 11795.0, "TargetKindPrice": 12118.71, "TickType": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "Time": "08:45:00.105000", "TradeAskVolSum": 39, "TradeBidVolSum": 149, "VolSum": [142, 144, 146, 148, 150, 152, 154, 156, 158, 160, 162, 164, 166, 168, 170, 172, 174, 176, 178], "Volume": [1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]}
--- cut ---
程式登出或是 api 物件重新生成(多重登入)時,呼叫 api.list_trades() 未顯示當日的掛單。 若使用 api.update_status() 也無法顯示掛單。
list_trades() 應該要包含當日的進出,否則這對部分操作示會有影響的。舉例來說,在這狀況下使用 cancel_order() 是不太方便的,由於該函示要求傳入 trade 物件 (而非order id),但文件上並沒有提到 trade 物件如何生成,最終導致無法撤單。
如果沒撤單會造成保證金無法利用,或是無法改單而產生虧損。
p.s. 以類似 monkey patch 的方式當然是可以處理的,不過稍嫌麻煩。
p.s. 使用 monkey patch 可能會造成原本的 order 亦無法撤單,請勿嘗試。
Hi Yvictor,
I got error as below when I am trying to execute the example code.
Traceback (most recent call last):
File "test.py", line 1, in <module>
import shioaji as sj
File "/home/sykuang/.local/lib/python3.8/site-packages/shioaji/__init__.py", line 22, in <module>
from shioaji.shioaji import Shioaji
File "/home/sykuang/.local/lib/python3.8/site-packages/shioaji/shioaji.py", line 7, in <module>
from shioaji.backend.solace import SolaceAPI
File "/home/sykuang/.local/lib/python3.8/site-packages/shioaji/backend/solace/__init__.py", line 1, in <module>
from shioaji.backend.solace.quote import Quote
File "shioaji/backend/solace/quote.pyx", line 4, in init shioaji.backend.solace.quote
File "/home/sykuang/.local/lib/python3.8/site-packages/pysolace/__init__.py", line 18, in <module>
inject_lib_path()
File "/home/sykuang/.local/lib/python3.8/site-packages/pysolace/__init__.py", line 15, in inject_lib_path
os.add_dll_directory(libs_path.as_posix())
AttributeError: module 'os' has no attribute 'add_dll_directory'
Sentry is attempting to send 0 pending error messages
Waiting up to 2 seconds
Press Ctrl-C to quit
In pysolace/init.py
def inject_lib_path():
import os
import sys
from pathlib import Path
dir_path = Path(__file__).parent
libs_path = dir_path.joinpath('.libs')
os.environ["PATH"] = ";".join(
[p for p in [os.environ.get("PATH", ""), libs_path.as_posix()] if p]
)
os.environ["LD_LIBRARY_PATH"] = ";".join(
[p for p in [os.environ.get("LD_LIBRARY_PATH", ""),
libs_path.as_posix()] if p]
)
if sys.version_info.major == 3 and sys.version_info.minor >= 8:
os.add_dll_directory(libs_path.as_posix())
You should add an os check for avoiding using add_dll_directory in Linux. I think add_dll_directory is for M$ windows.
由於 list_trade回傳的trade.order 無帳號資訊,導致透過此trade進行cancel_order會出現錯誤.
應該要跟 place_order回傳的trade物件一致.
在docker環境下的 0.0.6.dev6 可以運行
但你們最新release的版本 0.1.1.dev0
這個是event_callback訊息
Response Code: 0 | Event Code: 0 | Info: host '203.66.91.161:80', IP 203.66.91.161:80 (host 1 of 1) (host connection attempt 1 of 1) (total connection attempt 1 of 1) | Event: Session
up
就會出現以下錯誤
Unexpected error: (<class 'AttributeError'>, AttributeError("'Shioaji' object has no attribute 'fut_account'",), <traceback object at 0x7fccc408f308>)
例如範例中:
ticks = api.ticks(api.Contracts.Stocks["2330"], "2020-03-04")
結果印出來的bid_price、ask_price、ask_volume、bid_volume均為0
我抓近期的資料也是一樣,
跟看盤軟體顯示的資料都有出入
還麻煩解惑,謝謝。
目前的文件看起來似乎只能用在期貨跟選擇權?
Win10-64bit, python3.6.5,
c:> pip install shioaji
ERROR: Could not find a version that satisfies the requirement shioaji (from versions: none)
ERROR: No matching distribution found for shioaji
用pip安裝別的套件正常。
pip3 install shioaji
ERROR: Could not find a version that satisfies the requirement shioaji (from versions: none)
ERROR: No matching distribution found for shioaji
這套件還有在維護嗎?
The APIs are friendly for Stocks and Futures, but not for Options.
I use the APIs to do Option quoting and encounter the error response "Max Num Subscriptions Exceeded".
I think that "Is there a method to subscript the big title like "TXO201904" or "TXO201904W4" which tag does not include the details (like TXO201904W4C10100,TXO201904W4P10100,TXO201904W4C10200,TXO201904W4P10200)?"
Thanks.
問題 1. 請問有沒有python的指令可以在盤後將當天的股價資料載入?
問題 2. 用api.quote.subscribe()讀取當天的股價後,該怎麼讓資料寫入到txt檔中?
問題 3. 用api.login登入結果出現連不上線的情況,該怎麼處理?
執行 place_order() 後,trade object 回應 status=OrderStatus(status=<Status.Inactive: 'Inactive'>),
重新啟動程式執行後是可以成功的。
目前懷疑是程式後 login Session 啟動就放著不動一天後,Session 可能斷掉了,
請問是否有建議如何偵測/判別 Session 狀態,然後重新登入,謝謝。
verison:0.3.0.dev0
Python 的 dictionary 是 unorder
dict.values 的 output 順序不保證。
--- shioaji.py.orig 2019-03-29 11:00:18.145788028 +0800
+++ shioaji.py 2019-03-29 11:04:17.326463142 +0800
@@ -1,4 +1,4 @@
-from shioaji.backend import get_backends
+from shioaji import backend
from shioaji.backend.solace.quote import Quote
import datetime as dt
from shioaji.order import Order
@@ -48,7 +48,7 @@
currency (str): {NTX, USX, NTD, USD, HKD, EUR, JPY, GBP}
set the default currency for display
"""
- _http, _socket = get_backends().values()
+ _http, _socket = backend.http, backend.socket
self.quote = Quote()
self._http = _http(simulation, proxies)
self._socket = _socket(simulation, proxies)
--- backend/__init__.py.orig 2019-03-29 11:01:03.124408744 +0800
+++ backend/__init__.py 2019-03-29 11:01:36.975371308 +0800
@@ -1,10 +1,2 @@
-from shioaji.backend.http import HttpApi
-from shioaji.backend.socket import Wrapper
-
-
-def get_backends():
- apis = {
- 'http': HttpApi,
- 'socket': Wrapper,
- }
- return apis
+from shioaji.backend.http import HttpApi as http
+from shioaji.backend.socket import Wrapper as socket
請問禮拜六主機維護嗎,抓不到未平倉資訊;
另外看API ,get_account_openposition function這個之後會拿掉;
但是list_position取得的資訊無法得知未平倉商品合約月份(code、cond、direction、pnl、price、quantity、yd_quantity) ,
這會導致無法判斷是否到了換倉日而該換倉(也許商品已經是在次月)
請確認,謝謝!
Try to install on macOS, but failed. (On Debian Linux, it work well)
$ python --version
Python 3.7.1
$ pip3 install shioaji
Collecting shioaji
ERROR: Could not find a version that satisfies the requirement shioaji (from versions: none)
ERROR: No matching distribution found for shioaji
Hi,
As first pic showes, there used to be wheel files for python 3.6/3.7 win amd64 on pypi.
However, for the latest 0.2.0.dev1, there is only python 3.5 wheel for win amd64 as second pic shows.
Is it intended? People using python 3.6 or 3.7 could not install Shioaji on a win amd64 machine for the latest version by pip now.
Could you please check? Thanks.
如題 最近台灣證券交易市場正在改成逐筆交易
這個套件是不是也同樣支援逐筆交易呢?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.