Always use fully expanded FQME throughout `.clearing`

Since crypto backends now also may expand an FQME like `xbteur.kraken`
-> `xbteur.spot.kraken` (by filling in the venue token), we need to use
this identifier when looking up per-market order dialogs or submitting
new requests. The simple fix is to simply look up that expanded from
from the `Feed.flumes` table which is always keyed by the `MktPair.fqme:
str` - the expanded form.
basic_buy_bot
Tyler Goodlet 2023-06-20 12:29:50 -04:00
parent 736bbbff77
commit 020a3955d2
2 changed files with 13 additions and 11 deletions

View File

@ -395,9 +395,10 @@ async def open_brokerd_dialog(
if trades_endpoint: if trades_endpoint:
break break
else: else:
raise RuntimeError( log.warning(
f'No live trading EP found: {brokermod.name}?' f'No live trading EP found: {brokermod.name}?'
) )
exec_mode: str = 'paper'
if ( if (
trades_endpoint is not None trades_endpoint is not None
@ -408,9 +409,6 @@ async def open_brokerd_dialog(
trades_endpoint, trades_endpoint,
) )
else:
exec_mode: str = 'paper'
@acm @acm
async def maybe_open_paper_ep(): async def maybe_open_paper_ep():
if exec_mode == 'paper': if exec_mode == 'paper':
@ -523,6 +521,7 @@ class Router(Struct):
] = defaultdict(set) ] = defaultdict(set)
# TODO: mapping of ems dialog ids to msg flow history # TODO: mapping of ems dialog ids to msg flow history
# - use the new ._util.OrderDialogs?
# msgflows: defaultdict[ # msgflows: defaultdict[
# str, # str,
# ChainMap[dict[str, dict]], # ChainMap[dict[str, dict]],
@ -641,6 +640,9 @@ class Router(Struct):
loglevel=loglevel, loglevel=loglevel,
) as feed, ) as feed,
): ):
# extract expanded fqme in case input was of a less
# qualified form, eg. xbteur.kraken -> xbteur.spot.kraken
fqme: str = list(feed.flumes.keys())[0]
brokername, _, _, _ = unpack_fqme(fqme) brokername, _, _, _ = unpack_fqme(fqme)
brokermod = feed.mods[brokername] brokermod = feed.mods[brokername]
broker = brokermod.name broker = brokermod.name
@ -675,7 +677,7 @@ class Router(Struct):
client_ready = trio.Event() client_ready = trio.Event()
task_status.started( task_status.started(
(relay, feed, client_ready) (fqme, relay, feed, client_ready)
) )
# sync to the client side by waiting for the stream # sync to the client side by waiting for the stream
@ -1468,13 +1470,13 @@ async def maybe_open_trade_relays(
loglevel: str = 'info', loglevel: str = 'info',
): ):
relay, feed, client_ready = await _router.nursery.start( fqme, relay, feed, client_ready = await _router.nursery.start(
_router.open_trade_relays, _router.open_trade_relays,
fqme, fqme,
exec_mode, exec_mode,
loglevel, loglevel,
) )
yield relay, feed, client_ready yield fqme, relay, feed, client_ready
async with tractor.trionics.maybe_open_context( async with tractor.trionics.maybe_open_context(
acm_func=cached_mngr, acm_func=cached_mngr,
@ -1487,13 +1489,13 @@ async def maybe_open_trade_relays(
key=cache_on_fqme_unless_paper, key=cache_on_fqme_unless_paper,
) as ( ) as (
cache_hit, cache_hit,
(relay, feed, client_ready) (fqme, relay, feed, client_ready)
): ):
if cache_hit: if cache_hit:
log.info(f'Reusing existing trades relay for {fqme}:\n' log.info(f'Reusing existing trades relay for {fqme}:\n'
f'{relay}\n') f'{relay}\n')
yield relay, feed, client_ready yield fqme, relay, feed, client_ready
@tractor.context @tractor.context
@ -1576,7 +1578,7 @@ async def _emsd_main(
fqme, fqme,
exec_mode, exec_mode,
loglevel, loglevel,
) as (relay, feed, client_ready): ) as (fqme, relay, feed, client_ready):
brokerd_stream = relay.brokerd_stream brokerd_stream = relay.brokerd_stream
dark_book = _router.get_dark_book(broker) dark_book = _router.get_dark_book(broker)

View File

@ -574,7 +574,7 @@ async def open_trade_dialog(
if fqme: if fqme:
bs_fqme, _, broker = fqme.rpartition('.') bs_fqme, _, broker = fqme.rpartition('.')
mkt, _ = await brokermod.get_mkt_info(bs_fqme) mkt, _ = await brokermod.get_mkt_info(bs_fqme)
mkt_by_fqme[fqme] = mkt mkt_by_fqme[mkt.fqme] = mkt
# for each sym in the ledger load it's `MktPair` info # for each sym in the ledger load it's `MktPair` info
for tid, txdict in ledger.data.items(): for tid, txdict in ledger.data.items():