本篇分享一个获取最新期货品种交易时间的python脚本。脚本基于天勤量化开源库,安装Python 3.6及以上版本,命令行下pip install tqsdk即可安装。最新期货品种交易时间(20220401)如下:
交易所: SHFE
品种: cu 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 [['21:00:00', '25:00:00']]
品种: fu 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 [['21:00:00', '23:00:00']]
品种: rb 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 [['21:00:00', '23:00:00']]
品种: au 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 [['21:00:00', '26:30:00']]
品种: ss 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 [['21:00:00', '25:00:00']]
品种: ag 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 [['21:00:00', '26:30:00']]
品种: hc 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 [['21:00:00', '23:00:00']]
品种: sn 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 [['21:00:00', '25:00:00']]
品种: ru 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 [['21:00:00', '23:00:00']]
品种: ni 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 [['21:00:00', '25:00:00']]
品种: bu 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 [['21:00:00', '23:00:00']]
品种: wr 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 []
品种: al 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 [['21:00:00', '25:00:00']]
品种: zn 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 [['21:00:00', '25:00:00']]
品种: sp 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 [['21:00:00', '23:00:00']]
品种: pb 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 [['21:00:00', '25:00:00']]
交易所: DCE
品种: jm 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 [['21:00:00', '23:00:00']]
品种: pp 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 [['21:00:00', '23:00:00']]
品种: l 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 [['21:00:00', '23:00:00']]
品种: c 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 [['21:00:00', '23:00:00']]
品种: p 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 [['21:00:00', '23:00:00']]
品种: b 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 [['21:00:00', '23:00:00']]
品种: m 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 [['21:00:00', '23:00:00']]
品种: i 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 [['21:00:00', '23:00:00']]
品种: eb 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 [['21:00:00', '23:00:00']]
品种: rr 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 [['21:00:00', '23:00:00']]
品种: lh 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 []
品种: jd 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 []
品种: pg 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 [['21:00:00', '23:00:00']]
品种: j 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 [['21:00:00', '23:00:00']]
品种: bb 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 []
品种: a 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 [['21:00:00', '23:00:00']]
品种: fb 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 []
品种: y 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 [['21:00:00', '23:00:00']]
品种: eg 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 [['21:00:00', '23:00:00']]
品种: cs 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 [['21:00:00', '23:00:00']]
品种: v 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 [['21:00:00', '23:00:00']]
交易所: CZCE
品种: PM 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 []
品种: SF 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 []
品种: JR 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 []
品种: TA 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 [['21:00:00', '23:00:00']]
品种: OI 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 [['21:00:00', '23:00:00']]
品种: PK 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 []
品种: FG 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 [['21:00:00', '23:00:00']]
品种: WH 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 []
品种: PF 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 [['21:00:00', '23:00:00']]
品种: SA 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 [['21:00:00', '23:00:00']]
品种: CF 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 [['21:00:00', '23:00:00']]
品种: UR 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 []
品种: ZC 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 [['21:00:00', '23:00:00']]
品种: CJ 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 []
品种: CY 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 [['21:00:00', '23:00:00']]
品种: MA 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 [['21:00:00', '23:00:00']]
品种: SM 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 []
品种: RI 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 []
品种: RM 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 [['21:00:00', '23:00:00']]
品种: AP 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 []
品种: LR 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 []
品种: SR 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 [['21:00:00', '23:00:00']]
品种: RS 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 []
交易所: INE
品种: bc 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 [['21:00:00', '25:00:00']]
品种: sc 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 [['21:00:00', '26:30:00']]
品种: lu 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 [['21:00:00', '23:00:00']]
品种: nr 交易时间: 日盘 (['09:00:00', '10:15:00'], ['10:30:00', '11:30:00'], ['13:30:00', '15:00:00']) 夜盘 [['21:00:00', '23:00:00']]
交易所: CFFEX
品种: IF 交易时间: 日盘 (['09:30:00', '11:30:00'], ['13:00:00', '15:00:00']) 夜盘 []
品种: IC 交易时间: 日盘 (['09:30:00', '11:30:00'], ['13:00:00', '15:00:00']) 夜盘 []
品种: TF 交易时间: 日盘 (['09:30:00', '11:30:00'], ['13:00:00', '15:15:00']) 夜盘 []
品种: TS 交易时间: 日盘 (['09:30:00', '11:30:00'], ['13:00:00', '15:15:00']) 夜盘 []
品种: T 交易时间: 日盘 (['09:30:00', '11:30:00'], ['13:00:00', '15:15:00']) 夜盘 []
品种: IH 交易时间: 日盘 (['09:30:00', '11:30:00'], ['13:00:00', '15:00:00']) 夜盘 []
Python脚本代码如下:
#!/usr/bin/python
from tqsdk import TqApi
api = TqApi(auth="账户名,密码")
allInstruments = api.query_quotes(ins_class="FUTURE", expired=False)
#print(allInstruments)
map = {i:api.get_quote(i) for i in allInstruments}
#print(map)
def split2exprod( exchinstr: str):
exchange,instr = exchinstr.split('.')
product="".join(filter(str.isalpha,instr))
l= [exchange, product]
return l
result={}
for k,v in map.items():
if v.ins_class == 'FUTURE_OPTION' :
rl = split2exprod(v.underlying_symbol)
elif v.ins_class == 'FUTURE':
rl = split2exprod(k)
else:
pass # pass FUTURE_COMBINE
if rl[0] not in result.keys():
result[rl[0]] = {rl[1] : v.trading_time}
else:
if rl[1] not in result[rl[0]].keys():
result[rl[0]].update( { rl[1] : v.trading_time })
for exch,v in result.items():
print("交易所:",exch)
for p,t in v.items():
print("品种: ",p," 交易时间: 日盘 ",tuple(t['day'])," 夜盘 ",t['night'])
api.close()