912 浏览
0

async with api.register_update_notify() as update_chan:

async for _ in update_chan:
“““““““““““`
“““““““““““`
““““““““““““`
if api.is_changing(quote, “last_price”):
if 多单浮动盈利 > 100:
target_pos.set_target_volume(0) # 平仓
# 下边是查询持有的多单
position = api.get_position(SYMBOL)
Dd_1 = position.pos_long # 多单持仓

while Dd_1>0:
api.wait_update()
# 确保多单平仓完成,给我发送一个消息

matols 发表新评论 2022年7月27日

建议如果需要准确控制或识别,需要自己做一个多空单的状态库管理。
self.btag=0 #交易状态 0初始化 1开仓挂单 2持仓中 3平仓挂单 4清仓
self.stag=0

然后每次更新后进行状态为替换、更新、重置

0

确实写的有问题,需要持续调用wait_update。。你看下我们target_volume使用的官方例子吧,通知这个好说,可以看一下我们的钉钉的例子,或者你找下对应的api,再简单点就本地log保存。

https://doc.shinnytech.com/tqsdk/latest/reference/tqsdk.lib.html?highlight=volume#tqsdk.TargetPosTask.set_target_volume

https://doc.shinnytech.com/tqsdk/latest/advanced/dingding.html

李思恒 已回答的问题 2022年7月27日
您正在查看1个答案中的1个,单击此处查看所有答案。