Factor df conversion into lone routine: `ledger_to_dfs()`
parent
5d24b5defb
commit
85ae180f8f
|
@ -353,13 +353,11 @@ def open_ledger_dfs(
|
||||||
can update the ledger on exit.
|
can update the ledger on exit.
|
||||||
|
|
||||||
'''
|
'''
|
||||||
from ._ledger import (
|
|
||||||
open_trade_ledger,
|
|
||||||
)
|
|
||||||
|
|
||||||
if not ledger:
|
if not ledger:
|
||||||
import time
|
import time
|
||||||
from tractor._debug import open_crash_handler
|
from tractor._debug import open_crash_handler
|
||||||
|
from ._ledger import open_trade_ledger
|
||||||
|
|
||||||
now = time.time()
|
now = time.time()
|
||||||
with (
|
with (
|
||||||
|
@ -388,7 +386,16 @@ def open_ledger_dfs(
|
||||||
# allow_reload=True,
|
# allow_reload=True,
|
||||||
# )
|
# )
|
||||||
|
|
||||||
|
yield ledger_to_dfs(ledger), ledger
|
||||||
|
|
||||||
|
|
||||||
|
def ledger_to_dfs(
|
||||||
|
ledger: TransactionLedger,
|
||||||
|
|
||||||
|
) -> dict[str, pl.DataFrame]:
|
||||||
|
|
||||||
txns: dict[str, Transaction] = ledger.to_txns()
|
txns: dict[str, Transaction] = ledger.to_txns()
|
||||||
|
|
||||||
# ldf = pl.DataFrame(
|
# ldf = pl.DataFrame(
|
||||||
# list(txn.to_dict() for txn in txns.values()),
|
# list(txn.to_dict() for txn in txns.values()),
|
||||||
ldf = pl.from_dicts(
|
ldf = pl.from_dicts(
|
||||||
|
@ -615,8 +622,10 @@ def open_ledger_dfs(
|
||||||
df[i, 'pos_bep'] = pos_bep
|
df[i, 'pos_bep'] = pos_bep
|
||||||
|
|
||||||
df[i, 'pos_ppu'] = ppu
|
df[i, 'pos_ppu'] = ppu
|
||||||
|
|
||||||
|
# keep backrefs to suffice reccurence relation
|
||||||
last_ppu: float = ppu
|
last_ppu: float = ppu
|
||||||
last_cumsize: float = cumsize
|
last_cumsize: float = cumsize
|
||||||
last_is_enter: bool = is_enter
|
last_is_enter: bool = is_enter
|
||||||
|
|
||||||
yield dfs, ledger
|
return dfs
|
||||||
|
|
Loading…
Reference in New Issue