Support loading quarterly futes existing lives

Do parsing of the `'symbol'` and check for an `_<expiry>` suffix, in
which case we re-format in capitalized FQME style, do the
`Client._pairs[str, Pair]` lookup and then send the `Pair.bs_fqme` in
the `Order.fqme: str` field.
basic_buy_bot
Tyler Goodlet 2023-06-19 12:30:43 -04:00
parent 7f39de59d4
commit 77db2fa7c8
2 changed files with 21 additions and 20 deletions

View File

@ -647,29 +647,32 @@ class Client:
signed=True, signed=True,
action='get', action='get',
) )
# figure out which venue (in FQME terms) we're using
# since that normally maps 1-to-1 with the account (right?)
venue: str = self.mkt_mode.rstrip('_futes')
orders: list[Order] = [] orders: list[Order] = []
for entry in resp: for entry in resp:
oid: str = entry['clientOrderId'] oid: str = entry['clientOrderId']
symbol: str = entry['symbol']
# XXX TODO XXX: it appears as though entries have no # build out a fqme-styled key that should map to a pair
# indicator from the symbology system which market # entry in `._pairs` cross-venue table.
# / venue the order is from.. which normally isn't bs_mktid, _, expiry = entry['symbol'].partition('_')
# a huge deal since you could assume based on the bs_mktid += f'.{venue.upper()}'
# endpoint you made the request to, BUT the futes USD-M
# endpoints have multiple contracts for the same if expiry:
# symbols (eg. BTCUSDT.PERP, BTCUSDT.230630.. etc.) bs_mktid += f'.{expiry}'
# NOTE: for now until we have a better system we're else:
# going to assume orders that don't have some kind of bs_mktid += '.PERP'
# further info in the order resp dict are perps though
# likely this will need to change in the future.. # should never key error if we've got it right B)
venue: str = self.mkt_mode.rstrip('_futes') pair: Pair = self._pairs[bs_mktid]
bs_mktid: str = entry['symbol']
fqme: str = f'{bs_mktid.lower()}.{venue}.perp'
orders.append( orders.append(
Order( Order(
oid=oid, oid=oid,
symbol=fqme, symbol=pair.bs_fqme.lower(),
action=entry['side'].lower(), action=entry['side'].lower(),
price=float(entry['price']), price=float(entry['price']),

View File

@ -373,11 +373,9 @@ async def open_trade_dialog(
ctx.open_stream() as ems_stream, ctx.open_stream() as ems_stream,
): ):
# deliver all pre-exist open orders to EMS thus syncing # deliver all pre-exist open orders to EMS thus syncing
# state with the binance existing live limit set. # state with existing live limits reported by them.
open_orders: list[Order] = await client.get_open_orders() order: Order
for order in await client.get_open_orders():
# fill out `Status` with boxed `Order`s and sync the EMS.
for order in open_orders:
status_msg = Status( status_msg = Status(
time_ns=time.time_ns(), time_ns=time.time_ns(),
resp='open', resp='open',