Hi,
Since a couple of days when I start my script the websocket works and sometimes not.
Any idea why?
This is how I start the script for the 1 minute: node getData 1m
I run this script 8 times. for 1m, 3m, 5m, 15m 1h, 4h, 1d, 1w
This is my code:
//Define Binance Settings
const BinanceOptions = config.get(‘Binance’); //Here I have my API keys and useServerTime:True
const binance = require(“node-binance-api”)().options(BinanceOptions);
// Database Name
const dbName = ‘myDB’;
// Use connect method to connect to the server
MongoClient.connect(config.get(‘MongoDB.URL’), { useNewUrlParser: true, useUnifiedTopology: true }, function (err, client) {
var db = client.db(dbName);
const collection = db.collection(‘pairs’);
let pairs = ;
//Get BTC Pairs ant put them into an array
//dbo.collection(“pairs”)
collection.find({ ‘exchange’: ‘Binance’, ‘details.symbol’: { $regex: “BTC$” } })
.project({ _id: 0, ‘details.symbol’: 1 })
.toArray(async function (err, result) {
if (err) throw err;
for (i = 0; i < result.length; i++) {
pairs.push(result[i].details.symbol);
}
//console.log(pairs);
/* Periods: 1m,3m,5m,15m,30m,1h,2h,4h,6h,8h,12h,1d,3d,1w,1M -------------------------------*/
binance.websockets.chart(pairs, process.argv[2], async (symbol, interval, chart) => {
//let tick = binance.last(chart);
let ohlc = binance.ohlc(chart);
//let a = chart[tick].close;
let lastClose = ohlc.close[ohlc.close.length - 1];
let last60 = ohlc.close[ohlc.close.length - 61];
let last240 = ohlc.close[ohlc.close.length - 241];
let candles60div = parseFloat(((lastClose / last60) - 1) * 100).toFixed(2);
console.log(lastClose);
console.log(last60);
console.log('1h:' + candles60div + '%');
});
});
});
The result I receive is:
undefined
undefined
1h:NaN%
undefined
undefined
1h:NaN%
And when it works I got:
0.00000857
0.00001021
1h:-16.06%
0.00000542
0.00000567
1h:-4.41%
0.00000927
0.0000096
1h:-3.44%
Thx for the help.
/m