`kraken`: make pps work with arbitrary deposits
Factor and fix dst <- src pair parsing into a new func `get_likely_pair()` and use throughout initial position loading; solves a parsing bug for src asset balances which aren't only 3 chars long.. a terrible assumption.kraken_deposits_fixes
parent
d690ad2bab
commit
1346c33f04
|
@ -496,19 +496,30 @@ async def trades_dialogue(
|
||||||
for dst, size in balances.items():
|
for dst, size in balances.items():
|
||||||
# we don't care about tracking positions
|
# we don't care about tracking positions
|
||||||
# in the user's source fiat currency.
|
# in the user's source fiat currency.
|
||||||
if dst == src_fiat:
|
if (
|
||||||
|
dst == src_fiat
|
||||||
|
or not any(
|
||||||
|
dst in bsuid for bsuid in table.pps
|
||||||
|
)
|
||||||
|
):
|
||||||
|
log.warning(
|
||||||
|
f'Skipping balance `{dst}`:{size} for position calcs!'
|
||||||
|
)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
def has_pp(
|
def get_likely_pair(
|
||||||
dst: str,
|
dst: str,
|
||||||
size: float,
|
bsuid: str,
|
||||||
|
src_fiat: str = src_fiat
|
||||||
|
|
||||||
) -> Position | bool:
|
) -> str:
|
||||||
|
'''
|
||||||
|
Attempt to get the likely trading pair masting
|
||||||
|
a given destination asset `dst: str`.
|
||||||
|
|
||||||
src2dst: dict[str, str] = {}
|
'''
|
||||||
for bsuid in table.pps:
|
|
||||||
try:
|
try:
|
||||||
dst_name_start = bsuid.rindex(src_fiat)
|
src_name_start = bsuid.rindex(src_fiat)
|
||||||
except (
|
except (
|
||||||
ValueError, # substr not found
|
ValueError, # substr not found
|
||||||
):
|
):
|
||||||
|
@ -519,12 +530,23 @@ async def trades_dialogue(
|
||||||
log.warning(
|
log.warning(
|
||||||
f'No src fiat {src_fiat} found in {bsuid}?'
|
f'No src fiat {src_fiat} found in {bsuid}?'
|
||||||
)
|
)
|
||||||
continue
|
return
|
||||||
|
|
||||||
_dst = bsuid[:dst_name_start]
|
likely_dst = bsuid[:src_name_start]
|
||||||
if _dst != dst:
|
if likely_dst == dst:
|
||||||
continue
|
return bsuid
|
||||||
|
|
||||||
|
def has_pp(
|
||||||
|
dst: str,
|
||||||
|
size: float,
|
||||||
|
|
||||||
|
) -> Position | bool:
|
||||||
|
|
||||||
|
src2dst: dict[str, str] = {}
|
||||||
|
|
||||||
|
for bsuid in table.pps:
|
||||||
|
likely_pair = get_likely_pair(dst, bsuid)
|
||||||
|
if likely_pair:
|
||||||
src2dst[src_fiat] = dst
|
src2dst[src_fiat] = dst
|
||||||
|
|
||||||
for src, dst in src2dst.items():
|
for src, dst in src2dst.items():
|
||||||
|
@ -578,11 +600,11 @@ async def trades_dialogue(
|
||||||
# in the ``pps.toml`` for the necessary pair
|
# in the ``pps.toml`` for the necessary pair
|
||||||
# yet and thus this likely pair grabber will
|
# yet and thus this likely pair grabber will
|
||||||
# likely fail.
|
# likely fail.
|
||||||
likely_pair = {
|
for bsuid in table.pps:
|
||||||
bsuid[:3]: bsuid
|
likely_pair = get_likely_pair(dst, bsuid)
|
||||||
for bsuid in table.pps
|
if likely_pair:
|
||||||
}.get(dst)
|
break
|
||||||
if not likely_pair:
|
else:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
'Could not find a position pair in '
|
'Could not find a position pair in '
|
||||||
'ledger for likely widthdrawal '
|
'ledger for likely widthdrawal '
|
||||||
|
@ -595,6 +617,8 @@ async def trades_dialogue(
|
||||||
|
|
||||||
xfer_trans = await client.get_xfers(
|
xfer_trans = await client.get_xfers(
|
||||||
dst,
|
dst,
|
||||||
|
# TODO: not all src assets are
|
||||||
|
# 3 chars long...
|
||||||
src_asset=likely_pair[3:],
|
src_asset=likely_pair[3:],
|
||||||
)
|
)
|
||||||
if xfer_trans:
|
if xfer_trans:
|
||||||
|
|
Loading…
Reference in New Issue