2

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?

George Edwards
  • 8,979
  • 20
  • 78
  • 161

1 Answers1

2

if you want to get just the daily value, you should change the granularity to 86400, 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.

SunriseM
  • 985
  • 9
  • 15
  • 1
    Yes, but as I mentioned, the issue is that the data isn’t guaranteed to return a value for every period, so if there weren’t any trades on several days during the period, then those two queries will overlap/ have duplicate data. – George Edwards Feb 10 '18 at 21:53
  • 1
    well it doesn't look like gdax api gives an better way to do it. So you can get the first period, and then in the second you check that each bucket start time is from the specified interval (after 17 dec) – SunriseM Feb 10 '18 at 21:59