代码1
import pandas as pd import datetime import time from tqsdk import TqApi, TqBacktest, TargetPosTask,tafunc,TqAccount,TqAuth from contextlib import closing async def HL_1(api,symbol): data_length=10 klines=api.get_kline_serial(symbol, duration_seconds=60*1440, data_length=data_length) async with api.register_update_notify(klines) as update_chan: num=0 while True: if num>=10: print(symbol,'结束') break async for _ in update_chan: if api.is_changing(klines,['close']): print(klines.iloc[-1]['close'],klines.iloc[-1]['volume'],num) num=num+1 print('完全结束',symbol) symbol_list=['SHFE.cu2102'] api_master = TqApi(auth=TqAuth("xxxx", "xxxxxx")) for symbol in symbol_list: api_master.create_task(HL_1(api_master,symbol)) with closing(api_master): while True: api_master.wait_update()
这段代码不能正常运行
代码2
import pandas as pd import datetime import time from tqsdk import TqApi, TqBacktest, TargetPosTask,tafunc,TqAccount,TqAuth from contextlib import closing async def HL_1(api,symbol): data_length=10 klines=api.get_kline_serial(symbol, duration_seconds=60*1440, data_length=data_length) async with api.register_update_notify(klines) as update_chan: num=0 while True: if num>=10: print(symbol,'结束') break async for _ in update_chan: #if api.is_changing(klines,['close']): print(klines.iloc[-1]['close'],klines.iloc[-1]['volume'],num) num=num+1 print('完全结束',symbol) symbol_list=['SHFE.cu2102'] api_master = TqApi(auth=TqAuth("xxxxx", "xxxxxxx")) for symbol in symbol_list: api_master.create_task(HL_1(api_master,symbol)) with closing(api_master): while True: api_master.wait_update()
代码2 是可以正常运行的。
为什么,在 async for _ in update_chan: 里边加上 api.is_changing(klines,[‘close’]) 就不再运行了呢?
ringo 已回答的问题 2020年12月10日
确实有效,谢谢 !