ccxt: Pagination not working as expected with FTX exchange

  • OS: MacOS
  • Programming Language version: Python
  • CCXT version: 1.50.89

I tried to get all of the trade I have made, using the method, “exchange.fetchMyTrades()”, which basically called “/fills” api as below:(start time is “2020-06-01”, and end time is “2020-06-09”)

GET https://ftx.com/api/fills?market=DOGE-PERP&limit=2&start_time=1590969600&end_time=1623236704

the expected behaviour is that it returns the earliest records first, is that right? so I could use: since = orders[len(orders) - 1][‘timestamp’] to continue to fetch more. but it continues to return the result of “2020-06-09”, and while the loop goes on it just returns same result everytime… it is really confusing, I tried the ftx api directly and the result is the same, so not sure if this has something to do with the exchange.

here is the code I am using, copied from the manual.

def getAllTrades():
  exchange = ftx
  since = exchange.milliseconds () - 86400000*3  # -1 day from now
  since = exchange.parse8601 ('2020-06-01T00:00:00Z')
  # alternatively, fetch from a certain starting datetime
  # since = exchange.parse8601('2018-01-01T00:00:00Z')
  all_orders = []
  while since < exchange.milliseconds ():
      print("since:", since)
      limit = 2  # change for your limit
      orders = exchange.fetchMyTrades(symbol, since, limit)
      if len(orders):
          since = orders[len(orders) - 1]['timestamp']
          all_orders += orders
      else:
          break

  return all_orders

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 20 (14 by maintainers)

Commits related to this issue

Most upvoted comments

@kroitor Thanks for the speedy reply! I’ve been trying to play with this example from FTX.US docs by using the start_time parameter, and it looks to have no effect on the expected outcome. So I will submit an issue with FTX to see what they say about it.

I fully recognize how difficult this could be, and I have only worked with 4 exchanges, so my opinion is limited in that regard.

Would having data be aligned to a since timestamp be something to add to the Certification program? From a quick look at the requirements, there is already the idea of a required structure for incoming data.

There is also the idea that ccxt has for the user to check if a function is available through exchange.has['function']. Possibly adding a flag there to indicate what pagination strategy to use would be helpful? Tho, this has the problem of introducing more issues. For FTX it would require knowing to use the end_time parameter for that to work, while other exchanges would have a different parameter names.