How to retrieve historical time and sales (trading history) using the REST API Trades endpoint.

The REST API OHLC endpoint only provides a limited amount of historical data, specifically 720 data points of the requested interval. For example, asking for OHLC data in 1 minute intervals will return the most recent 720 minutes (12 hours) of data.

For applications that require additional OHLC or tick data, it is possible to retrieve the entire trading history of our markets (the historical time and sales) via the REST API Trades endpoint. The OHLC for any time frame and any interval can then be created from the historical time and sales data.

The Trades endpoint takes an optional parameter named since, which specifies the starting date/time of the data. The since value is a UNIX timestamp at nanosecond resolution (a standard UNIX timestamp in seconds with 9 additional digits).

For example, a call to the Trades endpoint such as https://api.kraken.com/0/public/Trades?pair=xbtusd&since=1559347200000000000 would return the historical time and sales for XBT/USD from the 1st of June 2019 at 00:00:00 UTC:

{"error":[],"result":{"XXBTZUSD":[["8552.90000","0.03190270",1559347203.7998,"s","m",""],["8552.90000","0.03155529",1559347203.8086,"s","m",""],["8552.90000","0.00510797",1559347203.9664,"s","m",""],["8552.90000","0.09047336",1559347203.9789,"s","m",""],["8552.90000","0.00328738",1559347203.9847,"s","m",""],["8552.90000","0.00492152",1559347203.9897,"s","m",""],["8552.90000","0.00201848",1559347203.9937,"s","m",""],["8552.90000","0.11422068",1559347203.9993,"s","m",""],["8552.90000","0.00425858",1559347204.071,"s","m",""],["8552.90000","0.00427679",1559347204.0762,"s","m",""],["8552.90000","0.06381401",1559347204.1662,"s","m",""]
...
["8579.50000","0.05379597",1559350785.248,"s","l",""],["8579.50000","0.94620403",1559350785.2936,"s","l",""],["8578.10000","0.45529068",1559350785.297,"s","l",""]],"last":"1559350785297011117"}}

Subsequent calls to the Trades endpoint should replace the since parameter's value with the last parameter's value from the results of the previous call such as https://api.kraken.com/0/public/Trades?pair=xbtusd&since=1559350785297011117.

Using the special since value of 0 (zero) would return the historical time and sales from the beginning of the market (starting with the very first trade).