帐号161407创建如下:
~~~api:[‘161407’, <tqsdk.api.TqApi object at 0x115253080>]
~~~follow_TargetPosTask_dict:{‘161407_DCE.b2006’: <tqsdk.lib.TargetPosTask object at 0x11529c588>, ‘161407_SHFE.rb2010’: <tqsdk.lib.TargetPosTask object at 0x11529c438>]
帐号161353创建如下:
~~~api:[‘161353’, <tqsdk.api.TqApi object at 0x115204a58>]
~~~follow_TargetPosTask_dict:{‘161353_DCE.b2006’: <tqsdk.lib.TargetPosTask object at 0x11529c588>, ‘161353_SHFE.rb2010’: <tqsdk.lib.TargetPosTask object at 0x11529c438>]
2个线程创建的2个不同的api,这2个api创建的合约的TargetPosTask怎么是一样的?例如DCE.b2006都是0x115c89048。这样导致,一个帐号可以正常下单,但另一个帐号无法下单。
TargetPosTask源代码,TargetPosTask是TargetPosTaskSingleton,不同合约合约可以创建不同的TargetPosTask实例,但不同帐号同一个合约还是同一个实例吧?
class TargetPosTaskSingleton(type): _instances = {} def __call__(cls, api, symbol, price="ACTIVE", offset_priority="今昨,开", trade_chan=None, *args, **kwargs): if symbol not in TargetPosTaskSingleton._instances: TargetPosTaskSingleton._instances[symbol] = super(TargetPosTaskSingleton, cls).__call__(api, symbol, price, offset_priority, trade_chan, *args, **kwargs) else: instance = TargetPosTaskSingleton._instances[symbol] if instance._offset_priority != offset_priority: raise Exception("您试图用不同的 offset_priority 参数创建两个 %s 调仓任务, offset_priority参数原为 %s, 现为 %s" % (symbol, instance._offset_priority, offset_priority)) if instance._price != price: raise Exception("您试图用不同的 price 参数创建两个 %s 调仓任务, price参数原为 %s, 现为 %s" % (symbol, instance._price, price)) return TargetPosTaskSingleton._instances[symbol] class TargetPosTask(object, metaclass=TargetPosTaskSingleton): """目标持仓 task, 该 task 可以将指定合约调整到目标头寸""" def __init__(self, api: TqApi, symbol: str, price: str = "ACTIVE", offset_priority: str = "今昨,开", trade_chan: Optional[TqChan] = None) -> None:
永锋 梁 更改状态以发布 2020年4月25日