例如:
import asyncio
from tqsdk import TqApi, TqAccount, TargetPosTask
import time
api = TqApi(TqAccount("Z中信建投", 'xxx', 'xxx'))
target1 = TargetPosTask(api, "DCE.m2001")
target2 = TargetPosTask(api, "DCE.m2002")
position1 = api.get_position("DCE.m2001")
position2 = api.get_position("DCE.m2002")
async def _wait():
await asyncio.sleep(0.1)
api.wait_update(time.time() + 2)
async def wait():
while True:
await _wait()
if api.is_changing(position1) and api.is_changing(position2):
return
async def fun(target, aim):
target.set_target_volume(aim)
loop = asyncio.get_event_loop()
loop.run_until_complete(
asyncio.gather(
fun(target1, 1), fun(target2, -1), wait()
)
)
才疏学浅, 看你们的源码实在头疼. 麻烦了. 还有如果不行的话,请问有没有什么补救措施, 我主要是想在wait_update的间隙内夹杂一点私货.
west 已回答的问题 2019年10月9日
不能在协程中调用 wait_update, 如需在协程中等待业务数据更新请使用 register_update_notify,你可以参考网格交易的异步demo,https://github.com/shinnytech/tqsdk-python/blob/master/tqsdk/demo/example/gridtrading_async.py
west 已回答的问题 2019年10月9日