Hi All,
I use this code to get OCHLV at 1h time, but Volume not correct with tradingview. Why and How to fix ??
const axios = require('axios');
const moment = require('moment');
const fs = require('fs');
const start = moment('2022-04-25').utc().startOf('day');
const end = moment('2023-04-26').utc().endOf('day');
const symbol = 'BTCUSDT';
const interval = '1h';
const minVolume = 500;
const url = `https://fapi.binance.com/fapi/v1/klines?symbol=${symbol}&interval=${interval}&startTime=${start.valueOf()}&endTime=${end.valueOf()}`;
axios.get(url)
.then(response => {
const klines = response.data.filter(kline => parseFloat(kline[5]) >= minVolume);
const greaterThanTenK = response.data.filter(arr => Number(arr[5]) > minVolume);
//Array count = greaterThanTenK.length;
console.log(klines);
const rows = klines.map(kline => {
return {
timestamp: moment(kline[0]).format('YYYY-MM-DD HH:mm:ss'),
open: parseFloat(kline[1]),
high: parseFloat(kline[2]),
low: parseFloat(kline[3]),
close: parseFloat(kline[4]),
volume: parseFloat(kline[5])
};
});
console.log(rows);
const csv = 'Timestamp,Open,High,Low,Close,Volume\n' + rows.map(row => `${row.timestamp},${row.open},${row.high},${row.low},${row.close},${row.volume}`).join('\n');
fs.writeFile('BTCUSDT_Klines.csv', csv, err => {
if (err) {
console.error(err);
} else {
console.log('BTCUSDT_Klines.csv saved!');
}
});
})
.catch(error => {
console.error(error);
});