Don't mistakenly alias options to underlyingn for positions

cached_feeds
Tyler Goodlet 2021-03-26 11:51:00 -04:00
parent 65e7680cdd
commit f17a26c948
1 changed files with 10 additions and 2 deletions

View File

@ -37,7 +37,7 @@ import trio
import tractor import tractor
from async_generator import aclosing from async_generator import aclosing
from ib_insync.wrapper import RequestError from ib_insync.wrapper import RequestError
from ib_insync.contract import Contract, ContractDetails from ib_insync.contract import Contract, ContractDetails, Option
from ib_insync.order import Order from ib_insync.order import Order
from ib_insync.ticker import Ticker from ib_insync.ticker import Ticker
from ib_insync.objects import Position from ib_insync.objects import Position
@ -1206,10 +1206,18 @@ async def stream_and_write(
def pack_position(pos: Position) -> Dict[str, Any]: def pack_position(pos: Position) -> Dict[str, Any]:
con = pos.contract con = pos.contract
if isinstance(con, Option):
# TODO: option symbol parsing and sane display:
symbol = con.localSymbol.replace(' ', '')
else:
symbol = con.symbol
return { return {
'broker': 'ib', 'broker': 'ib',
'account': pos.account, 'account': pos.account,
'symbol': con.symbol, 'symbol': symbol,
'currency': con.currency, 'currency': con.currency,
'size': float(pos.position), 'size': float(pos.position),
'avg_price': float(pos.avgCost) / float(con.multiplier or 1.0), 'avg_price': float(pos.avgCost) / float(con.multiplier or 1.0),