我输入的python代码
from datetime import datetime
from contextlib import closing
from tqsdk import TqApi, TqSim
from tqsdk.tools import DataDownloader
api = TqApi(TqSim())
download_tasks = {}
download_tasks[“SR_daily”] = DataDownloader(api, symbol_list=”CZCE.SR901″, dur_sec=24*60*60,start_dt=datetime(2018, 1, 1), end_dt=datetime(2018, 9, 1), csv_file_name=”SR901_daily.csv”)
download_tasks[“rb_5min”] = DataDownloader(api, symbol_list=”KQ.m@SHFE.rb”, dur_sec=5*60,start_dt=datetime(2017, 1, 1), end_dt=datetime(2018, 9, 1), csv_file_name=”rb_5min.csv”)
download_tasks[“T_tick”] = DataDownloader(api, symbol_list=[“CFFEX.T1809″], dur_sec=0,start_dt=datetime(2018, 5, 1), end_dt=datetime(2018, 6, 1), csv_file_name=”T1809_tick.csv”)
执行后,不报错
但是停止在最后一行代码
无法成功下载
官方给的文档没问题
还是ide的问题
换用pycharm
设置好继承packages
一切正常
我已经成功解决
是因为vs code的问题
我编写完代码
关闭vs code
重启,再运行,就好了
成功运行的代码为
from datetime import datetime, date
from contextlib import closing
from tqsdk import TqApi, TqSim
from tqsdk.tools import DataDownloader
api = TqApi(TqSim())
download_tasks = {}
download_tasks[“SR_daily”] = DataDownloader(api, symbol_list=”CZCE.SR901″, dur_sec=24*60*60, start_dt=date(2018, 1, 1), end_dt=date(2018, 9, 1), csv_file_name=”SR901_daily.csv”)
download_tasks[“rb_5min”] = DataDownloader(api, symbol_list=”KQ.m@SHFE.rb”, dur_sec=5*60, start_dt=date(2017, 1, 1), end_dt=date(2018, 9, 1), csv_file_name=”rb_5min.csv”)
download_tasks[“cu_min”] = DataDownloader(api, symbol_list=[“SHFE.cu1805”, “SHFE.cu1807”, “CFFEX.IC1803″], dur_sec=60, start_dt=datetime(2018, 1, 1, 6, 0 ,0), end_dt=datetime(2018, 6, 1, 16, 0, 0), csv_file_name=”cu_min.csv”)
with closing(api):
while not all([v.is_finished() for v in download_tasks.values()]):
api.wait_update()
print(“progress: “, { k:(“%.2f%%” % v.get_progress()) for k,v in download_tasks.items() })