Add option and adhoc meta-info support to `con2fqsn()`

fix_forex
Tyler Goodlet 2022-07-21 10:14:29 -04:00
parent a27431c34f
commit fb39da19f4
1 changed files with 16 additions and 1 deletions

View File

@ -47,6 +47,7 @@ import ib_insync as ibis
from ib_insync.contract import ( from ib_insync.contract import (
Contract, Contract,
ContractDetails, 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
@ -473,7 +474,6 @@ class Client:
pattern, pattern,
upto=upto, upto=upto,
) )
for key, deats in results.copy().items(): for key, deats in results.copy().items():
tract = deats.contract tract = deats.contract
@ -968,6 +968,10 @@ def con2fqsn(
expiry = con.lastTradeDateOrContractMonth or '' expiry = con.lastTradeDateOrContractMonth or ''
match con: match con:
case Option():
# TODO: option symbol parsing and sane display:
symbol = con.localSymbol.replace(' ', '')
case ibis.Commodity(): case ibis.Commodity():
# commodities and forex don't have an exchange name and # commodities and forex don't have an exchange name and
# no real volume so we have to calculate the price # no real volume so we have to calculate the price
@ -984,6 +988,17 @@ def con2fqsn(
# no real volume on forex feeds.. # no real volume on forex feeds..
calc_price = True calc_price = True
if not suffix:
entry = _adhoc_symbol_map.get(
con.symbol or con.localSymbol
)
if entry:
meta, kwargs = entry
cid = meta.get('conId')
if cid:
assert con.conId == meta['conId']
suffix = meta['exchange']
# append a `.<suffix>` to the returned symbol # append a `.<suffix>` to the returned symbol
# key for derivatives that normally is the expiry # key for derivatives that normally is the expiry
# date key. # date key.