ccxt / ccxt

A JavaScript / TypeScript / Python / C# / PHP cryptocurrency trading API with support for more than 100 bitcoin/altcoin exchanges
https://docs.ccxt.com
MIT License
32.52k stars 7.47k forks source link

Error when calling watch_trades() on gateio and kucoin. #17507

Closed mrpouley closed 1 year ago

mrpouley commented 1 year ago

Operating System

linux 5.15

Programming Languages

python

CCXT Version

3.0.56

Description

Using this simple example here with gateio and kucoin, I get the following errors.

Code

Code:

# -*- coding: utf-8 -*-

import ccxt.pro
from asyncio import gather, run

async def symbol_loop(exchange, symbol):
    print('Starting the', exchange.id, 'symbol loop with', symbol)
    while True:
        try:
            trades = await exchange.watch_trades(symbol)
            now = exchange.milliseconds()
            print(exchange.iso8601(now), exchange.id, symbol, len(trades), trades[-1]['price'])
        except Exception as e:
            print(str(e))
            # raise e  # uncomment to break all loops in case of an error in any one of them
            break  # you can break just this one loop if it fails

async def exchange_loop(exchange_id, symbols):
    print('Starting the', exchange_id, 'exchange loop with', symbols)
    exchange = getattr(ccxt.pro, exchange_id)({
        'newUpdates': True,  # https://github.com/ccxt/ccxt/wiki/ccxt.pro.manual#incremental-data-structures
    })
    loops = [symbol_loop(exchange, symbol) for symbol in symbols]
    await gather(*loops)
    await exchange.close()

async def main():
    exchanges = {
        'gateio': ['BTC/USDT',  'ETH/USDT'],
        # 'kucoin': ['BTC/USDT', 'ETH/BTC'],
    }
    loops = [exchange_loop(exchange_id, symbols) for exchange_id, symbols in exchanges.items()]
    await gather(*loops)

run(main())

Error for gateio:

Starting the gateio exchange loop with ['BTC/USDT', 'ETH/USDT']
Starting the gateio symbol loop with BTC/USDT
Starting the gateio symbol loop with ETH/USDT
Exception in callback FastClient.receive_loop.<locals>.handler() at /home/mrpouley/.local/lib/python3.10/site-packages/ccxt/async_support/base/ws/fast_client.py:21
handle: <Handle FastClient.receive_loop.<locals>.handler() at /home/mrpouley/.local/lib/python3.10/site-packages/ccxt/async_support/base/ws/fast_client.py:21>
Traceback (most recent call last):
  File "/usr/lib/python3.10/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/home/mrpouley/.local/lib/python3.10/site-packages/ccxt/async_support/base/ws/fast_client.py", line 26, in handler
    self.handle_message(message)
  File "/home/mrpouley/.local/lib/python3.10/site-packages/ccxt/async_support/base/ws/aiohttp_client.py", line 32, in handle_message
    self.handle_text_or_binary_message(message.data)
  File "/home/mrpouley/.local/lib/python3.10/site-packages/ccxt/async_support/base/ws/aiohttp_client.py", line 27, in handle_text_or_binary_message
    self.on_message_callback(self, decoded)
  File "/home/mrpouley/.local/lib/python3.10/site-packages/ccxt/pro/gate.py", line 927, in handle_message
    self.handle_subscription_status(client, message)
  File "/home/mrpouley/.local/lib/python3.10/site-packages/ccxt/pro/gate.py", line 831, in handle_subscription_status
    del client.subscriptions[id]
KeyError: '1'
Connection to wss://api.gateio.ws/ws/v4/ timed out due to a ping-pong keepalive missing on time
Connection to wss://api.gateio.ws/ws/v4/ timed out due to a ping-pong keepalive missing on time

Error for kucoin:

Starting the kucoin exchange loop with ['BTC/USDT', 'ETH/BTC']
Starting the kucoin symbol loop with BTC/USDT
Starting the kucoin symbol loop with ETH/BTC
Exception in callback FastClient.receive_loop.<locals>.handler() at /home/mrpouley/.local/lib/python3.10/site-packages/ccxt/async_support/base/ws/fast_client.py:21
handle: <Handle FastClient.receive_loop.<locals>.handler() at /home/mrpouley/.local/lib/python3.10/site-packages/ccxt/async_support/base/ws/fast_client.py:21>
Traceback (most recent call last):
  File "/usr/lib/python3.10/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/home/mrpouley/.local/lib/python3.10/site-packages/ccxt/async_support/base/ws/fast_client.py", line 26, in handler
    self.handle_message(message)
  File "/home/mrpouley/.local/lib/python3.10/site-packages/ccxt/async_support/base/ws/aiohttp_client.py", line 32, in handle_message
    self.handle_text_or_binary_message(message.data)
  File "/home/mrpouley/.local/lib/python3.10/site-packages/ccxt/async_support/base/ws/aiohttp_client.py", line 27, in handle_text_or_binary_message
    self.on_message_callback(self, decoded)
  File "/home/mrpouley/.local/lib/python3.10/site-packages/ccxt/pro/kucoin.py", line 799, in handle_message
    return method(client, message)
  File "/home/mrpouley/.local/lib/python3.10/site-packages/ccxt/pro/kucoin.py", line 451, in handle_subscription_status
    method = self.safe_value(subscription, 'method')
  File "/home/mrpouley/.local/lib/python3.10/site-packages/ccxt/base/exchange.py", line 764, in safe_value
    return dictionary[key] if Exchange.key_exists(dictionary, key) else default_value
  File "/home/mrpouley/.local/lib/python3.10/site-packages/ccxt/base/exchange.py", line 698, in key_exists
    if key in dictionary:
TypeError: argument of type 'bool' is not iterable
carlosmiei commented 1 year ago

Hello @mrpouley, Thanks for letting us know, we will fix them asap.

andershansson commented 1 year ago

I'm also experiencing this error (when using gateio)

frosty00 commented 1 year ago

17531