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)}') 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 pp_objs: dict[Union[str, int], Position] = table.pps
pps: dict[int, Position] pps: dict[int, Position]
@ -418,29 +418,6 @@ async def trades_dialogue(
pos = has_pp(dst) pos = has_pp(dst)
if not pos: if not pos:
# get transfers to make sense of abs balances.
likely_pair = {
bsuid[:3]: bsuid
for bsuid in table.pps
}.get(dst)
if likely_pair:
# this was likely pp that had a withdrawal
# from the dst asset out of the account.
xfer_trans = await client.get_xfers(
dst,
src_asset=likely_pair[3:],
)
if xfer_trans:
updated = table.update_from_trans(
xfer_trans,
cost_scalar=1,
)
log.info(
'Updated {dst} from transfers:\n'
f'{pformat(updated)}'
)
# we have a balance for which there is no pp # we have a balance for which there is no pp
# entry? so we have to likely update from the # entry? so we have to likely update from the
@ -454,6 +431,43 @@ async def trades_dialogue(
table.update_from_trans(api_trans) table.update_from_trans(api_trans)
pos = has_pp(dst) pos = has_pp(dst)
if not pos: 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
# from the dst asset out of the account.
xfer_trans = await client.get_xfers(
dst,
src_asset=likely_pair[3:],
)
if xfer_trans:
updated = table.update_from_trans(
xfer_trans,
cost_scalar=1,
)
log.info(
'Updated {dst} from transfers:\n'
f'{pformat(updated)}'
)
if not has_pp(dst):
raise ValueError( raise ValueError(
'Could not reproduce balance:\n' 'Could not reproduce balance:\n'
f'dst: {dst}, {size}\n' f'dst: {dst}, {size}\n'