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

View File

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