ccxt: watch_order_book error with Binance : Connection closed by remote server, closing code 1008
Hello,
I upgraded both CCXT and CCXT Pro to the latest version and I receive this error when I try to watch Binance order book for one spot symbol :
File "/home/abc/env/lib/python3.6/site-packages/ccxtpro/binance.py", line 155, in watch_order_book
orderbook = await self.watch(url, messageHash, message, messageHash, subscription)
ccxt.base.errors.NetworkError: Connection closed by remote server, closing code 1008
Error code1008 is not referenced in the Binance API.
What do you think is the reason for this issue and how can I fix it?
Thank you,
This is how I initiate the loop:
async def watch_book(account, client, market, i, j):
while True:
try:
ob = await client.watch_order_book(market.symbol)
except Exception as e:
break
async def wallet_loop(account, loop, i, wallet):
client = getattr(ccxtpro, exchange.exid)({'enableRateLimit': True, 'asyncio_loop': loop, })
ws_loops = [watch_book(account, client, market, i, j) for j, market in enumerate(markets_monitor)]
await asyncio.gather(*ws_loops)
await client.close()
async def main(account, loop, wallets):
wallet_loops = [wallet_loop(account, loop, i, wallet) for i, wallet in enumerate(wallets)]
await asyncio.gather(*wallet_loops)
loop = asyncio.get_event_loop()
gp = asyncio.wait([main(account, loop, wallets)])
loop.run_until_complete(gp)
loop.close()
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 18 (7 by maintainers)
@YuriyTigiev try adding more pairs to it to see where it breaks. Then add the database connector. Make sure you use an async connector, for example: https://aioinflux.readthedocs.io/en/stable/
Please find below a reproducible example.
When 4 markets are monitored it throws a
RuntimeError : This event loop is already running
then returns data, but when 5 markets are monitored it throws the RuntimeError with no data. That is the problemNow, when I replace
break
withcontinue
my IP address get banned by the remote host (happened yesterday) so I don’t think it’s a workaround.Thanks for your support, Kinzowa
@Kinzowa replace this code
with
ccxt will handle the disconnects and reconnect automatically.
Let us know if this does not solve your problem and thanks for using ccxt pro!