diff --git a/package-lock.json b/package-lock.json index 632a123..8451e38 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "binance-triangle-arbitrage", - "version": "5.6.0", + "version": "5.6.1", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -684,6 +684,11 @@ "has-flag": "^3.0.0" } }, + "systeminformation": { + "version": "4.27.3", + "resolved": "https://registry.npmjs.org/systeminformation/-/systeminformation-4.27.3.tgz", + "integrity": "sha512-0Nc8AYEK818h7FI+bbe/kj7xXsMD5zOHvO9alUqQH/G4MHXu5tHQfWqC/bzWOk4JtoQPhnyLgxMYncDA2eeSBw==" + }, "tough-cookie": { "version": "2.5.0", "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.5.0.tgz", diff --git a/package.json b/package.json index 4e5c29b..fc8b116 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "binance-triangle-arbitrage", - "version": "5.6.0", + "version": "5.6.1", "repository": { "type": "git", "url": "https://github.com/bmino/binance-triangle-arbitrage.git" @@ -19,7 +19,8 @@ "blessed": "^0.1.81", "node-binance-api": "^0.11.11", "pino": "^6.5.0", - "pino-pretty": "^4.1.0" + "pino-pretty": "^4.1.0", + "systeminformation": "^4.27.3" }, "license": "MIT" } diff --git a/src/main/Main.js b/src/main/Main.js index 37c7198..d62ce84 100644 --- a/src/main/Main.js +++ b/src/main/Main.js @@ -1,7 +1,7 @@ const CONFIG = require('../../config/config'); const logger = require('./Loggers'); const Util = require('./Util'); -const os = require('os'); +const si = require('systeminformation'); const BinanceApi = require('./BinanceApi'); const MarketCache = require('./MarketCache'); const HUD = require('./HUD'); @@ -21,6 +21,7 @@ if (CONFIG.TRADING.ENABLED) console.log(`WARNING! Order execution is enabled!\n` process.on('uncaughtException', handleError); checkConfig() + .then(si.networkStats) .then(() => { console.log(`Checking latency ...`); return SpeedTest.multiPing(5); @@ -55,10 +56,6 @@ checkConfig() console.log(`Log Level: ${CONFIG.LOG.LEVEL}`); console.log(); - logger.performance.debug(`Operating System: ${os.type()} ${os.release()}`); - logger.performance.debug(`System Total Memory: ${(os.totalmem() / 1073741824).toFixed(1)} GB`) - logger.performance.debug(`CPU Core Speeds: [${os.cpus().map(cpu => cpu.speed)}] MHz`); - // Allow time for depth caches to populate setTimeout(calculateArbitrage, 6000); setInterval(displayStatusUpdate, CONFIG.TIMING.STATUS_UPDATE_INTERVAL); @@ -94,9 +91,21 @@ function displayStatusUpdate() { if (tickersWithoutDepthUpdate.length > 0) { logger.performance.debug(`Tickers without a depth cache update: [${tickersWithoutDepthUpdate}]`); } - logger.performance.debug(`Latest ${recentCalculationTimes.length} calculation cycles averaging ${Util.average(recentCalculationTimes).toFixed(2)} ms`); - logger.performance.debug(`CPU 1 minute load averaging ${os.loadavg()[0].toFixed(1)}%`); + logger.performance.debug(`Calculation cycle average speed: ${Util.average(recentCalculationTimes).toFixed(2)} ms`); recentCalculationTimes = []; + + Promise.all([ + si.currentLoad(), + si.mem(), + si.networkStats(), + SpeedTest.ping() + ]) + .then(([load, memory, network, latency]) => { + logger.performance.debug(`CPU Load: ${(load.avgload * 100).toFixed(0)}% [${load.cpus.map(cpu => cpu.load.toFixed(0) + '%')}]`); + logger.performance.debug(`Memory Usage: ${Util.toGB(memory.used).toFixed(1)} GB`); + logger.performance.debug(`Network Usage: ${Util.toKB(network[0].rx_sec).toFixed(1)} KBps (up) and ${Util.toKB(network[0].tx_sec).toFixed(1)} KBps (down)`); + logger.performance.debug(`API Latency: ${latency} ms`); + }); } function handleError(err) { @@ -224,6 +233,11 @@ function checkBalances() { logger.execution.error(msg); throw new Error(msg); } + if (balances['BNB'].available <= 0.001) { + const msg = `Only detected ${balances['BNB'].available} BNB which is not sufficient to pay for trading fees via BNB`; + logger.execution.error(msg); + throw new Error(msg); + } }); } diff --git a/src/main/SpeedTest.js b/src/main/SpeedTest.js index 30c4cc0..212a025 100644 --- a/src/main/SpeedTest.js +++ b/src/main/SpeedTest.js @@ -1,10 +1,8 @@ -const logger = require('./Loggers'); const BinanceApi = require('./BinanceApi'); const SpeedTest = { ping() { - logger.performance.debug(`Pinging the Binance API ...`); const before = Date.now(); return BinanceApi.time() .then(() => Date.now() - before); diff --git a/src/main/Util.js b/src/main/Util.js index 5e116d1..3a51f9f 100644 --- a/src/main/Util.js +++ b/src/main/Util.js @@ -7,6 +7,18 @@ const Util = { return Util.sum(array) / array.length }, + toKB: (bytes) => { + return bytes / 1024; + }, + + toMB: (bytes) => { + return bytes / 1024 / 1024; + }, + + toGB: (bytes) => { + return bytes / 1024 / 1024 / 1024; + }, + prune: (object, threshold) => { return Object.keys(object) .slice(0, threshold)