From a4232641ce5abf0d9588e172840d823683a31275 Mon Sep 17 00:00:00 2001 From: jerick Date: Mon, 18 May 2026 15:14:53 -0400 Subject: [PATCH] coin pair normalizations --- bot.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/bot.py b/bot.py index 970276b..2d7235e 100644 --- a/bot.py +++ b/bot.py @@ -89,11 +89,21 @@ def run_cycle(config: Config) -> bool: log.error("Could not fetch position tickers: %s", exc) tickers = {} - # Build a price lookup tolerant of altname vs internal key differences + # Build a price lookup tolerant of altname vs internal key differences. + # Kraken returns older pairs under internal names (e.g. XZECZUSD instead + # of ZECUSD) by adding an X prefix to the base and Z prefix to the quote. + # We index each price under both the raw key and the normalised altname. price_lookup: dict[str, float] = {} for key, ticker in tickers.items(): try: - price_lookup[key] = float(ticker["c"][0]) + price = float(ticker["c"][0]) + price_lookup[key] = price + # Normalise: XZECZUSD → ZECUSD, XXBTZUSD → XBTUSD + normalized = key.replace("ZUSD", "USD") + if normalized.startswith("X"): + normalized = normalized[1:] + if normalized != key: + price_lookup[normalized] = price except (KeyError, ValueError): pass