Look for transfers after ledger + api trans load

If we don't have a pos table built out already (in mem) we can't figure
out the likely dst asset (since there's no pair entry to guide us) that
we should use to search for withdrawal transactions; so move it later.

Further this ports to the new api changes in `piker.pp`` that will land
with #365.
kraken_ws_orders
Tyler Goodlet 2022-07-26 14:14:57 -04:00
parent 0fb31586fd
commit 168c9863cb
1 changed files with 38 additions and 24 deletions

View File

@ -286,7 +286,7 @@ def trades2pps(
)
log.info(f'Updated pps:\n{pformat(updated)}')
pp_entries, closed_pp_objs = table.dump_active('kraken')
pp_entries, closed_pp_objs = table.dump_active()
pp_objs: dict[Union[str, int], Position] = table.pps
pps: dict[int, Position]
@ -418,11 +418,36 @@ async def trades_dialogue(
pos = has_pp(dst)
if not pos:
# we have a balance for which there is no pp
# entry? so we have to likely update from the
# ledger.
updated = table.update_from_trans(ledger_trans)
log.info(f'Updated pps from ledger:\n{pformat(updated)}')
pos = has_pp(dst)
if not pos and not simulate_pp_update:
# try reloading from API
table.update_from_trans(api_trans)
pos = has_pp(dst)
if not pos:
# get transfers to make sense of abs balances.
# NOTE: we do this after ledger and API
# loading since we might not have an entry
# in the ``pps.toml`` for the necessary pair
# yet and thus this likely pair grabber will
# likely fail.
likely_pair = {
bsuid[:3]: bsuid
for bsuid in table.pps
}.get(dst)
if not likely_pair:
raise ValueError(
'Could not find a position pair in '
'ledger for likely widthdrawal '
f'candidate: {dst}'
)
if likely_pair:
# this was likely pp that had a withdrawal
@ -442,18 +467,7 @@ async def trades_dialogue(
f'{pformat(updated)}'
)
# we have a balance for which there is no pp
# entry? so we have to likely update from the
# ledger.
updated = table.update_from_trans(ledger_trans)
log.info(f'Updated pps from ledger:\n{pformat(updated)}')
pos = has_pp(dst)
if not pos and not simulate_pp_update:
# try reloading from API
table.update_from_trans(api_trans)
pos = has_pp(dst)
if not pos:
if not has_pp(dst):
raise ValueError(
'Could not reproduce balance:\n'
f'dst: {dst}, {size}\n'