[Fix]spread contract with no size info will cause no position update

This commit is contained in:
vn.py 2019-04-13 08:44:43 +08:00
parent 8994f525b0
commit 4c83b08315

View File

@ -487,11 +487,6 @@ class CtpTdApi(TdApi):
)
self.positions[key] = position
# Get contract size, return if size value not collected
size = symbol_size_map.get(position.symbol, None)
if not size:
return
# For SHFE position data update
if position.exchange == Exchange.SHFE:
if data["YdPosition"] and not data["TodayPosition"]:
@ -500,6 +495,9 @@ class CtpTdApi(TdApi):
else:
position.yd_volume = data["Position"] - data["TodayPosition"]
# Get contract size (spread contract has no size value)
size = symbol_size_map.get(position.symbol, 0)
# Calculate previous position cost
cost = position.price * position.volume * size
@ -508,7 +506,7 @@ class CtpTdApi(TdApi):
position.pnl += data["PositionProfit"]
# Calculate average position price
if position.volume:
if position.volume and size:
cost += data["PositionCost"]
position.price = cost / (position.volume * size)