Ccxt: Fetch_ohlcv (symbol,'1m') of okex timeout

Created on 22 Mar 2018  ·  3Comments  ·  Source: ccxt/ccxt

PROBLIEM:
I run about 30 minutes later, the problem of time out, is the question of exchange, or the problem of ccxt, how to solve it.

  • OS: win10
  • Programming Language version: python 3.6
  • CCXT version: ccxt-1.11.137
  • Exchange: okex
  • Method: exchange.fetch_ohlcv(self.symbol, '1m')

CODE:

 def get_close_prices(self):
        close_prices = []
        bar_data = np.array(self.exchange.fetch_ohlcv(symbol, '1m'))
        for element in bar_data:
            close_prices.append(float(element[4]))
        return close_prices

if __name__ == '__main__':
while true:
        close_prices = self.get_close_prices()
        time.sleep(1 * 60)

ERROR:

File "E:/work/test/test.py", line 44, in handle_bar
close_prices = np.array(self.get_close_prices())
File "E:/work/test/test.py", line 24, in get_close_prices
bar_data = np.array(self.exchange.fetch_ohlcv(self.symbol, '1m'))
File "E:\sorfware\anaconda3.5\lib\site-packages\ccxt\okcoinusd.py", line 348, in fetch_ohlcv
response = getattr(self, method)(self.extend(request, params))
File "E:\sorfware\anaconda3.5\lib\site-packages\ccxt\base\exchange.py", line 298, in request
return self.fetch2(path, api, method, params, headers, body)
File "E:\sorfware\anaconda3.5\lib\site-packages\ccxt\base\exchange.py", line 295, in fetch2
return self.fetch(request['url'], request['method'], request['headers'], request['body'])
File "E:\sorfware\anaconda3.5\lib\site-packages\ccxt\base\exchange.py", line 359, in fetch
self.raise_error(RequestTimeout, method, url, e)
File "E:\sorfware\anaconda3.5\lib\site-packages\ccxt\base\exchange.py", line 280, in raise_error
raise exception_type(output)
ccxt.base.errors.RequestTimeout: okex GET https://www.okex.com/api/v1/kline.do?symbol=bch_btc&type=1min&since=1521547087487 HTTPSConnectionPool(host='www.okex.com', port=443): Read timed out. (read timeout=10)

duplicate question

All 3 comments

I run about 30 minutes later, the problem of time out, is the question of exchange, or the problem of ccxt

It is a problem of the exchange, any exchange will reply with RequestTimeout occasionally, you just need to handle it properly.

how to solve it.

Just catch the exceptions and retry later.

Hope it helps.

Thank you so much, I solved it according to your instructions, that is to catch the exception.

@nashse thx for reporting back!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hippylover picture hippylover  ·  3Comments

luigikitten picture luigikitten  ·  3Comments

kumboo picture kumboo  ·  3Comments

Sarona93 picture Sarona93  ·  3Comments

alpaykoray picture alpaykoray  ·  3Comments