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 16, 2020
2 parents 93058e7 + f93d5bc commit 86ef13a
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 22 deletions.
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.2",
"version": "5.6.3",
"repository": {
"type": "git",
"url": "https://github.com/bmino/binance-triangle-arbitrage.git"
Expand Down
8 changes: 3 additions & 5 deletions src/main/ArbitrageExecution.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ const ArbitrageExecution = {
executeCalculatedPosition(calculated) {
const startTime = Date.now();

if (!ArbitrageExecution.isSafeToExecute(calculated)) return false;

const { symbol } = calculated.trade;
const age = {
ab: startTime - calculated.depth.ab.eventTime,
Expand Down Expand Up @@ -56,9 +54,9 @@ const ArbitrageExecution = {
logger.execution.debug(`Price Error: ${variation.ab.toFixed(8)}%`);
logger.execution.debug();
logger.execution.debug(`${calculated.trade.bc.ticker} Stats:`);
logger.execution.debug(`BC Expected Conversion: ${calculated.b.spent.toFixed(8)} ${symbol.b} into ${calculated.c.earned.toFixed(8)} ${symbol.c}`);
logger.execution.debug(`BC Observed Conversion: ${actual.b.spent.toFixed(8)} ${symbol.b} into ${actual.c.earned.toFixed(8)} ${symbol.c}`);
logger.execution.debug(`BC Price Error: ${variation.bc.toFixed(8)}%`);
logger.execution.debug(`Expected Conversion: ${calculated.b.spent.toFixed(8)} ${symbol.b} into ${calculated.c.earned.toFixed(8)} ${symbol.c}`);
logger.execution.debug(`Observed Conversion: ${actual.b.spent.toFixed(8)} ${symbol.b} into ${actual.c.earned.toFixed(8)} ${symbol.c}`);
logger.execution.debug(`Price Error: ${variation.bc.toFixed(8)}%`);
logger.execution.debug();
logger.execution.debug(`${calculated.trade.ca.ticker} Stats:`);
logger.execution.debug(`Expected Conversion: ${calculated.c.spent.toFixed(8)} ${symbol.c} into ${calculated.a.earned.toFixed(8)} ${symbol.a}`);
Expand Down
11 changes: 7 additions & 4 deletions src/main/CalculationNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ const CalculationNode = {

cycleCount: 0,

cycle(relationships, depthCacheClone, errorCallback, executionCallback) {
cycle(relationships, depthCacheClone, errorCallback, executionCheckCallback, executionCallback) {
const startTime = Date.now();

let successCount = 0;
let errorCount = 0;
let results = {};

relationships.forEach(relationship => {
for (const relationship of relationships) {
try {
const depthSnapshot = {
ab: depthCacheClone[relationship.ab.ticker],
Expand All @@ -22,13 +22,16 @@ const CalculationNode = {
if (calculated) {
successCount++;
if (CONFIG.HUD.ENABLED) results[calculated.id] = calculated;
executionCallback(calculated);
if (executionCheckCallback(calculated)) {
executionCallback(calculated);
break;
}
}
} catch (error) {
errorCount++;
errorCallback(error.message);
}
});
}

const calculationTime = Date.now() - startTime;

Expand Down
31 changes: 20 additions & 11 deletions src/main/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,32 @@ checkConfig()
.catch(handleError);

function calculateArbitrage() {
const depthSnapshots = BinanceApi.getDepthSnapshots(MarketCache.tickers.watching);
MarketCache.pruneDepthCacheAboveThreshold(depthSnapshots, CONFIG.DEPTH.SIZE);
if (isSafeToCalculateArbitrage()) {
const depthSnapshots = BinanceApi.getDepthSnapshots(MarketCache.tickers.watching);
MarketCache.pruneDepthCacheAboveThreshold(depthSnapshots, CONFIG.DEPTH.SIZE);

const { calculationTime, successCount, errorCount, results } = CalculationNode.cycle(
MarketCache.relationships,
depthSnapshots,
(e) => logger.performance.warn(e),
ArbitrageExecution.executeCalculatedPosition
);
const {calculationTime, successCount, errorCount, results} = CalculationNode.cycle(
MarketCache.relationships,
depthSnapshots,
(e) => logger.performance.warn(e),
ArbitrageExecution.isSafeToExecute,
ArbitrageExecution.executeCalculatedPosition
);

recentCalculationTimes.push(calculationTime);
if (CONFIG.HUD.ENABLED) refreshHUD(results);
recentCalculationTimes.push(calculationTime);
if (CONFIG.HUD.ENABLED) refreshHUD(results);

displayCalculationResults(successCount, errorCount, calculationTime);
}

displayCalculationResults(successCount, errorCount, calculationTime);
setTimeout(calculateArbitrage, CONFIG.TIMING.CALCULATION_COOLDOWN);
}

function isSafeToCalculateArbitrage() {
if (ArbitrageExecution.inProgressIds.size > 0) return false;
return true;
}

function displayCalculationResults(successCount, errorCount, calculationTime) {
if (errorCount === 0) return;
const totalCalculations = successCount + errorCount;
Expand Down

0 comments on commit 86ef13a

Please sign in to comment.