获取交易日列表
get_trading_dates(market, start_time='', end_time='', count=-1)
- 获取交易日列表使用的是这个函数,参数如何设置呢?
-
- 根据市场获取交易日列表 :
- param market:
- 市场代码 'SH','SZ','IF','DF','SF','ZF'等
- start_time: 起始时间 '20200101'
- end_time: 结束时间 '20201231'
- count: 数据个数,-1为全部数据
- return list(long) 毫秒数的时间戳列表

- 返回数据是一个时间戳列表
-
我们在用conv_time()方法把列表改成方便阅读的方式
import time
def conv_time(ct):
'''
conv_time(1476374400000) --> '20161014000000.000'
'''
local_time = time.localtime(ct / 1000)
data_head = time.strftime('%Y%m%d%H%M%S', local_time)
data_secs = (ct - int(ct)) * 1000
time_stamp = '%s.%03d' % (data_head, data_secs)
return time_stamp
完整代码:将时间戳改为20240808这样的格式
# coding=utf-8
import time
from xtquant import xtdata
date = xtdata.get_trading_dates("SH",start_time="20230808",end_time="20280808",count=-1)
def conv_time(timestamp):
return time.strftime('%Y%m%d', time.localtime(timestamp / 1000))
formatted_dates = [conv_time(ts) for ts in date]
print(formatted_dates)
|