[QMT]09-下载历史行情数据到本地

下载历史行情数据

download_history_data(stock_code, period, start_time='', end_time='')

1

  • 释义

  • 补充历史行情数据

  • 参数

  • stock_code - string 合约代码

  • period - string 周期

  • start_time - string 起始时间

  • end_time - string 结束时间

  • 返回

  • 备注

  • 同步执行,补充数据完成后返回

下载数据实操:

from xtquant import xtdata
code ='600050.SH'
period = '1m'
day = '20221220'
xtdata.download_history_data(stock_code=code, period=period, start_time=day, end_time=day)

检验下载结果:

在\userdata_mini\datadir目录中,根据不同市场去找SH或SZ子目录,继续去60目录(1m周期)就能看到新下载的600050.DAT文件了

本地文件读取历史行情

请参考 [QMT]08-从本地行情数据解析历史K线信息

from xtquant import xtdata
import pandas as pd
import datetime,time
code =['600050.SH']
period = '1m'
day = '20221220'
data_dir=r'X:\iQuant\userdata_mini\datadir'
kline_data=xtdata.get_local_data(field_list=[],stock_code=code,period=period, start_time=day,end_time=day,count=10,data_dir=data_dir)
df =pd.concat([kline_data[i].T for i in ['time', 'open', 'high','low','close','volume','amount','settelementPrice', 'openInterest']],axis=1)
df.columns=['time','open','high','low','close','volume','amount','settelementPrice','openInterest']
df['time']=df['time'].apply(lambda x: datetime.datetime.fromtimestamp(x/1000.0))
print(tabulate(df,headers=df.columns,))
print(df.shape[0])

读取结果:

time open high low close volume amount settelementPrice openInterest
------------- ------------------- ------ ------ ----- ------- -------- ---------------- ------------------ --------------
1671519060000 2022-12-20 14:51:00 4.5 4.5 4.49 4.5 5316 2.39101e+06 0 13 1671519120000 2022-12-20 14:52:00 4.49 4.5 4.49 4.49 14650 6.58753e+06 0 13 1671519180000 2022-12-20 14:53:00 4.5 4.5 4.49 4.5 17313 7.7887e+06 0 13 1671519240000 2022-12-20 14:54:00 4.5 4.51 4.5 4.51 15259 6.86707e+06 0 13 1671519300000 2022-12-20 14:55:00 4.51 4.51 4.5 4.5 5920 2.66748e+06 0 13 1671519360000 2022-12-20 14:56:00 4.51 4.52 4.5 4.52 16682 7.52376e+06 0 13 1671519420000 2022-12-20 14:57:00 4.52 4.52 4.51 4.52 20157 9.0974e+06 0 13 1671519480000 2022-12-20 14:58:00 4.51 4.51 4.51 4.51 825 372375 0 18 1671519540000 2022-12-20 14:59:00 4.51 4.51 4.51 4.51 0 0 0 18 1671519600000 2022-12-20 15:00:00 4.51 4.52 4.51 4.52 33970 1.53544e+07 0 15 10

猜你喜欢

转载自blog.csdn.net/liuyukuan/article/details/128763405
今日推荐