Exception возвращает TimeoutError()
В функции в некоторых случаях срабатывает исключение Exception as ex = Timeout(). Ошибка странная, потому что если бы была проблема сетевая то сработало бы исключение ccxt.NetworkError. Как определить истинную причину исключения?
async def FetchTrades(exchange, pair, since, till, limit=1000, attempts = 3, sleep = 60):
networkError = 0
fetchError = 0
while networkError < attempts:
try:
trades = []
#id = await FindNearestFromId(exchange, pair, since)
preLoad = await exchange.fetchTrades(symbol = pair, since=since, limit = 1)
if(preLoad == None or len(preLoad) == 0):
preLoad = await exchange.fetchTrades(symbol = pair, since=(since - 10 * 24 * 60 * 60 * 1000), limit = 1)
if(preLoad == None or len(preLoad) == 0):
return (pair, trades, since, till)
id = int(preLoad[0]['id'])
while int(preLoad[0]['timestamp']) > since:
id = int(preLoad[0]['id'])
fromID = (id - limit) if(id > limit) else 1
id = fromID
preLoad = await exchange.fetchTrades(symbol = pair, params={'fromId':str(fromID)}, limit = 1)
prev_id = -1
tradesPage = None
while True:
tradesPage = await exchange.fetchTrades(symbol = pair, params={'fromId':str(id)}, limit = limit)
if(tradesPage != None and len(tradesPage)):
prev_id = id
id = tradesPage[-1]['id']
tradesPageCleaned = list(map(lambda x: (x['symbol'], dt.datetime.strptime(x['datetime'], '%Y-%m-%dT%H:%M:%S.%fZ'),x['timestamp'], int(x['id']), x['side'], x['price'], x['amount'], x['cost'], x['fee']), tradesPage))
trades = trades + tradesPageCleaned
if(prev_id == id):
break
if(tradesPage[-1]['timestamp'] >= till):
break
else:
break
tradesFiltered = list(filter(lambda x: x[2] >= since and x[2] < till, trades))
return (pair, tradesFiltered, since, till)
except ccxt.NetworkError as ex:
log.error("{}, {}".format(sys._getframe().f_code.co_name, ex))
networkError = networkError + 1
if(networkError >= attempts):
raise Exception(ex)
log.warning("{}: sleep {} seconds".format(sys._getframe().f_code.co_name, sleep))
time.sleep(sleep)
except Exception as ex:
log.error("{}, {}".format(sys._getframe().f_code.co_name, ex))
raise Exception(ex)