Tick周期为什么只有最近一个交易日有数据,数据补充过了,也显示下载完成。
#encoding:gbk
from datetime import datetime, timedelta
class GlobalVariable:pass
g = GlobalVariable()
g.accountID = 'test'
g.accountType = 'STOCK'
g.stock_list = ['518660.SH']
def init(c):
c.set_account(g.accountID,g.accountType)
c.capital = et.prepare_invest
c.start = '2021-01-01 00:00:00'
c.end = datetime.today().strftime('%Y-%m-%d %M:%H:%S')
def handlebar(c):
# print({datetime.fromtimestamp(c.get_bar_timetag(c.barpos)/1000)})
current_bar_date = datetime.fromtimestamp(c.get_bar_timetag(c.barpos)/1000)
start_time = (current_bar_date - timedelta(minutes=5)).strftime('%Y%m%d%H%M%S')
end_time = current_bar_date.replace(hour=23, minute=59, second=59).strftime('%Y%m%d%H%M%S')
print(f's{start_time}e{end_time}')
data = c.get_market_data_ex([],g.stock_list,'tick',start_time,end_time=end_time)
for stock_code, d in data.items():
print(f'stock_code:{stock_code}:{d["lastPrice"]}')
|