question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CCXT Pro's `watch_trades` open streams only for 100 first symbols of USDT pairs

See original GitHub issue
  • OS: MacOS Ventura 13.0.1
  • Programming Language version: Python 3.10.1
  • CCXT version: 2.2.103

While fetching trades for all USDT pairs (more than 100 pairs) stream connections has been established for the first 100 pairs only. And for the rest pairs got ‘RequestTimeout Connection timeout’. I’ve checked Binance API limits and have no found suitable info, why only 100 stream could be establish.

import asyncio
from traceback import format_tb

import ccxt.pro as ccxt


def filter_binance_spot(item):
    return item['status'] == 'TRADING' and item['isSpotTradingAllowed']


def filter_binance_quotes(item):
    return item['quoteAsset'] in ['BUSD', 'USDT', 'BTC']


class BinanceExchange(object):

    def __init__(self) -> None:
        self.__exchange = ccxt.binance({'verbose': True, 'newUpdates': True, 'options': {'defaultType': 'spot', 'watchTrades': {'name': 'aggTrade'}}})
        # print(f"\n\tEXCHANGE::\t", self.__exchange.enableRateLimit, self.__exchange.rateLimit)

    async def __get_trades(self, symbol):
        while True:
            trades = await self.__exchange.watch_trades(symbol, since=self.__exchange.seconds())
            # print(f"\tTRADES::\t\t{symbol}::\t", len(trades), )

    async def start(self):
        try:
            markets = await self.__exchange.load_markets()
            spot_trading_pairs = list(filter(filter_binance_spot, [item['info'] for item in markets.values()]))
            symbols = [item['symbol'] for item in filter(filter_binance_quotes, spot_trading_pairs)]
            # print(f"\n\tSYMBOLS::\t\t", len(markets), len(spot_trading_pairs), len(symbols))
            get_trades = [self.__get_trades(symbol) for symbol in symbols]
            await asyncio.gather(*get_trades)

        except Exception as exc:
            print('[' + type(exc).__name__ + ']')
            print(str(exc))
            print(format_tb(exc.__traceback__))
        
        finally:
            await self.__exchange.close()


if __name__ == '__main__':
    print(f"\n\tccxt version::\t{ccxt.__version__}\n\n")
    asyncio.run(BinanceExchange().start())
2022-12-13T17:55:02.991Z connecting to wss://stream.binance.com:9443/ws/0 with timeout 10000 ms
2022-12-13T17:55:02.992Z connecting to wss://stream.binance.com:9443/ws/1 with timeout 10000 ms
2022-12-13T17:55:02.992Z connecting to wss://stream.binance.com:9443/ws/2 with timeout 10000 ms
...
2022-12-13T17:55:02.992Z connecting to wss://stream.binance.com:9443/ws/931 with timeout 10000 ms

...

2022-12-13T17:55:13.032Z RequestTimeout Connection timeout
2022-12-13T17:55:13.032Z on_error Connection timeout
...
``

Full output is attached. binance.txt.gz

Issue Analytics

  • State:open
  • Created 9 months ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ealesidcommented, Dec 14, 2022

Hello @ealesid, There’s no limit of subscriptions so probably there’s an issue handling all the connections we will merge a small fix that will mitigate this issue (hopefully).

Just for information

Binance suggest endpoint to connect to combined streams (Link)

Raw streams are accessed at /ws/<streamName>
Combined streams are accessed at /stream?streams=<streamName1>/<streamName2>/<streamName3>
1reaction
carlosmieicommented, Dec 13, 2022

Hello @ealesid, There’s no limit of subscriptions so probably there’s an issue handling all the connections we will merge a small fix that will mitigate this issue (hopefully).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Watching multiple symbols in parallel with WebSockets #6558
I am using the newest CCXT pro version 0.0.58 on a Windows machine. C:\Users\Administrator\node_modules\ccxt.pro\js\binance.js:219 orderbook.
Read more >
Manual — ccxt 2.4.71 documentation
The Unified CCXT Pro Streaming API inherits CCXT usage patterns to make ... watchTrades (symbol) # the following call will return the first...
Read more >
CCXT Crypto Exchange Order Book Data [Example Tutorial]
CCXT Example - Individual Pair. Our first example will request the current order book for the BTC/USDT trading pair on the Binance exchange....
Read more >
Getting started with CCXT Crypto Exchange Library and Python
Learn how to use CCXT library to fetch data from different exchanges for trading and visualization.
Read more >
Brief Intro to CCXT [CryptoCurrency Trading Library] - YouTube
In this video I am briefly going over CCXT. We are taking a look at market information on different exchanges and also on...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found