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 9, 2020
2 parents 0b3ec59 + 8de0386 commit 93058e7
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 23 deletions.
2 changes: 1 addition & 1 deletion config/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,13 @@ Upon each version update you should copy the new syntax from `config.json.exampl
* Default: `"debug"`
* Description: Log level to configure how verbose logging messages are. Output can be found in the /log directory
* Values:
* `"silent"`
* `"fatal"`
* `"error"`
* `"warn"`
* `"info"`
* `"debug"`
* `"trace"`
* `"silent"`

#### `LOG.PRETTY_PRINT` (Boolean)
* Default: `true`
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "binance-triangle-arbitrage",
"version": "5.6.1",
"version": "5.6.2",
"repository": {
"type": "git",
"url": "https://github.com/bmino/binance-triangle-arbitrage.git"
Expand Down
6 changes: 3 additions & 3 deletions src/main/ArbitrageExecution.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ const ArbitrageExecution = {
},

getExecutionStrategy() {
switch (CONFIG.TRADING.EXECUTION_STRATEGY.toLowerCase()) {
switch (CONFIG.TRADING.EXECUTION_STRATEGY) {
case 'parallel':
return ArbitrageExecution.parallelExecutionStrategy;
default:
Expand Down Expand Up @@ -254,8 +254,8 @@ const ArbitrageExecution = {
},

parseActualResults(method, { executedQty, cummulativeQuoteQty, fills }) {
const spent = method.toUpperCase() === 'BUY' ? parseFloat(cummulativeQuoteQty) : parseFloat(executedQty);
const earned = method.toUpperCase() === 'SELL' ? parseFloat(cummulativeQuoteQty) : parseFloat(executedQty);
const spent = method === 'BUY' ? parseFloat(cummulativeQuoteQty) : parseFloat(executedQty);
const earned = method === 'SELL' ? parseFloat(cummulativeQuoteQty) : parseFloat(executedQty);
const fees = fills
.filter(fill => fill.commissionAsset === 'BNB')
.map(fill => parseFloat(fill.commission))
Expand Down
2 changes: 1 addition & 1 deletion src/main/BinanceApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const BinanceApi = {
},

marketBuyOrSell(method) {
return method.toUpperCase() === 'BUY' ? BinanceApi.marketBuy : BinanceApi.marketSell;
return method === 'BUY' ? BinanceApi.marketBuy : BinanceApi.marketSell;
},

handleBuyOrSellError(error, reject) {
Expand Down
12 changes: 6 additions & 6 deletions src/main/CalculationNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const CalculationNode = {
}
};

if (trade.ab.method === 'Buy') {
if (trade.ab.method === 'BUY') {
// Buying BA
const dustedB = CalculationNode.orderBookConversion(investmentA, trade.symbol.a, trade.symbol.b, trade.ab.ticker, depthSnapshot.ab);
calculated.b.earned = calculated.ab = CalculationNode.calculateDustless(trade.ab, dustedB);
Expand All @@ -87,7 +87,7 @@ const CalculationNode = {
calculated.b.earned = CalculationNode.orderBookConversion(calculated.a.spent, trade.symbol.a, trade.symbol.b, trade.ab.ticker, depthSnapshot.ab);
}

if (trade.bc.method === 'Buy') {
if (trade.bc.method === 'BUY') {
// Buying CB
const dustedC = CalculationNode.orderBookConversion(calculated.b.earned, trade.symbol.b, trade.symbol.c, trade.bc.ticker, depthSnapshot.bc);
calculated.c.earned = calculated.bc = CalculationNode.calculateDustless(trade.bc, dustedC);
Expand All @@ -98,7 +98,7 @@ const CalculationNode = {
calculated.c.earned = CalculationNode.orderBookConversion(calculated.b.spent, trade.symbol.b, trade.symbol.c, trade.bc.ticker, depthSnapshot.bc);
}

if (trade.ca.method === 'Buy') {
if (trade.ca.method === 'BUY') {
// Buying AC
const dustedA = CalculationNode.orderBookConversion(calculated.c.earned, trade.symbol.c, trade.symbol.a, trade.ca.ticker, depthSnapshot.ca);
calculated.a.earned = calculated.ca = CalculationNode.calculateDustless(trade.ca, dustedA);
Expand All @@ -122,7 +122,7 @@ const CalculationNode = {

recalculateTradeLeg(trade, quantityEarned, depthSnapshot) {
const { base, quote, method, ticker } = trade;
if (method.toUpperCase() === 'BUY') {
if (method === 'BUY') {
const dustedQuantity = CalculationNode.orderBookConversion(quantityEarned, quote, base, ticker, depthSnapshot);
return CalculationNode.calculateDustless(trade, dustedQuantity);
} else {
Expand Down Expand Up @@ -218,14 +218,14 @@ const CalculationNode = {
const bidRates = Object.keys(depthSnapshot.bids || {});
const askRates = Object.keys(depthSnapshot.asks || {});

if (method === 'Sell') {
if (method === 'SELL') {
for (i=0; i<bidRates.length; i++) {
exchanged += depthSnapshot.bids[bidRates[i]];
if (exchanged >= quantity) {
return i+1;
}
}
} else if (method === 'Buy') {
} else if (method === 'BUY') {
for (i=0; i<askRates.length; i++) {
exchanged += depthSnapshot.asks[askRates[i]];
if (exchanged >= quantity) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/Loggers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const pino = require('pino');

const LOG_DIR = `${__dirname}/../../logs`;
const PINO_OPTS = {
level: CONFIG.LOG.LEVEL.toLowerCase(),
level: CONFIG.LOG.LEVEL,
timestamp: () => `,"time":"${new Date().toLocaleString()}"`,
prettyPrint: CONFIG.LOG.PRETTY_PRINT,
formatters: {
Expand Down
22 changes: 18 additions & 4 deletions src/main/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ function displayStatusUpdate() {
.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(`Network Usage: ${Util.toKB(network[0].rx_sec).toFixed(1)} KBps (down) and ${Util.toKB(network[0].tx_sec).toFixed(1)} KBps (up)`);
logger.performance.debug(`API Latency: ${latency} ms`);
});
}
Expand All @@ -119,10 +119,14 @@ function checkConfig() {

const VALID_VALUES = {
TRADING: {
EXECUTION_STRATEGY: ['linear', 'parallel']
EXECUTION_STRATEGY: ['linear', 'parallel'],
EXECUTION_TEMPLATE: ['BUY', 'SELL', null]
},
DEPTH: {
SIZE: [5, 10, 20, 50, 100, 500]
},
LOG: {
LEVEL: ['trace', 'debug', 'info', 'warn', 'error', 'fatal', 'silent']
}
};

Expand Down Expand Up @@ -157,16 +161,21 @@ function checkConfig() {
logger.execution.error(msg);
throw new Error(msg);
}
if (CONFIG.TRADING.EXECUTION_STRATEGY.toLowerCase() === 'parallel' && CONFIG.TRADING.WHITELIST.length === 0) {
if (CONFIG.TRADING.EXECUTION_STRATEGY === 'parallel' && CONFIG.TRADING.WHITELIST.length === 0) {
const msg = `Parallel execution requires defining a whitelist`;
logger.execution.error(msg);
throw new Error(msg);
}
if (!VALID_VALUES.TRADING.EXECUTION_STRATEGY.includes(CONFIG.TRADING.EXECUTION_STRATEGY.toLowerCase())) {
if (!VALID_VALUES.TRADING.EXECUTION_STRATEGY.includes(CONFIG.TRADING.EXECUTION_STRATEGY)) {
const msg = `${CONFIG.TRADING.EXECUTION_STRATEGY} is an invalid execution strategy`;
logger.execution.error(msg);
throw new Error(msg);
}
if (!CONFIG.TRADING.EXECUTION_TEMPLATE.every(template => VALID_VALUES.TRADING.EXECUTION_TEMPLATE.includes(template))) {
const msg = `${CONFIG.TRADING.EXECUTION_TEMPLATE} is an invalid execution template`;
logger.execution.error(msg);
throw new Error(msg);
}
if (CONFIG.TRADING.TAKER_FEE < 0) {
const msg = `Taker fee (${CONFIG.TRADING.TAKER_FEE}) must be a positive value`;
logger.execution.error(msg);
Expand All @@ -182,6 +191,11 @@ function checkConfig() {
logger.execution.error(msg);
throw new Error(msg);
}
if (!VALID_VALUES.LOG.LEVEL.includes(CONFIG.LOG.LEVEL)) {
const msg = `Log level can only contain one of the following values: ${VALID_VALUES.LOG.LEVEL}`;
logger.execution.error(msg);
throw new Error(msg);
}
if (isNaN(CONFIG.WEBSOCKETS.BUNDLE_SIZE) || CONFIG.WEBSOCKETS.BUNDLE_SIZE <= 0) {
const msg = `Websocket bundle size (${CONFIG.WEBSOCKETS.BUNDLE_SIZE}) must be a positive integer`;
logger.execution.error(msg);
Expand Down
10 changes: 5 additions & 5 deletions src/main/MarketCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ const MarketCache = {

const ab = MarketCache.getRelationship(a, b);
if (!ab) return;
if (CONFIG.TRADING.EXECUTION_TEMPLATE[0] && CONFIG.TRADING.EXECUTION_TEMPLATE[0].toUpperCase() !== ab.method.toUpperCase()) return;
if (CONFIG.TRADING.EXECUTION_TEMPLATE[0] && CONFIG.TRADING.EXECUTION_TEMPLATE[0] !== ab.method) return;

const bc = MarketCache.getRelationship(b, c);
if (!bc) return;
if (CONFIG.TRADING.EXECUTION_TEMPLATE[1] && CONFIG.TRADING.EXECUTION_TEMPLATE[1].toUpperCase() !== bc.method.toUpperCase()) return;
if (CONFIG.TRADING.EXECUTION_TEMPLATE[1] && CONFIG.TRADING.EXECUTION_TEMPLATE[1] !== bc.method) return;

const ca = MarketCache.getRelationship(c, a);
if (!ca) return;
if (CONFIG.TRADING.EXECUTION_TEMPLATE[2] && CONFIG.TRADING.EXECUTION_TEMPLATE[2].toUpperCase() !== ca.method.toUpperCase()) return;
if (CONFIG.TRADING.EXECUTION_TEMPLATE[2] && CONFIG.TRADING.EXECUTION_TEMPLATE[2] !== ca.method) return;

return {
ab,
Expand All @@ -92,14 +92,14 @@ const MarketCache = {

getRelationship(a, b) {
if (MarketCache.tickers.trading[a+b]) return {
method: 'Sell',
method: 'SELL',
ticker: a+b,
base: a,
quote: b,
dustDecimals: MarketCache.tickers.trading[a+b].dustDecimals
};
if (MarketCache.tickers.trading[b+a]) return {
method: 'Buy',
method: 'BUY',
ticker: b+a,
base: b,
quote: a,
Expand Down

0 comments on commit 93058e7

Please sign in to comment.