`kraken`: write ledger and pps files on startup

pre_overruns_ctxcancelled
Tyler Goodlet 2023-03-29 20:02:20 -04:00
parent fb90c2049f
commit 5cb63a67e1
1 changed files with 16 additions and 5 deletions

View File

@ -43,6 +43,7 @@ from piker.accounting import (
Position, Position,
PpTable, PpTable,
Transaction, Transaction,
TransactionLedger,
open_trade_ledger, open_trade_ledger,
open_pps, open_pps,
get_likely_pair, get_likely_pair,
@ -477,28 +478,39 @@ async def trades_dialogue(
# update things correctly. # update things correctly.
simulate_pp_update: bool = False simulate_pp_update: bool = False
table: PpTable
ledger: TransactionLedger
with ( with (
open_pps( open_pps(
'kraken', 'kraken',
acctid, acctid,
write_on_exit=True, write_on_exit=True,
) as table, ) as table,
open_trade_ledger( open_trade_ledger(
'kraken', 'kraken',
acctid, acctid,
) as ledger_dict, ) as ledger,
): ):
# transaction-ify the ledger entries # transaction-ify the ledger entries
ledger_trans = norm_trade_records(ledger_dict) ledger_trans = norm_trade_records(ledger)
if not table.pps:
# NOTE: we can't use this since it first needs
# broker: str input support!
# table.update_from_trans(ledger.to_trans())
table.update_from_trans(ledger_trans)
table.write_config()
# TODO: eventually probably only load # TODO: eventually probably only load
# as far back as it seems is not deliverd in the # as far back as it seems is not deliverd in the
# most recent 50 trades and assume that by ordering we # most recent 50 trades and assume that by ordering we
# already have those records in the ledger. # already have those records in the ledger.
tids2trades = await client.get_trades() tids2trades = await client.get_trades()
ledger_dict.update(tids2trades) ledger.update(tids2trades)
if tids2trades:
ledger.write_config()
api_trans = norm_trade_records(tids2trades) api_trans = norm_trade_records(tids2trades)
# retrieve kraken reported balances # retrieve kraken reported balances
@ -506,7 +518,6 @@ async def trades_dialogue(
# what amount of trades-transactions need # what amount of trades-transactions need
# to be reloaded. # to be reloaded.
balances = await client.get_balances() balances = await client.get_balances()
# await tractor.breakpoint()
for dst, size in balances.items(): for dst, size in balances.items():