Estoy teniendo grandes dificultades para hacer esto, así que tengo que pedirles ayuda ahora.
Estoy llegando al punto final de la API de binance para las tasas futuras históricas y necesito todos los datos disponibles para cada símbolo en mi matriz (desde el elemento actual hasta el primer elemento creado).
La API ofrece parámetros de consulta y límites para hacerlo "startTime" y "endTime" de tipo marca de tiempo larga en ms.
Aquí está el enlace a los documentos [fundingrate api endpoint[1] [1]: https://binance-docs.github.io/apidocs/futures/en/#get-funding-rate-history
Usando mi enfoque, obtengo un montón de resultados, pero se detienen aleatoriamente en algún momento del pasado, por lo que mi lógica de paginación debe ser incorrecta. Me parece que no puede averiguar dónde.
Este es mi código actual
(async () => { try { const markets = symbols; const targetDate = moment("2018-01-01"); //just one random past date I know it is for sure before any future contract creation on binance for (let i = 0; i < markets.length; i++) { let fundingRates = []; symbol = markets[i]; let startTime, endTime, days_per_batch; const initialResult = await binance.futuresFundingRate(symbol, { //make a request without a range to get a start and endpoint for pagination limit: 1000, }); startTime = moment(initialResult[0].fundingTime); //use the first retrieved item as startTime endTime = moment(initialResult[initialResult.length - 1].fundingTime); //use last received item as endTime days_per_batch = endTime.diff(startTime, "days"); //difference in days between first and last retrieved item of initial request while (endTime.isAfter(targetDate)) { const result = await binance.futuresFundingRate(symbol, { startTime: startTime.unix(), //cast to timestamps endTIme: endTime.unix(), //cast to timestamps limit: 1000, }); //concat retrieved result with result array that gets exported to csv fundingRates = [].concat( ...result.map((e) => { return { symbol: e.symbol, fundingRate: e.fundingRate, fundingTime: moment(e.fundingTime), }; }) ); //set the endTime to the previosu startTime and the startTime to startTime - days per batch (difference in days between first item and last item of result) endTime = startTime; startTime.subtract(days_per_batch, "days"); } exportToCSV(symbol, fundingRates); console.log("processing " + i + " / " + markets.length) } } catch (error) { console.log(error); } })();