Skip to content

Commit

Permalink
[Mod] use primaryExchange when exchange data not available
Browse files Browse the repository at this point in the history
  • Loading branch information
vnpy committed Jul 29, 2019
1 parent b755f9f commit 640150c
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions vnpy/gateway/ib/ib_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,16 @@ def updatePortfolio( # pylint: disable=invalid-name
accountName,
)

if not contract.exchange:
if contract.exchange:
exchange = EXCHANGE_IB2VT.get(contract.exchange, None)
elif contract.primaryExchange:
exchange = EXCHANGE_IB2VT.get(contract.primaryExchange, None)
else:
exchange = Exchange.SMART # Use smart routing for default

if not exchange:
msg = f"存在不支持的交易所持仓{contract.conId} {contract.exchange} {contract.primaryExchange}"
self.gateway.write_log(msg)
return

ib_size = contract.multiplier
Expand All @@ -444,7 +453,7 @@ def updatePortfolio( # pylint: disable=invalid-name

pos = PositionData(
symbol=contract.conId,
exchange=EXCHANGE_IB2VT.get(contract.exchange, contract.exchange),
exchange=exchange,
direction=Direction.NET,
volume=position,
price=price,
Expand Down

0 comments on commit 640150c

Please sign in to comment.