241 浏览
0

代码:

with TqApi(auth=xxxx, account=TqKq()) as api:
kl = api.get_kline_data_series(symbol=’KQ.m@DCE.m’, duration_seconds=60*60 ,
start_dt=datetime.date(2024, 9, 30), end_dt=datetime.date(2024, 9, 30))
i = 0
while i < len(kl):
time = datetime.datetime.fromtimestamp(kl.iloc[i][“datetime”] / 1e9)
print(time)
i += 1

结果:

2024-09-27 14:00:00
2024-09-27 21:00:00
2024-09-27 22:00:00
2024-09-30 09:00:00
2024-09-30 10:00:00
2024-09-30 11:00:00
2024-09-30 13:00:00
2024-09-30 14:00:00

李思恒 已回答的问题 2024年10月9日
0
from tqsdk import TqApi, TqAuth
from datetime import date
from tqsdk.tafunc import time_to_str
api = TqApi(auth=TqAuth("xxxx", "xxxx"))
kline = api.get_kline_data_series(symbol='KQ.m@DCE.m',
                                  duration_seconds=60*60,
                                  start_dt=date(2024, 9, 30), end_dt=date(2024, 9, 30))
kline["datetime"] = kline["datetime"].apply(time_to_str)
print(kline.iloc[0])
api.close()

这个是我完整代码你试试,没啥问题,尽量用我们的时间转换函数,考虑了时区

李思恒 已回答的问题 2024年10月9日
您正在查看1个答案中的1个,单击此处查看所有答案。