[QMT]08-Analysis of historical K-line information from local market data

Parsing QMT local data with python

Get local market data

get_local_data(field_list=[], stock_code=[], period='1d', start_time='', end_time='', count=-1,dividend_type='none', fill_data=True, data_dir=data_dir)
  • paraphrase

  • Get the market data from the local data file, which is used to quickly obtain the market data of the historical part in batches

  • parameter

  • field_list - list data field list, if empty, all fields

  • stock_list - list contract code list

  • period - string period

  • start_time - string start time

  • end_time - string end time

  • count - the number of int data

  • dividend_type - string Dividend method

  • fill_data - bool Whether to fill in the missing data backwards

  • data_dir - string Userdata_mini path of MiniQmt companion path, used to read data files directly. By default, xtdata will directly obtain this path from MiniQmt through the connection, no additional settings are required. If you need to adjust, you can pass the data path as data_dir, or you can directly modify xtdata.data_dir to change the default value

  • return

  • When the period is 1m 5m 1dK line period

  • return dict { field1 : value1, field2 : value2, ... }

  • field1, field2, ... : data fields

  • value1, value2, ... : pd.DataFrame dataset, index is stock_list, columns is time_list

  • The DataFrame corresponding to each field has the same dimension and the same index

  • When period is the tick period

  • return dict { stock1 : value1, stock2 : value2, ... }

  • stock1, stock2, ... : contract code

  • value1, value2, ... : np.ndarray data set, arranged in ascending order of data timestamp time

  • Remark

  • Only used to get level1 data

call demo

from xtquant import xtdata
import pandas as pd
import datetime,time
df=xtdata.get_local_data(field_list=['time','open','high','low','close','volume','amount'],stock_code=['600050.SH'],count=10)
df2=pd.concat([df[i].loc['600050.SH'].T for i in['time','open','high','low','close','volume','amount']],axis=1)
df2.columns=['time','open','high','low','close','volume','amount']
df2['time2']=df2.index
df2['time']=df2['time2'].apply(lambda x:  datetime.datetime.fromtimestamp(int(x/1000.0)))
df2.reset_index(drop=True,inplace=True)
print(df2)

output

        time  open  high   low  close   volume        amount          time2
0 2023-01-09  4.98  5.01  4.88   4.98  3246943  1.608308e+09  1673193600000
1 2023-01-10  4.95  5.02  4.90   4.98  2571948  1.277204e+09  1673280000000
2 2023-01-11  4.97  5.12  4.93   4.96  3127401  1.572082e+09  1673366400000
3 2023-01-12  4.94  5.14  4.92   5.11  3870406  1.952001e+09  1673452800000
4 2023-01-13  5.07  5.14  4.99   5.06  3227926  1.631200e+09  1673539200000
5 2023-01-16  5.06  5.10  4.98   5.02  2944490  1.483375e+09  1673798400000
6 2023-01-17  4.99  5.04  4.94   4.95  2094947  1.043011e+09  1673884800000
7 2023-01-18  4.95  5.12  4.91   5.07  3392366  1.713247e+09  1673971200000
8 2023-01-19  5.04  5.18  5.02   5.17  4324306  2.205093e+09  1674057600000
9 2023-01-20  5.19  5.62  5.17   5.53  7470132  4.101551e+09  1674144000000

Guess you like

Origin blog.csdn.net/liuyukuan/article/details/128758757