#!/usr/bin/env python # -*- coding: utf-8 -*- __author__ = "Ringo" from tqsdk import TqApi, TargetPosTask api = TqApi() SYMBOL = "SHFE.au1912" position = api.get_position(SYMBOL) target_pos = TargetPosTask(api, SYMBOL) while True: api.wait_update() # 设定目标持仓手数,具体下单动作在下一次api.wait_update()发出 target_pos.set_target_volume(20) # 判断目标持仓是否完成 if position.pos == 20: print("目标持仓已完成") break api.close()