From 17b976eb88ef520b476e8a731244ab01164447bf Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Mon, 20 Mar 2023 21:54:37 -0400 Subject: [PATCH] Use `MktPair` building `Position` objects in `PpTable.update_from_trans()` --- piker/accounting/_pos.py | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/piker/accounting/_pos.py b/piker/accounting/_pos.py index 288a702e..d3ac3acf 100644 --- a/piker/accounting/_pos.py +++ b/piker/accounting/_pos.py @@ -47,7 +47,7 @@ from ._mktinfo import ( Symbol, MktPair, Asset, - unpack_fqsn, + unpack_fqme, ) from .. import config from ..brokers import get_brokermod @@ -117,7 +117,7 @@ class Position(Struct): s = d.pop('symbol') fqsn = s.fqme - broker, key, suffix = unpack_fqsn(fqsn) + broker, key, suffix = unpack_fqme(fqsn) if isinstance(s, Symbol): sym_info = s.broker_info[broker] @@ -510,18 +510,29 @@ class PpTable(Struct): key=lambda t: t.dt, reverse=True, ): + fqme = t.fqme + bs_mktid = t.bs_mktid + + # template the mkt-info presuming a legacy market ticks + # if no info exists in the transactions.. + mkt = t.sys + if not mkt: + mkt = MktPair.from_fqme( + fqme, + price_tick='0.01', + size_tick='0.0', + bs_mktid=bs_mktid, + ) + pp = pps.setdefault( - t.bs_mktid, + bs_mktid, # if no existing pp, allocate fresh one. Position( - Symbol.from_fqsn( - t.fqsn, - info={}, - ) if not t.sym else t.sym, + mkt, size=0.0, ppu=0.0, - bs_mktid=t.bs_mktid, + bs_mktid=bs_mktid, expiry=t.expiry, ) )