Fix disti-mode paper pps relaying
Turns out we were putting too many brokername suffixes in the symbol field and thus the order mode msg parser wasn't matching the current asset to said msgs correctly and pps weren't being shown... This repairs that plus simplifies the order mode initial pos msg loading to just delegate into `process_trade_msg()` just as is done for real-time msg updates.size_in_shm_token
parent
02f53d0c13
commit
5c8c5d8fbf
|
@ -23,7 +23,6 @@ from contextlib import asynccontextmanager
|
|||
from datetime import datetime
|
||||
from operator import itemgetter
|
||||
import itertools
|
||||
from pprint import pformat
|
||||
import time
|
||||
from typing import (
|
||||
Any,
|
||||
|
@ -204,7 +203,7 @@ class PaperBoi(Struct):
|
|||
async def fake_fill(
|
||||
self,
|
||||
|
||||
symbol: str,
|
||||
fqsn: str,
|
||||
price: float,
|
||||
size: float,
|
||||
action: str, # one of {'buy', 'sell'}
|
||||
|
@ -258,34 +257,34 @@ class PaperBoi(Struct):
|
|||
await self.ems_trades_stream.send(msg)
|
||||
|
||||
# lookup any existing position
|
||||
token = f'{symbol}.{self.broker}'
|
||||
key = fqsn.rstrip(f'.{self.broker}')
|
||||
pp = self._positions.setdefault(
|
||||
token,
|
||||
fqsn,
|
||||
Position(
|
||||
Symbol(
|
||||
key=symbol,
|
||||
key=key,
|
||||
broker_info={self.broker: {}},
|
||||
),
|
||||
size=size,
|
||||
ppu=price,
|
||||
bsuid=symbol,
|
||||
bsuid=key,
|
||||
)
|
||||
)
|
||||
t = Transaction(
|
||||
fqsn=symbol,
|
||||
fqsn=fqsn,
|
||||
tid=oid,
|
||||
size=size,
|
||||
price=price,
|
||||
cost=0, # TODO: cost model
|
||||
dt=pendulum.from_timestamp(fill_time_s),
|
||||
bsuid=symbol,
|
||||
bsuid=key,
|
||||
)
|
||||
pp.add_clear(t)
|
||||
|
||||
pp_msg = BrokerdPosition(
|
||||
broker=self.broker,
|
||||
account='paper',
|
||||
symbol=symbol,
|
||||
symbol=fqsn,
|
||||
# TODO: we need to look up the asset currency from
|
||||
# broker info. i guess for crypto this can be
|
||||
# inferred from the pair?
|
||||
|
@ -416,7 +415,7 @@ async def simulate_fills(
|
|||
|
||||
# clearing price would have filled entirely
|
||||
await client.fake_fill(
|
||||
symbol=sym,
|
||||
fqsn=sym,
|
||||
# todo slippage to determine fill price
|
||||
price=tick_price,
|
||||
size=size,
|
||||
|
@ -443,7 +442,7 @@ async def handle_order_requests(
|
|||
# error on bad inputs
|
||||
reason = None
|
||||
if account != 'paper':
|
||||
reason = f'Paper account only. No account found: `{account}` ?'
|
||||
reason = f'No account found:`{account}` (paper only)?'
|
||||
|
||||
elif order.size == 0:
|
||||
reason = 'Invalid size: 0'
|
||||
|
@ -543,7 +542,6 @@ async def trades_dialogue(
|
|||
|
||||
# TODO: load paper positions per broker from .toml config file
|
||||
# and pass as symbol to position data mapping: ``dict[str, dict]``
|
||||
# await ctx.started(all_positions)
|
||||
await ctx.started((pp_msgs, ['paper']))
|
||||
|
||||
async with (
|
||||
|
|
|
@ -642,18 +642,7 @@ async def open_order_mode(
|
|||
# Pack position messages by account, should only be one-to-one.
|
||||
# NOTE: requires the backend exactly specifies
|
||||
# the expected symbol key in its positions msg.
|
||||
pps_by_account = {}
|
||||
for (broker, acctid), msgs in position_msgs.items():
|
||||
for msg in msgs:
|
||||
|
||||
sym = msg['symbol']
|
||||
if (
|
||||
(sym == symkey) or (
|
||||
# mega-UGH, i think we need to fix the FQSN
|
||||
# stuff sooner then later..
|
||||
sym == symkey.removesuffix(f'.{broker}'))
|
||||
):
|
||||
pps_by_account[acctid] = msg
|
||||
# pps_by_account = {}
|
||||
|
||||
# update pp trackers with data relayed from ``brokerd``.
|
||||
for account_name in accounts:
|
||||
|
@ -667,11 +656,6 @@ async def open_order_mode(
|
|||
# XXX: BLEH, do we care about this on the client side?
|
||||
bsuid=symbol,
|
||||
)
|
||||
msg = pps_by_account.get(account_name)
|
||||
if msg:
|
||||
log.info(f'Loading pp for {symkey}:\n{pformat(msg)}')
|
||||
startup_pp.update_from_msg(msg)
|
||||
|
||||
# allocator config
|
||||
alloc = mk_allocator(
|
||||
symbol=symbol,
|
||||
|
@ -789,6 +773,15 @@ async def open_order_mode(
|
|||
# Begin order-response streaming
|
||||
done()
|
||||
|
||||
for (broker, acctid), msgs in position_msgs.items():
|
||||
for msg in msgs:
|
||||
log.info(f'Loading pp for {symkey}:\n{pformat(msg)}')
|
||||
await process_trade_msg(
|
||||
mode,
|
||||
book,
|
||||
msg,
|
||||
)
|
||||
|
||||
# start async input handling for chart's view
|
||||
async with (
|
||||
|
||||
|
|
Loading…
Reference in New Issue