get_local_data.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #coding:utf-8
  2. from datetime import datetime as dt
  3. # 用get_market_data订阅历史和实时行情
  4. import time
  5. import pandas as pd
  6. if __name__=='__main__':
  7. from xtquant import xtdata
  8. s = '000001.SZ'
  9. # 实际使用时,该接口每天盘后执行一次即可
  10. # 该接口会下载历史行情并落地到本地,随后即可通过xtdata.get_local_data接口调用本地行情
  11. # 同时间、同股票、同周期的行情下载一次即可,
  12. xtdata.download_history_data(s, '1d','','')
  13. xtdata.download_history_data('000001.SH', '1d','','')
  14. data = xtdata.get_market_data([], [s], '1d', end_time='', count=-1, dividend_type='back')
  15. # data2 = xtdata.get_local_data([], [s], '1d', end_time='', count=2,dividend_type='back')
  16. print('data from get_local_data:\n')
  17. df = pd.DataFrame()
  18. for column in data:
  19. if column in ['time', 'open', 'high', 'low', 'close', 'volume', 'amount']:
  20. # print(f" {column}\n {data[column].head()}\n")
  21. print(column, data[column].T)
  22. df=pd.concat([df, data[column].T],axis=1)
  23. df.columns = ['time', 'open', 'high', 'low', 'close', 'volume', 'amount']
  24. df['time']=df['time'].apply(lambda x: dt.fromtimestamp(x / 1000.0))
  25. print('!!!!!!!', df)
  26. # print(df['time'].apply(lambda x: dt.fromtimestamp(x / 1000.0)))
  27. df2 = pd.concat([data[i].T for i in ['time', 'open', 'high', 'low', 'close', 'volume', 'amount']], axis=1)
  28. df2.columns = ['time', 'open', 'high', 'low', 'close', 'volume', 'amount']
  29. df2['time']=df2['time'].apply(lambda x: dt.fromtimestamp(x / 1000.0))
  30. print('>>>>>>>>>>>', df2)
  31. print(df.index)
  32. exit()
  33. #
  34. # for column in data2:
  35. # print(f" {column}\n {data2[column].head()}\n")