paper engine: use the `fqme` for the `bs_mktid`

Instead of stripping the broker part just use the full fqme for all
`Transaction.bs_mktid: str` values since it makes indexing the `PpTable`
much easier with less key mangling..
rekt_pps
Tyler Goodlet 2023-04-04 13:31:55 -04:00
parent 9770a39d7b
commit f51361435f
1 changed files with 11 additions and 7 deletions

View File

@ -249,8 +249,10 @@ class PaperBoi(Struct):
)
await self.ems_trades_stream.send(msg)
# lookup any existing position
key = fqme.rstrip(f'.{self.broker}')
# NOTE: for paper we set the "bs_mktid" as just the fqme since
# we don't actually have any unique backend symbol ourselves
# other then this thing, our fqme address.
bs_mktid: str = fqme
t = Transaction(
fqsn=fqme,
sym=self._syms[fqme],
@ -259,7 +261,7 @@ class PaperBoi(Struct):
price=price,
cost=0, # TODO: cost model
dt=pendulum.from_timestamp(fill_time_s),
bs_mktid=key,
bs_mktid=bs_mktid,
)
tx = t.to_dict()
@ -270,17 +272,19 @@ class PaperBoi(Struct):
self.ppt.update_from_trans({oid: t})
# transmit pp msg to ems
pp = self.ppt.pps[key]
pp = self.ppt.pps[bs_mktid]
pp_msg = BrokerdPosition(
broker=self.broker,
account='paper',
symbol=fqme,
size=pp.size,
avg_price=pp.ppu,
# TODO: we need to look up the asset currency from
# broker info. i guess for crypto this can be
# inferred from the pair?
currency=key,
size=pp.size,
avg_price=pp.ppu,
# currency=bs_mktid,
)
await self.ems_trades_stream.send(pp_msg)