取得报价後的处理 (callback)
执行订阅後,资料会一直自动更新,只要 server 端有发布新的报价,我们的程序就会自动去取回来,所以取回来之後,要怎麽处理,也就是自动化的精髓,这里我只是示范一下,所以使用 print,只有把回传的资料列出来而已,後续如果有机会的话,我再来看怎麽写这个自动化
@sj.on_quote
def quote_callback(topic, quote_msg):
print(topic, quote_msg)
# Shioaji 使用的订阅 library 为 solace, 这里的 event 指的是 solace 在订阅的过程中发生的事件,像是断线, 重新连线...等,一般来说不用特别设定,所以这里也只是 print 出来而已
@sj.on_event
def event_callback(resp_code, event_code, event):
print("Response Code: {} | Event Code: {} | Event: {}".format(resp_code, event_code, event))
api.quote.set_callback(quote_back)
api.quote.set_event_callback(event_callback)
设定要订阅的股票或期货代码
# 台积电 2330
tse2330 = api.Contracts.Stocks['2330']
# 台指期
txfj1 = api.Contracts.Futures['TXFJ1']
# 成交价
api.quote.subscribe(tse2330)
# 五档
api.quote.subscribe(tse2330, quote_type='bidask')
# 成交价
api.quote.subscribe(txfj1)
# 五档
api.quote.subscribe(txfj1, quote_type='bidask')
code (str): 股票代码
datetime (datetime.datetime): datetime
open (Decimal): open
avg_price (Decimal): average price
close (Decimal): deal price
high (Decimal): high since market open
low (Decimal): low since market open
amount (Decimal): amount (NTD)
total_amount (Decimal): total amount (NTD)
volume (int): volume (K shares)
if intraday_odd: (share)
total_volume (int): total volume (K shares)
if intraday_odd: (share)
tick_type (int): tick type (内外盘别)
{1: buy deal, 2: sell deal, 0: can't judge}
chg_type (int): (涨跌注记)
{1: limit up, 2: up, 3: unchanged, 4: down, 5: limit down}
price_chg (Decimal): price change
pct_chg (Decimal): percentage change (%)
bid_side_total_vol(int): total buy deal volume (K shares, 买盘成交总量)
if intraday_odd: (share)
ask_side_total_vol (int): total sell deal volume (K shares, 卖盘成交总量)
if intraday_odd: (share)
bid_side_total_cnt (int): total number of buy deal (买盘成交笔数)
ask_side_total_cnt (int): total number of sell deal (卖盘成交笔数)
closing_oddlot_shares (int): (share, 盘後零股成交股数)
fixed_trade_vol (int): fixed trade volume (K shares, 定盘成交量)
if intraday_odd: 0
suspend (bool): suspend (暂停交易)
simtrade (bool): simulated trade (试撮)
intraday_odd (bool): intraday odd (盘中零股)
code (str): 股票代码
datetime (datetime.datetime): datetime
bid_price (list of Decimal): bid price
bid_volume (list of int): bid volume (K shares)
diff_bid_vol (list of int): (K shares, 买价增减量)
ask_price (list of Decimal): ask price
ask_volume (list of int): ask volume
diff_ask_vol (list of int): (K shares, 卖价增减量)
suspend (bool): suspend (暂停交易)
simtrade (bool): simulated trade (试撮)
code (str): code
datetime (datetime.datetime): datetime
open (Decimal): open
underlying_price (Decimal): underlying price (标的物价格)
bid_side_total_vol(int): total buy deal volume (lot, 买盘成交总量)
ask_side_total_vol(int): total sell deal volume (lot, 卖盘成交总量)
avg_price (Decimal): average price
close (Decimal): deal price
high (Decimal): high since market open
low (Decimal): low since market open
amount (Decimal): amount (= deal price)
total_amount (Decimal): total amount (= sum of deal price)
volume (int): volume (lot)
total_volume (int): total volume (lot)
tick_type (int): tick type (内外盘别)
{1: buy deal, 2: sell deal, 0: can't judge}
chg_type (int): (涨跌注记)
{1: limit up, 2: up, 3: unchanged, 4: down, 5: limit down}
price_chg (Decimal): price change
pct_chg (Decimal): percentage change (%)
simtrade (int): simulated trade (试撮)
code (str): code
datetime (datetime.datetime): datetime
bid_total_vol (int): total buy deal volume (lot, 买盘成交总量)
ask_total_vol (int): total sell deal volume (lot, 卖盘成交总量)
bid_price (list of Decimal): bid price
bid_volume (list of int): bid volume (lot)
diff_bid_vol (list of int): (lot, 买价增减量)
ask_price (list of Decimal): ask price
ask_volume (list of int): ask volume (lot)
diff_ask_vol (list of int): (lot, 卖价增减量)
first_derived_bid_price (Decimal): first derived bid price (衍生一档买价)
first_derived_ask_price (Decimal): first derived ask price (衍生一档卖价)
first_derived_bid_vol (int): first derived bid volume (衍生一档买量)
first_derived_ask_vol (int): first derived bid volume (衍生一档卖量)
underlying_price (Decimal): underlying price (标的物价格)
simtrade (int): simulated trade (试撮)
<<: Day 05 - jS 微基础之ES6回圈:loop
前面我们讲特殊符号的时候,我们有讲过 $ 符号,它就是一个简化的格式化输出的符号。今天我们来看看字符...
相信大家或多或少都有去公家机关办事的经验。去公家机关办事时,如果等待时间拖太久,肯定觉得很烦吧?好不...
环境 Windows 10 21H1 Visual Studio 2019 前情提要 在【Day 2...
Day 27 网路设置与远端 网路及远端登入可能有先东西在先前已经介绍过,这边再稍微做个简单的范例。...
https://leetcode.com/problems/add-two-numbers/des...