ccxt: Watching ohlcv on Binance results in ccxt.base.errors.NetworkError: 1000
I am getting this error (ccxt.base.errors.NetworkError: 1000) for the Binance exchange after a couple of hours. This also occurs for BNB/USDT. However, strangely I don’t get this error for btc/usdt.
- OS: Linux (Ubuntu)
- Programming Language version: Python 3.7
- CCXT version: latest
Function giving the error (ccxt.base.errors.NetworkError: 1000)
:
exchange = getattr(ccxtpro, 'binance')({'enableRateLimit': True})
if not exchange.has['fetchOHLCV']:
raise KeyError('Exchange does not provide the ability to fetch OHLCV candles.')
if not exchange.has['watchOHLCV']:
raise KeyError('Exchange does not provide the ability to watch OHLCV candles.')
ohlcvs = await exchange.watch_ohlcv(symbol="ETH/USDT", timeframe="1m", limit=2)
if len(ohlcvs) < 2:
return False
# Copies the ohlcv candles, since ccxt cannot handle in-reference edits
candles = [ohlcvs[0][:], ohlcvs[1][:]]
candles[0][0] = from_unix(candles[0][0]) # Official formed candle, with previous timestamp
candles[1][0] = from_unix(candles[1][0]) # Unofficial candle, representing current timestamp
if not self.last_candles or candles[1][0] > self.last_candles[1][0]:
self.last_candles = candles
return True
return False
Other function using the data
last_candle = DataFrame([self.last_candles[0]], columns=TOHLCV.get_values()).set_index(TOHLCV.TIMESTAMP.value)
self.historical_minute = self.historical_minute.append(last_candle).tail(min_candles)
File "/src/mia/blotter/blotter/blotter.py", line 140, in __get_last_candle
ohlcvs = await self.exchange.watch_ohlcv(symbol=self.strategy.ccxt_pair, timeframe=timeframe, limit=2)
File "/venv/lib/python3.8/site-packages/ccxtpro/binance.py", line 394, in watch_ohlcv
return await self.after(future, self.filter_by_since_limit, since, limit, 0, True)
File "/venv/lib/python3.8/site-packages/ccxtpro/base/exchange.py", line 81, in after
return method(await future, *args)
File "/venv/lib/python3.8/site-packages/ccxtpro/binance.py", line 481, in watch_public
return await self.watch(url, messageHash, self.extend(request, query), messageHash, subscribe)
ccxt.base.errors.NetworkError: 1000
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 17 (11 by maintainers)
Commits related to this issue
- examples/ccxt.pro/py/binance-watch-ohlcv.py #7233 — committed to ccxt/ccxt by kroitor 4 years ago
- examples/ccxt.pro/py/binance-watch-ohlcv.py #7233 — committed to ccxt/ccxt by kroitor 4 years ago
Just to provide additional context, I too have experienced this issue. And I can confirm it was due to an underlying network connection issue unrelated to CCXT and the crypto-currency exchange. After adding an execption handler to restart things it is now a non-issue. I have provided my code below, which handles the exception by restarting.
The service, which my code is a part of, has been running without issue for over 14 months. I hope this helps someone. Cheers.
I ran the code you gave me in a Kubernetes container and it had one restart. I also attached the logs of that container. ccxt version: 1.30.94 ccxt pro version: 0.2.89 ccxt_previous.log
I get the same errors for ETH/USDT as well as BNB/USDT. I will do some logging later and will post the output.