永豐Shioaji api 操作記錄--取得行情
Shioaji API 行情種類
- 即時:
- 即時行情: subscribe()
- 市場快照: snapshot()
- 市場排行: scanner()
- 歷史:
即時行情
subscribe/unsubscribe
訂閱
# 登入並等 Contract 下載完成後
api.quote.subscribe(
api.Contracts.Stocks["2330"], #合約
quote_type = sj.constant.QuoteType.Tick, #報價種類
version = sj.constant.QuoteVersion.v1 #版本
)
# quote_type 共有三種: sj.constant.QuoteType.Tick(成交明細)、sj.constant.QuoteType.bidask(五檔)、sj.constant.QuoteType.quota(五檔+明細)
取消訂閱
snapshot
快照
# 登入並等 Contract 下載完成後
snapshot = api.snapshots([api.Contracts.Stocks['6231']])
print(snapshot)
# response
Snapshot(ts=1709821800000000000, code='6231', exchange='OTC', open=293.0, high=298.0, low=282.5, close=284.0,
tick_type=<TickType.Sell: 'Sell'>, change_price=-7.5, change_rate=-2.57, change_type=<ChangeType.Down: 'Down'>,
average_price=288.14, volume=2, total_volume=2210, amount=568000, total_amount=636783310, yesterday_volume=2382.0,
buy_price=284.0, buy_volume=3.0, sell_price=284.5, sell_volume=4, volume_ratio=0.93)
scanner
排行
歷史行情
Ticks