简体   繁体   English

查询超过350点的历史数据

[英]Querying Historic data over periods with more than 350 points

I am trying to get the historic pricing data of a given product over a period from the GDAX API. 我正在尝试从GDAX API获取给定产品在一段时间内的历史价格数据。 I understand the following note: 我了解以下注意事项:

The maximum number of data points for a single request is 350 candles. 单个请求的最大数据点数为350根蜡烛。 If your selection of start/end time and granularity will result in more than 350 data points, your request will be rejected. 如果您选择的开始/结束时间和粒度将导致超过350个数据点,则您的请求将被拒绝。 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. 这很有意义,因为会有365个结果大于350个限制。 I believe I could do a query for the 1st Jan -> 16th Dec and a second query for the 16th Dec -> 31st Dec . 我相信我可以对1月1日-> 12月16日进行查询,并为12月16日-> 12月31日进行第二次查询。 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? 是否有更智能的方式来枚举超过350个数据点的时间?

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. 如果只想获取每日值,则应将granularity更改为86400 ,因为粒度是您想要的每秒每秒多少个时间片,即1天= 86400秒,因此您每天可获得1个数据点。

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. 因此,既然您每天获得1个数据点,则可以请求从1月1日到12月16日,然后从12月17日到12月31日。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM