from datetime import date import pandas as pd from tqsdk import TqApi, TqBacktest, TqKq from tqsdk.tafunc import time_to_datetime pd.options.display.float_format = '{:20.0f}'.format SYMBOL = 'SHFE.rb2010' api = TqApi( backtest=TqBacktest(start_dt=date(2020, 8, 10), end_dt=date(2020, 8, 20))) klines = api.get_kline_serial(SYMBOL, duration_seconds=60 * 5, data_length=10) klines['datetime_dt'] = klines['datetime'].apply(time_to_datetime) print(klines) api.close()
在使用天勤量化之前,默认您已经知晓并同意以下免责条款,如果不同意请立即停止使用:https://www.shinnytech.com/blog/disclaimer/ datetime id open high low close volume open_oi close_oi symbol duration datetime_dt 0 1596780600000000000 12188 3836 3839 3833 3835 13977 1149495 1148265 SHFE.rb2010 300 2020-08-07 14:10:00 1 1596780900000000000 12189 3835 3840 3835 3837 12770 1148265 1147665 SHFE.rb2010 300 2020-08-07 14:15:00 2 1596781200000000000 12190 3837 3837 3833 3834 5832 1147665 1147704 SHFE.rb2010 300 2020-08-07 14:20:00 3 1596781500000000000 12191 3834 3836 3830 3834 8532 1147704 1148467 SHFE.rb2010 300 2020-08-07 14:25:00 4 1596781800000000000 12192 3834 3837 3833 3834 4680 1148467 1147365 SHFE.rb2010 300 2020-08-07 14:30:00 5 1596782100000000000 12193 3834 3837 3833 3835 6611 1147365 1145200 SHFE.rb2010 300 2020-08-07 14:35:00 6 1596782400000000000 12194 3835 3841 3835 3837 11648 1145200 1143732 SHFE.rb2010 300 2020-08-07 14:40:00 7 1596782700000000000 12195 3837 3838 3834 3834 7980 1143732 1143844 SHFE.rb2010 300 2020-08-07 14:45:00 8 1596783000000000000 12196 3834 3837 3831 3831 11881 1143844 1141372 SHFE.rb2010 300 2020-08-07 14:50:00 9 1596783300000000000 12197 3831 3835 3831 3832 17305 1141372 1137326 SHFE.rb2010 300 2020-08-07 14:55:00
lookis 编辑答案 2020年8月26日