coin pair normalizations
This commit is contained in:
14
bot.py
14
bot.py
@@ -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
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user