diff --git a/vnpy/trader/gateway/ctpGateway/ctpGateway.py b/vnpy/trader/gateway/ctpGateway/ctpGateway.py index 37851193..bd74cc24 100644 --- a/vnpy/trader/gateway/ctpGateway/ctpGateway.py +++ b/vnpy/trader/gateway/ctpGateway/ctpGateway.py @@ -796,7 +796,8 @@ class CtpTdApi(TdApi): # 计算持仓均价 if pos.position and pos.symbol in self.symbolSizeDict: size = self.symbolSizeDict[pos.symbol] - pos.price = (cost + data['PositionCost']) / (pos.position * size) + if size > 0 and pos.position > 0: + pos.price = (cost + data['PositionCost']) / abs(pos.position * size) # 读取冻结 if pos.direction is DIRECTION_LONG: