Call `open_ledger_dfs()` for `disect` sub-cmd

Drop all the old `polars` (groupby + agg related) mangling to get a df
per fqme by delegating to the new routine and add in the `.cumsum()`ing
(per frame) as a first start on computing pps using dfs instead of
python dicts + loops as in `ppu()`.
account_tests
Tyler Goodlet 2023-07-10 09:13:59 -04:00
parent 8f1983fd8e
commit 3704e2ceac
1 changed files with 26 additions and 28 deletions

View File

@ -40,10 +40,8 @@ from ._ledger import (
# open_trade_ledger, # open_trade_ledger,
# TransactionLedger, # TransactionLedger,
) )
from ._pos import ( from .calc import (
PpTable, open_ledger_dfs,
load_pps_from_ledger,
# load_account,
) )
@ -241,8 +239,10 @@ def disect(
# "fully_qualified_account_name" # "fully_qualified_account_name"
fqan: str, fqan: str,
fqme: str, # for ib fqme: str, # for ib
pdb: bool = False,
# TODO: in tractor we should really have
# a debug_mode ctx for wrapping any kind of code no?
pdb: bool = False,
bs_mktid: str = typer.Option( bs_mktid: str = typer.Option(
None, None,
"-bid", "-bid",
@ -252,34 +252,32 @@ def disect(
"-l", "-l",
), ),
): ):
from piker.log import get_console_log
get_console_log(loglevel)
pair: tuple[str, str] pair: tuple[str, str]
if not (pair := unpack_fqan(fqan)): if not (pair := unpack_fqan(fqan)):
raise ValueError('{fqan} malformed!?') raise ValueError('{fqan} malformed!?')
brokername, account = pair brokername, account = pair
# ledger: TransactionLedger # ledger dfs groupby-partitioned by fqme
# records: dict[str, dict] dfs: dict[str, pl.DataFrame]
table: PpTable with open_ledger_dfs(
df: pl.DataFrame # legder df
ppt: pl.DataFrame # piker position table
df, ppt, table = load_pps_from_ledger(
brokername, brokername,
account, account,
filter_by_ids={'fqme': [fqme]}, ) as dfs:
)
# sers = [ for key in dfs:
# pl.Series(e['fqme'], e['cumsum']) df = dfs[key]
# for e in ppt.to_dicts() dfs[key] = df.with_columns([
# ] pl.cumsum('size').alias('cumsum'),
# ppt_by_id: pl.DataFrame = ppt.filter( ])
# pl.col('fqme') == fqme,
# ) ppt = dfs[fqme]
assert not df.is_empty() assert not df.is_empty()
breakpoint() assert not ppt.is_empty()
# with open_trade_ledger(
# brokername, # TODO: we REALLY need a better console REPL for this
# account, # kinda thing..
# ) as ledger: breakpoint()
# for tid, rec in ledger.items():
# bs_mktid: str = rec['bs_mktid']