Support `Forex` in the pp packer

fix_forex
Tyler Goodlet 2022-07-12 16:55:58 -04:00
parent 4e5df973a9
commit cef511092d
1 changed files with 21 additions and 11 deletions

View File

@ -36,6 +36,7 @@ import tractor
from ib_insync.contract import ( from ib_insync.contract import (
Contract, Contract,
Option, Option,
Forex,
) )
from ib_insync.order import ( from ib_insync.order import (
Trade, Trade,
@ -88,20 +89,29 @@ def pack_position(
# TODO: lookup fqsn even for derivs. # TODO: lookup fqsn even for derivs.
symbol = con.symbol.lower() symbol = con.symbol.lower()
# TODO: probably write a mofo exchange mapper routine since ib
# can't get it's shit together like, ever.
# try our best to figure out the exchange / venue # try our best to figure out the exchange / venue
exch = (con.primaryExchange or con.exchange).lower() exch = (con.primaryExchange or con.exchange).lower()
if not exch: if not exch:
# for wtv cucked reason some futes don't show their
# exchange (like CL.NYMEX) ... if isinstance(con, Forex):
entry = _adhoc_symbol_map.get( # bc apparently it's not in the contract obj?
con.symbol or con.localSymbol exch = 'idealfx'
)
if entry: else:
meta, kwargs = entry # for wtv cucked reason some futes don't show their
cid = meta.get('conId') # exchange (like CL.NYMEX) ...
if cid: entry = _adhoc_symbol_map.get(
assert con.conId == meta['conId'] con.symbol or con.localSymbol
exch = meta['exchange'] )
if entry:
meta, kwargs = entry
cid = meta.get('conId')
if cid:
assert con.conId == meta['conId']
exch = meta['exchange']
assert exch, f'No clue:\n {con}' assert exch, f'No clue:\n {con}'
fqsn = '.'.join((symbol, exch)) fqsn = '.'.join((symbol, exch))