逻辑:
实盘情况下获取总的持仓
结果:

代码:
def my_get_positions(self):
"""获取当前持仓列表"""
buy_num = 0
sell_num = 0
positions = self.cta_engine.main_engine.get_all_positions()
# positions = self.cta_engine.get_all_positions()
# self.write_log(f" my_get_positions:{len(positions)}")
for position in positions:
if position.vt_symbol==self.vt_symbol:
if position.direction == Direction.LONG:
buy_num +=position.volume
if position.direction == Direction.SHORT:
sell_num += position.volume
self.write_log(
f"postions: {position.vt_symbol}, {self.vt_symbol} id :{position.vt_positionid} 方向: {position.direction}, 数量: {position.volume}, 均价: {position.price}, 盈亏: {position.pnl}")
return buy_num,sell_num
# 实盘的情况下获取持仓
if self.cta_engine.get_engine_type() ==EngineType.LIVE: #EngineType.BACKTESTING
buy_num,sell_num = self.my_get_positions()
为什么不一样呢,哪里有问题呢
这是界面的持仓:


