I am trying to get the historic pricing data of a given product over a period from the GDAX API. I understand the following note:
The maximum number of data points for a single request is 350 candles. If your selection of start/end time and granularity will result in more than 350 data points, your request will be rejected. If you wish to retrieve fine granularity data over a larger time range, you will need to make multiple requests with new start/end ranges.
However, if I wanted to get a daily value for a 1 year period with the following code:
const Gdax = require('gdax');
const publicClient = new Gdax.PublicClient();
publicClient.getProductHistoricRates(
'BTC-USD',
{ granularity: 60,
start: '2017-01-01', end: '2018-01-01' }
).then((res) => {
console.log(res)
});
then I get the following error message:
{ message: 'granularity too small for the requested time range' }
which makes sense, because there will be 365 results which is greater than the 350 limit. I believe I could do a query for the 1st Jan -> 16th Dec and a second query for the 16th Dec -> 31st Dec. However, the following note:
Historical rate data may be incomplete. No data is published for intervals where there are no ticks.
Suggests that particularly in smaller intervals, that logic might not be sound. Is there a more intelligent way of enumerating over a period of more than 350 data points?
if you want to get just the daily value, you should change the
granularity
to86400
, as granularity is how many time slices per second you want, 1 day = 86400 seconds so you get 1 data point per day.So now that you get 1 data point per day, you can request from 1st Jan to 16th Dec and then 17 Dec to 31 Dec.