Sort ticker_history

CCXT does not sort the ticker history from exchanges.
Bittrex and Binance are sorted ASC (oldest first, newest last) when
GDAX is sorted DESC (newest first, oldest last).

Because of that the get_ticker_history() fall in a very long loop
when the tickers are sorted DESC. Means it downloads more than
needed.

This commit enable exhanges like GDAX and unify the ticker_history
list across all exchanges.
This commit is contained in:
Gerald Lonlas
2018-05-31 23:45:35 -07:00
parent acbfe91f13
commit c9e49ed7b4
2 changed files with 77 additions and 0 deletions

View File

@@ -294,6 +294,11 @@ def get_ticker_history(pair: str, tick_interval: str, since_ms: Optional[int] =
while not since_ms or since_ms < till_time_ms:
data_part = _API.fetch_ohlcv(pair, timeframe=tick_interval, since=since_ms)
# Because some exchange sort Tickers ASC and other DESC.
# Ex: Bittrex returns a list of tickers ASC (oldest first, newest last)
# when GDAX returns a list of tickers DESC (newest first, oldest last)
data_part = sorted(data_part, key=lambda x: x[0])
if not data_part:
break