Fix KeyError for prefixed coins in historical candle fetch
Bypass SDK's name_to_coin lookup in candles_snapshot by calling http_info.post directly with the raw coin name. This fixes KeyError for symbols like xyz:GOLD, xyz:CL, mkts:USTECH that aren't in the name_to_coin dictionary. The WebSocket subscription already bypassed this lookup (line 154), but the historical fetch path did not.
This commit is contained in:
@ -108,7 +108,8 @@ class LiveCandleFetcher:
|
||||
while current_start < end_ms:
|
||||
try:
|
||||
http_info = Info(constants.MAINNET_API_URL, skip_ws=True)
|
||||
batch = http_info.candles_snapshot(coin, "1m", current_start, end_ms)
|
||||
req = {"coin": coin, "interval": "1m", "startTime": current_start, "endTime": end_ms}
|
||||
batch = http_info.post("/info", {"type": "candleSnapshot", "req": req})
|
||||
if not batch:
|
||||
break
|
||||
|
||||
@ -158,11 +159,24 @@ class LiveCandleFetcher:
|
||||
print("\nListening for live candle data... Press Ctrl+C to stop.")
|
||||
try:
|
||||
while True:
|
||||
time.sleep(1)
|
||||
try:
|
||||
time.sleep(1)
|
||||
except Exception as e:
|
||||
logging.error(f"WebSocket connection lost: {e}")
|
||||
self.info.ws_manager.stop()
|
||||
time.sleep(5)
|
||||
self.info = Info(constants.MAINNET_API_URL, skip_ws=False)
|
||||
for coin in self.coins_to_watch:
|
||||
callback = lambda msg, c=coin: self.on_message({**msg, 'data': {**msg.get('data',{}), 'coin': c}})
|
||||
subscription = {"type": "candle", "coin": coin, "interval": "1m"}
|
||||
self.info.ws_manager.subscribe(subscription, callback)
|
||||
logging.info(f"Re-subscribed to 1m candles for {coin}")
|
||||
time.sleep(0.2)
|
||||
print("\nReconnected. Listening for live candle data...")
|
||||
except KeyboardInterrupt:
|
||||
print("\nStopping WebSocket listener...")
|
||||
self.info.ws_manager.stop()
|
||||
self.candle_queue.put(None)
|
||||
self.candle_queue.put(None)
|
||||
db_writer.join()
|
||||
print("Listener stopped.")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user