Add (hacky) forex pair support to `Client.find_contract()`
parent
e0491cf2e7
commit
6a1a62d8c0
|
@ -205,6 +205,19 @@ _adhoc_futes_set = {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# taken from list here:
|
||||||
|
# https://www.interactivebrokers.com/en/trading/products-spot-currencies.php
|
||||||
|
_adhoc_fiat_set = set((
|
||||||
|
'USD, AED, AUD, CAD,'
|
||||||
|
'CHF, CNH, CZK, DKK,'
|
||||||
|
'EUR, GBP, HKD, HUF,'
|
||||||
|
'ILS, JPY, MXN, NOK,'
|
||||||
|
'NZD, PLN, RUB, SAR,'
|
||||||
|
'SEK, SGD, TRY, ZAR'
|
||||||
|
).split(' ,')
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# map of symbols to contract ids
|
# map of symbols to contract ids
|
||||||
_adhoc_symbol_map = {
|
_adhoc_symbol_map = {
|
||||||
# https://misc.interactivebrokers.com/cstools/contract_info/v3.10/index.php?action=Conid%20Info&wlId=IB&conid=69067924
|
# https://misc.interactivebrokers.com/cstools/contract_info/v3.10/index.php?action=Conid%20Info&wlId=IB&conid=69067924
|
||||||
|
@ -480,6 +493,14 @@ class Client:
|
||||||
except RequestError as err:
|
except RequestError as err:
|
||||||
log.warning(err.message)
|
log.warning(err.message)
|
||||||
|
|
||||||
|
# forex pairs
|
||||||
|
elif sectype == 'CASH':
|
||||||
|
dst, src = tract.localSymbol.split('.')
|
||||||
|
pair_key = "/".join([dst, src])
|
||||||
|
tract.exchange = 'FOREX'
|
||||||
|
results[f'{pair_key}.forex'] = tract
|
||||||
|
results.pop(key)
|
||||||
|
|
||||||
return results
|
return results
|
||||||
|
|
||||||
async def get_fute(
|
async def get_fute(
|
||||||
|
@ -521,7 +542,7 @@ class Client:
|
||||||
async def find_contract(
|
async def find_contract(
|
||||||
self,
|
self,
|
||||||
pattern: str,
|
pattern: str,
|
||||||
currency: str = 'USD',
|
currency: str = '',
|
||||||
**kwargs,
|
**kwargs,
|
||||||
|
|
||||||
) -> Contract:
|
) -> Contract:
|
||||||
|
@ -537,12 +558,27 @@ class Client:
|
||||||
# XXX UPDATE: we can probably do the tick/trades scraping
|
# XXX UPDATE: we can probably do the tick/trades scraping
|
||||||
# inside our eventkit handler instead to bypass this entirely?
|
# inside our eventkit handler instead to bypass this entirely?
|
||||||
|
|
||||||
|
# fqsn parsing stage
|
||||||
|
# ------------------
|
||||||
if '.ib' in pattern:
|
if '.ib' in pattern:
|
||||||
from ..data._source import unpack_fqsn
|
from ..data._source import unpack_fqsn
|
||||||
broker, symbol, expiry = unpack_fqsn(pattern)
|
broker, symbol, expiry = unpack_fqsn(pattern)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
symbol = pattern
|
symbol = pattern
|
||||||
|
|
||||||
|
# another hack for forex pairs lul.
|
||||||
|
if (
|
||||||
|
'.forex' in symbol
|
||||||
|
# and not '.ib' in pattern
|
||||||
|
# or '/' in symbol
|
||||||
|
):
|
||||||
|
exch = 'FOREX'
|
||||||
|
symbol = symbol.removesuffix('.forex')
|
||||||
|
if '/' in symbol:
|
||||||
|
symbol, currency = symbol.split('/')
|
||||||
|
|
||||||
|
else:
|
||||||
# try:
|
# try:
|
||||||
# # give the cache a go
|
# # give the cache a go
|
||||||
# return self._contracts[symbol]
|
# return self._contracts[symbol]
|
||||||
|
@ -557,6 +593,9 @@ class Client:
|
||||||
|
|
||||||
qualify: bool = True
|
qualify: bool = True
|
||||||
|
|
||||||
|
# contract searching stage
|
||||||
|
# ------------------------
|
||||||
|
|
||||||
# futes
|
# futes
|
||||||
if exch in _futes_venues:
|
if exch in _futes_venues:
|
||||||
if expiry:
|
if expiry:
|
||||||
|
@ -578,10 +617,11 @@ class Client:
|
||||||
qualify = False
|
qualify = False
|
||||||
|
|
||||||
elif exch in ('FOREX'):
|
elif exch in ('FOREX'):
|
||||||
currency = ''
|
# if '/' in symbol:
|
||||||
symbol, currency = sym.split('/')
|
# currency = ''
|
||||||
|
# symbol, currency = sym.split('/')
|
||||||
con = ibis.Forex(
|
con = ibis.Forex(
|
||||||
symbol=symbol,
|
pair=''.join((symbol, currency)),
|
||||||
currency=currency,
|
currency=currency,
|
||||||
)
|
)
|
||||||
con.bars_kwargs = {'whatToShow': 'MIDPOINT'}
|
con.bars_kwargs = {'whatToShow': 'MIDPOINT'}
|
||||||
|
@ -649,6 +689,7 @@ class Client:
|
||||||
async def get_sym_details(
|
async def get_sym_details(
|
||||||
self,
|
self,
|
||||||
symbol: str,
|
symbol: str,
|
||||||
|
|
||||||
) -> tuple[Contract, Ticker, ContractDetails]:
|
) -> tuple[Contract, Ticker, ContractDetails]:
|
||||||
|
|
||||||
contract = await self.find_contract(symbol)
|
contract = await self.find_contract(symbol)
|
||||||
|
|
Loading…
Reference in New Issue