Skip to content

Instantly share code, notes, and snippets.

@anticlergygang
Last active May 2, 2020 00:50
Show Gist options
  • Select an option

  • Save anticlergygang/139593a2bc058aa1b7c9e55f9edbb2e7 to your computer and use it in GitHub Desktop.

Select an option

Save anticlergygang/139593a2bc058aa1b7c9e55f9edbb2e7 to your computer and use it in GitHub Desktop.
const ccxt = require('ccxt');
const colors = require('colors');
const moment = require('moment-timezone');
const exchanges = {
bittrex: new ccxt.bittrex(),
binance: new ccxt.binance()
};
const percentChange = (oldPrice, newPrce) => {
return ((newPrce - oldPrice) / oldPrice) * 100;
};
let sharedMarkets = ['ADA/BTC', 'ADX/BTC', 'ARK/BTC', 'BAT/BTC', 'BCH/BTC', 'BNT/BTC', 'BTG/BTC', 'DASH/BTC', 'DNT/BTC', 'ENG/BTC', 'ETC/BTC', 'ETH/BTC', 'FUN/BTC', 'KMD/BTC', 'LSK/BTC', 'LTC/BTC', 'LUN/BTC', 'MANA/BTC', 'MCO/BTC', 'NAV/BTC', 'NEO/BTC', 'OMG/BTC', 'PIVX/BTC', 'POWR/BTC', 'QTUM/BTC', 'RCN/BTC', 'RLC/BTC', 'SALT/BTC', 'SNT/BTC', 'STEEM/BTC', 'STORJ/BTC', 'STRAT/BTC', 'VIA/BTC', 'VIB/BTC', 'WAVES/BTC', 'WINGS/BTC', 'XLM/BTC', 'XMR/BTC', 'XRP/BTC', 'XVG/BTC', 'XZC/BTC', 'ZEC/BTC', 'ADA/ETH', 'ADX/ETH', 'BAT/ETH', 'BCH/ETH', 'BNT/ETH', 'BTG/ETH', 'DASH/ETH', 'DNT/ETH', 'ENG/ETH', 'ETC/ETH', 'FUN/ETH', 'LTC/ETH', 'LUN/ETH', 'MANA/ETH', 'MCO/ETH', 'NEO/ETH', 'OMG/ETH', 'POWR/ETH', 'QTUM/ETH', 'RCN/ETH', 'RLC/ETH', 'SALT/ETH', 'SNT/ETH', 'STORJ/ETH', 'STRAT/ETH', 'VIB/ETH', 'WAVES/ETH', 'WINGS/ETH', 'XLM/ETH', 'XMR/ETH', 'XRP/ETH', 'ZEC/ETH', 'BCH/USDT', 'BTC/USDT', 'ETH/USDT', 'LTC/USDT', 'NEO/USDT'];
let sharedMarketsPromises = [];
let sortArr = [];
const checkArbOps = (market = undefined) => {
sharedMarketsPromises = []
sharedMarkets.forEach((e, i) => {
sharedMarketsPromises.push(exchanges.bittrex.fetchTicker(e));
sharedMarketsPromises.push(exchanges.binance.fetchTicker(e));
});
if (market === undefined) {
Promise.all(sharedMarketsPromises).then(out => {
console.log('\n');
sortArr = [];
for (let i = 0; i < out.length / 2; i = i + 2) {
if (percentChange(out[i].ask, out[i + 1].bid).toFixed(2) > 0) {
sortArr.push([`bittrex>binance ${out[i].symbol}: `, `${percentChange(out[i].ask,out[i + 1].bid).toFixed(2)} @ ${moment().format('MM/DD/YYYY hh:mm:ss')}`, percentChange(out[i].ask, out[i + 1].bid).toFixed(2)]);
} else {}
if (percentChange(out[i + 1].ask, out[i].bid).toFixed(2) > 0) {
sortArr.push([`binance>bittrex ${out[i + 1].symbol}: `, `${percentChange(out[i + 1].ask,out[i].bid).toFixed(2)} @ ${moment().format('MM/DD/YYYY hh:mm:ss')}`, percentChange(out[i + 1].ask, out[i].bid).toFixed(2)]);
} else {}
}
sortArr.sort(function(a, b) {
return a[2] - b[2];
});
sortArr.forEach((e, i) => {
if (e[2] >= 1) {
console.log(`${e[0]}${e[1]}`.greenBG);
} else if (e[2] >= 0) {
console.log(`${e[0]}${e[1]}`.green);
} else {}
});
}).catch(err => {
// console.log(err);
});
} else {
Promise.all(sharedMarketsPromises).then(out => {
console.log('\n');
for (let i = 0; i < out.length / 2; i = i + 2) {
if (out[i].symbol === market) {
if (percentChange(out[i].ask, out[i + 1].bid).toFixed(2) > 0) {
console.log(`bittrex>binance ${out[i].symbol}: ${percentChange(out[i].ask,out[i + 1].bid).toFixed(2)} @ ${moment().format('MM/DD/YYYY hh:mm:ss')}`.green);
} else {
console.log(`bittrex>binance ${out[i].symbol}: ${percentChange(out[i].ask,out[i + 1].bid).toFixed(2)}`.red);
}
if (percentChange(out[i + 1].ask, out[i].bid).toFixed(2) > 0) {
console.log(`binance>bittrex ${out[i + 1].symbol}: ${percentChange(out[i + 1].ask,out[i].bid).toFixed(2)} @ ${moment().format('MM/DD/YYYY hh:mm:ss')}`.green);
} else {
console.log(`binance>bittrex ${out[i + 1].symbol}: ${percentChange(out[i + 1].ask,out[i].bid).toFixed(2)}`.red);
}
}
}
}).catch(err => {
// console.log(err);
});
}
};
setInterval(() => {
checkArbOps();
}, 30000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment