[Mod] complete test of mini_gateway
This commit is contained in:
parent
c7621cbfa3
commit
cf7b89365a
@ -469,50 +469,47 @@ class MiniTdApi(TdApi):
|
|||||||
|
|
||||||
def onRspQryInvestorPosition(self, data: dict, error: dict, reqid: int, last: bool):
|
def onRspQryInvestorPosition(self, data: dict, error: dict, reqid: int, last: bool):
|
||||||
""""""
|
""""""
|
||||||
if not data:
|
if data:
|
||||||
print(data, error, reqid, last)
|
# Get buffered position object
|
||||||
return
|
key = f"{data['InstrumentID'], data['PosiDirection']}"
|
||||||
|
position = self.positions.get(key, None)
|
||||||
# Get buffered position object
|
if not position:
|
||||||
key = f"{data['InstrumentID'], data['PosiDirection']}"
|
position = PositionData(
|
||||||
position = self.positions.get(key, None)
|
symbol=data["InstrumentID"],
|
||||||
if not position:
|
exchange=symbol_exchange_map[data["InstrumentID"]],
|
||||||
position = PositionData(
|
direction=DIRECTION_MINI2VT[data["PosiDirection"]],
|
||||||
symbol=data["InstrumentID"],
|
gateway_name=self.gateway_name
|
||||||
exchange=symbol_exchange_map[data["InstrumentID"]],
|
)
|
||||||
direction=DIRECTION_MINI2VT[data["PosiDirection"]],
|
self.positions[key] = position
|
||||||
gateway_name=self.gateway_name
|
|
||||||
)
|
# For SHFE position data update
|
||||||
self.positions[key] = position
|
if position.exchange == Exchange.SHFE:
|
||||||
|
if data["YdPosition"] and not data["TodayPosition"]:
|
||||||
# For SHFE position data update
|
position.yd_volume = data["Position"]
|
||||||
if position.exchange == Exchange.SHFE:
|
# For other exchange position data update
|
||||||
if data["YdPosition"] and not data["TodayPosition"]:
|
else:
|
||||||
position.yd_volume = data["Position"]
|
position.yd_volume = data["Position"] - data["TodayPosition"]
|
||||||
# For other exchange position data update
|
|
||||||
else:
|
# Get contract size (spread contract has no size value)
|
||||||
position.yd_volume = data["Position"] - data["TodayPosition"]
|
size = symbol_size_map.get(position.symbol, 0)
|
||||||
|
|
||||||
# Get contract size (spread contract has no size value)
|
# Calculate previous position cost
|
||||||
size = symbol_size_map.get(position.symbol, 0)
|
cost = position.price * position.volume * size
|
||||||
|
|
||||||
# Calculate previous position cost
|
# Update new position volume
|
||||||
cost = position.price * position.volume * size
|
position.volume += data["Position"]
|
||||||
|
position.pnl += data["PositionProfit"]
|
||||||
# Update new position volume
|
|
||||||
position.volume += data["Position"]
|
# Calculate average position price
|
||||||
position.pnl += data["PositionProfit"]
|
if position.volume and size:
|
||||||
|
cost += data["PositionCost"]
|
||||||
# Calculate average position price
|
position.price = cost / (position.volume * size)
|
||||||
if position.volume and size:
|
|
||||||
cost += data["PositionCost"]
|
# Get frozen volume
|
||||||
position.price = cost / (position.volume * size)
|
if position.direction == Direction.LONG:
|
||||||
|
position.frozen += data["ShortFrozen"]
|
||||||
# Get frozen volume
|
else:
|
||||||
if position.direction == Direction.LONG:
|
position.frozen += data["LongFrozen"]
|
||||||
position.frozen += data["ShortFrozen"]
|
|
||||||
else:
|
|
||||||
position.frozen += data["LongFrozen"]
|
|
||||||
|
|
||||||
if last:
|
if last:
|
||||||
for position in self.positions.values():
|
for position in self.positions.values():
|
||||||
|
Loading…
Reference in New Issue
Block a user