coin pair normalizations

This commit is contained in:
2026-05-18 15:14:53 -04:00
parent 3ec7d5fd19
commit a4232641ce

14
bot.py
View File

@@ -89,11 +89,21 @@ def run_cycle(config: Config) -> bool:
log.error("Could not fetch position tickers: %s", exc) log.error("Could not fetch position tickers: %s", exc)
tickers = {} 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] = {} price_lookup: dict[str, float] = {}
for key, ticker in tickers.items(): for key, ticker in tickers.items():
try: 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): except (KeyError, ValueError):
pass pass