I have the following warning (check commented line in the code), and I don't know how to add the promise() object as my function is not asynchronous.
function MostProfitable() {
var max = 0;
var id;
for (var i = 0; i < minmaxcoins.length; i++) {
if (Number(minmaxcoins[i][4]) > Number(max)) {
max = minmaxcoins[i][4];
id = i;
}
}
try {
if (minmaxcoins[id][4] >= 0.6) { // error at this line
console.info('Max coin: ', minmaxcoins[id][0], ' ', minmaxcoins[id][1]);
console.info('Min coin: ', minmaxcoins[id][2], ' ', minmaxcoins[id][3]);
console.info('Profit: ', minmaxcoins[id][4], '%');
const d = new Date();
opportunity = opportunity + 1;
console.info(
opportunity,
' ***********************************************',
d
);
begin();
}
} catch (error) {
console.error(error);
begin();
}
}
here's the error/ warning :
(node:1788) UnhandledPromiseRejectionWarning: TypeError: Cannot read property '4' of undefined
at MostProfitable (/home/root1/hft.js:274:20)
at getMax (/home/root1/hft.js:261:2)
at pairprice (/home/root1/hft.js:175:2)
at getcoins (/home/root1/hft.js:116:1)
at binance.bookTickers (/home/root1/hft.js:69:2)
at Request.request [as _callback] (/home/root1/node_modules/node-binance-api/node-binance-api.js:3296:24)
at Request.self.callback (/home/root1/node_modules/request/request.js:185:22)
at Request.emit (events.js:198:13)
at Request.<anonymous> (/home/root1/node_modules/request/request.js:1154:10)
at Request.emit (events.js:198:13)
(node:1788) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:1788) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
I know it's just a warning but I notice that the app bugs as it's should work 24/7 non-stop. Can someone explain this problem?