Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
bmino committed Sep 8, 2020
2 parents 402d29f + 11a56de commit 0b3ec59
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 12 deletions.
7 changes: 6 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
}
28 changes: 21 additions & 7 deletions src/main/Main.js
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
});
}

Expand Down
2 changes: 0 additions & 2 deletions src/main/SpeedTest.js
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
12 changes: 12 additions & 0 deletions src/main/Util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 0b3ec59

Please sign in to comment.