From 642ef2a1cb89cabe0f10c127319617f335520004 Mon Sep 17 00:00:00 2001 From: msincenselee Date: Thu, 6 Jun 2019 10:36:51 +0800 Subject: [PATCH] bug fix --- vnpy/trader/gateway/ctpGateway/ctpGateway.py | 4 ++-- vnpy/trader/gateway/ctpseGateway/ctpseGateway.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/vnpy/trader/gateway/ctpGateway/ctpGateway.py b/vnpy/trader/gateway/ctpGateway/ctpGateway.py index 31c5ee3e..69d74d9c 100644 --- a/vnpy/trader/gateway/ctpGateway/ctpGateway.py +++ b/vnpy/trader/gateway/ctpGateway/ctpGateway.py @@ -1061,7 +1061,7 @@ class CtpTdApi(TdApi): # 仓位累加汇总 pos.position += data['Position'] - if pos.position and size: + if pos.position > 0 and size > 0: # 计算持仓均价 pos.price = (pre_cost + data['OpenCost']) / (pos.position * size) @@ -1069,7 +1069,7 @@ class CtpTdApi(TdApi): pre_settlement_price = data['PreSettlementPrice'] # 当前一笔的开仓均价 - open_cost_price = (data['OpenCost'] / (data['Position'] * size)) if data['Position'] > 0 else 0.0 + open_cost_price = (data['OpenCost'] / (data['Position'] * size)) if data['Position'] * size != 0 else 0.0 pre_profit = 0 # 上-交易日收益 = (上一交易日结算价 - 开仓价)* 昨仓持仓数量 * 杠杆 diff --git a/vnpy/trader/gateway/ctpseGateway/ctpseGateway.py b/vnpy/trader/gateway/ctpseGateway/ctpseGateway.py index 1bb21950..a070c7f7 100644 --- a/vnpy/trader/gateway/ctpseGateway/ctpseGateway.py +++ b/vnpy/trader/gateway/ctpseGateway/ctpseGateway.py @@ -1077,7 +1077,7 @@ class CtpTdApi(TdApi): # 仓位累加汇总 pos.position += data['Position'] - if pos.position and size: + if pos.position > 0 and size > 0: # 计算持仓均价 pos.price = (pre_cost + data['OpenCost']) / (pos.position * size) @@ -1085,7 +1085,7 @@ class CtpTdApi(TdApi): pre_settlement_price = data['PreSettlementPrice'] # 当前一笔的开仓均价 - open_cost_price = (data['OpenCost'] / (data['Position'] * size)) if data['Position'] > 0 else 0.0 + open_cost_price = (data['OpenCost'] / (data['Position'] * size)) if data['Position'] * size != 0 else 0.0 pre_profit = 0 # 上-交易日收益 = (上一交易日结算价 - 开仓价)* 昨仓持仓数量 * 杠杆