python新手,借鉴论坛里一位大师的帖子写的代码,每次运行时都会报task was destroyed but it is pending;对于多个合约,似乎只有部分合约能正常运行。困扰了我好几天了,在用户论坛和百度搜索上都没找到解决办法,真诚请教大家,请大家指点迷津。
代码主要结构如下:
from datetime import date
from tqsdk import TqApi, TqSim, TqAuth, TargetPosTask, TqReplay, TqKq, TqAccount
from tqsdk.ta import ATR
from contextlib import closing
import json
async def demo(symbol, list_price, i, atr_limit, loss_price, filename, filename1):
quote = api.get_quote(symbol)
klines = api.get_kline_serial(symbol, 24 * 60 * 60, 100)
target_pos = TargetPosTask(api, symbol)
async with api.register_update_notify([quote, klines]) as update_chan:
async for _ in update_chan:
………………
list_symbol = [“CZCE.TA109”, “CZCE.MA109”, “CZCE.SR109”, “CZCE.RM109”, “CZCE.UR109”, “DCE.c2109”, “DCE.pp2109”, “DCE.cs2109”, “SHFE.bu2109”, “SHFE.fu2109”]
##模拟盘
api = TqApi(TqKq(), auth=TqAuth(“XX”, “XX”))
i = 0
for x in list_symbol:
api.create_task(demo(x, list_price, i, atr_limit, loss_price, filename, filename1))
i = i + 1
with closing(api):
while True:
api.wait_update()