[Fix]close #1507
This commit is contained in:
parent
20b5ef4e9b
commit
38f00a24ed
@ -486,6 +486,11 @@ class CtpTdApi(TdApi):
|
|||||||
)
|
)
|
||||||
self.positions[key] = position
|
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
|
# For SHFE position data update
|
||||||
if position.exchange == Exchange.SHFE:
|
if position.exchange == Exchange.SHFE:
|
||||||
if data["YdPosition"] and not data["TodayPosition"]:
|
if data["YdPosition"] and not data["TodayPosition"]:
|
||||||
@ -495,7 +500,7 @@ class CtpTdApi(TdApi):
|
|||||||
position.yd_volume = data["Position"] - data["TodayPosition"]
|
position.yd_volume = data["Position"] - data["TodayPosition"]
|
||||||
|
|
||||||
# Calculate previous position cost
|
# Calculate previous position cost
|
||||||
cost = position.price * position.volume
|
cost = position.price * position.volume * size
|
||||||
|
|
||||||
# Update new position volume
|
# Update new position volume
|
||||||
position.volume += data["Position"]
|
position.volume += data["Position"]
|
||||||
@ -504,7 +509,7 @@ class CtpTdApi(TdApi):
|
|||||||
# Calculate average position price
|
# Calculate average position price
|
||||||
if position.volume:
|
if position.volume:
|
||||||
cost += data["PositionCost"]
|
cost += data["PositionCost"]
|
||||||
position.price = cost / position.volume
|
position.price = cost / (position.volume * size)
|
||||||
|
|
||||||
# Get frozen volume
|
# Get frozen volume
|
||||||
if position.direction == Direction.LONG:
|
if position.direction == Direction.LONG:
|
||||||
|
Loading…
Reference in New Issue
Block a user