[Fix]spread contract with no size info will cause no position update
This commit is contained in:
parent
8994f525b0
commit
4c83b08315
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user