Actually, require `mkt_by_fqme` in `.iter_trans()`

rekt_pps
Tyler Goodlet 2023-04-17 16:30:58 -04:00
parent f106472bcb
commit 7ee6f36e62
1 changed files with 11 additions and 13 deletions

View File

@ -143,8 +143,8 @@ class TransactionLedger(UserDict):
def iter_trans( def iter_trans(
self, self,
mkt_by_fqme: dict[str, MktPair],
broker: str = 'paper', broker: str = 'paper',
mkt_by_fqme: dict[str, MktPair] | None = None,
) -> Generator[ ) -> Generator[
tuple[str, Transaction], tuple[str, Transaction],
@ -176,7 +176,12 @@ class TransactionLedger(UserDict):
fqme = txdict.get('fqme', txdict['fqsn']) fqme = txdict.get('fqme', txdict['fqsn'])
dt = parse(txdict['dt']) dt = parse(txdict['dt'])
expiry = txdict.get('expiry') expiry = txdict.get('expiry')
mkt_by_fqme = mkt_by_fqme or {}
mkt = mkt_by_fqme.get(fqme)
if not mkt:
# we can't build a trans if we don't have
# the ``.sys: MktPair`` info, so skip.
continue
yield ( yield (
tid, tid,
@ -189,29 +194,22 @@ class TransactionLedger(UserDict):
cost=txdict.get('cost', 0), cost=txdict.get('cost', 0),
bs_mktid=txdict['bs_mktid'], bs_mktid=txdict['bs_mktid'],
# optional # TODO: change to .sys!
sym=mkt_by_fqme[fqme] if mkt_by_fqme else None, sym=mkt,
expiry=parse(expiry) if expiry else None, expiry=parse(expiry) if expiry else None,
) )
) )
def to_trans( def to_trans(
self, self,
broker: str = 'paper',
**kwargs, **kwargs,
) -> dict[str, Transaction]: ) -> dict[str, Transaction]:
''' '''
Return the entire output from ``.iter_trans()`` in a ``dict``. Return entire output from ``.iter_trans()`` in a ``dict``.
''' '''
return dict( return dict(self.iter_trans(**kwargs))
self.iter_trans(
broker,
**kwargs,
)
)
@cm @cm