-
Notifications
You must be signed in to change notification settings - Fork 71
Description
I think I found a bug that occurs in get_historical_price_hour_from (and I think in get_historical_price_day_from as well, but I only used get_historical_price_hour_from so I will be talking about this function).
So basically if I understand your code correctly, you keep fetching the price history until we are at fromTs, but basically if price history is not available (because we go beyond the time where price history is stored) it returns only zeroes: {'time': xxxxxxx, 'high': 0, 'low': 0, 'open': 0, 'volumefrom': 0, 'volumeto': 0, 'close': 0, 'conversionType': 'direct', 'conversionSymbol': ''} and you remove those from the list in validHist = [elem for elem in p if elem["time"] >= fromTs_i and elem["open"] != 0 and elem["close"] != 0]. So for example I would get this response if I try to get the price history of Ethereum on January 1st 2000. I would get only zeroes because Ethereum didn't exist back then.
And I think you also assumed that. Because a few lines later at if len(validHist) < len(p): break, you check if we removed some zero entries (and elem["time"] >= fromTs_i but that is not important for this story) and if we did, you assume that we reached the end of valid price histories and we break out of the while loop. However, when fetching the price history of Solana (but it applies to other coins as well), I got this:
For whatever reason, the price history sometimes has zero entries in it, even though we haven't reached the end yet! In my example, I was fetching from January 1st 2010 (just a lower bound to indicate that I want all the possible price history available) until July 1st 2023. But it prematurely terminated in this loop, even though there is more price history to fetch!
A possible fix could be to not terminate when we removed at least 1 entry, but to keep going until all 2000 (or to how much limit is set) entries are zero entries. In that case you are absolutely sure that you reached the very beginning of a coin's price history.
