Open berkinalex opened 4 years ago
if you use all async code then you can easily add a delay after every doChart, or you can dynamically time the next doChart to keep you within the 1200 weight per minute limit
I have tried setTimeout and this asynchronous function; https://developer.mozilla.org/es/docs/Web/JavaScript/Referencia/Sentencias/funcion_asincrona, but I can't get it to work
Could you give me a hand ?, thanks for your help
I have been trying to obtain each of the temporalities and cryptocurrencies that binance offers us in spot mode, and store in a file called for example batbtc.json, that is, right now the script creates a file for each of the existing pairs and the last 500 candles, but I have a problem, I cannot get all the temporalities of each symbol (symbol), and I cannot open multiple websocket connections because binance has them limited ... someone comes up with something to get all cryptos in each binance temporality in an individual json?
my code for now is as follows
`//obtiene las velas de esta temporalidad y las guarda en un JSON const fs = require('fs'); var binance = require('./conexion_binance.js'); var simbolo;
//obtener todas las criptos (volumen y cambio diario) binance.prevDay(false, async (error, prevDay) => { let markets = []; for ( let obj of prevDay ) { let symbol = obj.symbol; simbolo = symbol; if (symbol.substr(-3) !== 'BTC' && symbol.substr(-3) !== 'ETH' && symbol.substr(-3) !== 'BNB' && symbol.substr(-4) !== 'USDT') continue; markets.push(symbol); } let responses = []; const intervals = ['1m', '3m', '1m', '3m', '5m', '15m', '30m', '1h', '2h', '4h', '6h', '8h', '12h', '1d', '3d', '1w', '1M']; for(var i = 0; i <= intervals.length - 1; i++) { responses.push(doChart(intervals[i], markets)); } Promise.all(responses).then(() => { console.log(values); }).catch(() => { console.log(results); }); });
function doChart(interval, markets) { return new Promise((resolve, reject) => { return binance.websockets.chart(markets, interval, (simbolo, interval, chart) => { let output = [], tick; const range = Object.keys(chart).slice(-20); for ( let time of range ) { tick = chart[time]; tick.timestamp = Number(time); let timestamp = new Date(tick.timestamp).toLocaleString(); output.push(tick); } fs.writeFile(
velas/${interval}/
+simbolo+".json", JSON.stringify(chart, null, 4), (err)=>{}); }); }); }`