From 99f2de2161eb098cefd5c0bf21955558ad2f1f63 Mon Sep 17 00:00:00 2001 From: msincenselee Date: Tue, 30 Jan 2018 21:39:26 +0800 Subject: [PATCH] bug fix --- vnpy/trader/gateway/ctpGateway/ctpGateway.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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: