From bf903c59e0c95cfcd353d221451a71926d14a201 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Art=C5=ABras=20Sotni=C4=8Denko?= Date: Sun, 23 Jul 2017 04:47:10 +0300 Subject: [PATCH 01/10] added c-cex.io exchange --- settings.js | 44 ++++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/settings.js b/settings.js index 68feca6a..9f2ed6de 100644 --- a/settings.js +++ b/settings.js @@ -2,7 +2,7 @@ // let boilerPlateMarket = // { // marketName: '', -// URL: '', //URL To Fetch API From. +// URL: '', //API URL To Fetch market prices from. // toBTCURL: false, //URL, if needed for an external bitcoin price api. // last: function (data, coin_prices) { //Get the last price of coins in JSON data // return new Promise(function (res, rej) { @@ -62,7 +62,34 @@ let markets = [ } }, + { + marketName: 'c-cex', + URL: 'https://c-cex.com/t/prices.json', //URL To Fetch API From. + toBTCURL: false, //URL, if needed for an external bitcoin price api. + last: function (data, coin_prices) { + return new Promise(function (res, rej) { + try { + for (let ticker in data) { + if(ticker.includes('-btc')) { + let coinName = ticker.replace("-btc", ''); + if (!coin_prices[coinName]) coin_prices[coinName] = {}; + coin_prices[coinName].ccex = ticker.lastprice; + } + if(ticker.includes('btc-')) { + let coinName = ticker.replace("btc-", ''); + if (!coin_prices[coinName]) coin_prices[coinName] = {}; + coin_prices[coinName].ccex = ticker.lastprice; + } + } + res(coin_prices); + } catch(err) { + console.log(err); + rej(err); + } + }) + } + }, { marketName: 'bittrex', URL: 'https://bittrex.com/api/v1.1/public/getmarketsummaries', @@ -88,7 +115,6 @@ let markets = [ }, }, - { marketName: 'btc38', URL: 'http://api.btc38.com/v1/ticker.php?c=all&mk_type=cny', @@ -115,7 +141,6 @@ let markets = [ }) } }, - { marketName: 'jubi', URL: 'https://www.jubi.com/api/v1/allticker/', //URL To Fetch API From. @@ -144,8 +169,6 @@ let markets = [ } }, - - { marketName: 'poloniex', URL: 'https://poloniex.com/public?command=returnTicker', @@ -170,8 +193,7 @@ let markets = [ }) }, - }, - + }, { marketName: 'cryptopia', URL: 'https://www.cryptopia.co.nz/api/GetMarkets/BTC', //URL To Fetch API From. @@ -196,8 +218,7 @@ let markets = [ }) }, - }, - + }, { marketName: 'bleutrade', URL: 'https://bleutrade.com/api/v2/public/getmarketsummaries', //URL To Fetch API From. @@ -223,7 +244,6 @@ let markets = [ }) }, }, - { marketName: 'kraken', // kraken has no one size fits all market summery so each pair has to be entered as param in GET - will need to add new coins as they are added to exchange @@ -259,11 +279,11 @@ let markets = [ }) }, }, - ]; let marketNames = []; -for(let i = 1; i < markets.length; i++) { // Loop except cryptowatch +let marketLen = markets.length //assiging len to variable so that evey loop it wont look up the makert length +for(let i = 1; i < marketLen; i++) { // Loop except cryptowatch marketNames.push(markets[i].marketName); } console.log("Markets:", marketNames); From 8960ef53deb610ae52b743045befc45ac8276fc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Art=C5=ABras=20Sotni=C4=8Denko?= Date: Sun, 23 Jul 2017 05:44:38 +0300 Subject: [PATCH 02/10] added c-cex.io exchange --- settings.js | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/settings.js b/settings.js index 9f2ed6de..a7bb7eb3 100644 --- a/settings.js +++ b/settings.js @@ -41,7 +41,6 @@ let markets = [ if (indexOfBTC > 0 && !pair.includes('future') && !market.includes('qryptos') && !market.includes('quoine') && !market.includes('poloniex') && !market.includes('kraken')) { if(marketNames.indexOf(market) === -1 ){ marketNames.push(market); - console.log(marketNames); } let coin = pair.replace(/btc/i, '').toUpperCase(); let price = data[key].price.last; @@ -71,15 +70,11 @@ let markets = [ return new Promise(function (res, rej) { try { for (let ticker in data) { - if(ticker.includes('-btc')) { - let coinName = ticker.replace("-btc", ''); + let ticker = ticker.toUpperCase() + if(ticker.includes('-BTC')) { + let coinName = ticker.replace("-BTC", ''); if (!coin_prices[coinName]) coin_prices[coinName] = {}; - coin_prices[coinName].ccex = ticker.lastprice; - } - if(ticker.includes('btc-')) { - let coinName = ticker.replace("btc-", ''); - if (!coin_prices[coinName]) coin_prices[coinName] = {}; - coin_prices[coinName].ccex = ticker.lastprice; + coin_prices[coinName].ccex = data[ticker].lastprice; } } res(coin_prices); @@ -149,7 +144,7 @@ let markets = [ last: function (data, coin_prices, toBTCURL) { //Where to find the last price of coin in JSON data return new Promise(function (res, rej) { let priceOfBTC = data.btc.last; - console.log(priceOfBTC); + //console.log(priceOfBTC); try { for (let key in data) { let coinName = key.toUpperCase(); @@ -160,7 +155,6 @@ let markets = [ } res(coin_prices); } - catch (err) { console.log(err); rej(err) From 5a8a95f51ddf70fdbbe12d55a1e280727ec4c700 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Art=C5=ABras=20Sotni=C4=8Denko?= Date: Sun, 23 Jul 2017 06:18:17 +0300 Subject: [PATCH 03/10] A little fix I forgot to commit --- settings.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/settings.js b/settings.js index a7bb7eb3..2ba55ae0 100644 --- a/settings.js +++ b/settings.js @@ -70,9 +70,8 @@ let markets = [ return new Promise(function (res, rej) { try { for (let ticker in data) { - let ticker = ticker.toUpperCase() if(ticker.includes('-BTC')) { - let coinName = ticker.replace("-BTC", ''); + let coinName = ticker.replace("-BTC", '').toUpperCase(); if (!coin_prices[coinName]) coin_prices[coinName] = {}; coin_prices[coinName].ccex = data[ticker].lastprice; } From 10ce8fd36c6d0c7174539c2cf538ba3fb61da960 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Art=C5=ABras=20Sotni=C4=8Denko?= Date: Mon, 24 Jul 2017 01:08:29 +0300 Subject: [PATCH 04/10] refactored some code to be more readable --- docs/index.html | 7 ++- docs/js/script.js | 7 +-- index.html | 3 +- main.js | 125 +++++++++++++++++++++++++--------------------- package.json | 3 +- settings.js | 32 +++++++++--- 6 files changed, 103 insertions(+), 74 deletions(-) diff --git a/docs/index.html b/docs/index.html index 0ad4c48d..095ed1eb 100644 --- a/docs/index.html +++ b/docs/index.html @@ -6,12 +6,12 @@ - Cryptocurrency Arbitrage + Altcoin Arbitrage - + @@ -55,7 +55,6 @@ - diff --git a/docs/js/script.js b/docs/js/script.js index 42988c94..a0abf115 100644 --- a/docs/js/script.js +++ b/docs/js/script.js @@ -6,8 +6,9 @@ function history(coin1, coin2) { var checkedMarkets = { showAll: true, - bittrex: true, - poloniex: true + cexio: true, + 'c-cex': true, + cryptopia: true, }, checkedCoins = { @@ -104,7 +105,7 @@ $(window).load(function () { $('#header').show(); - let socket = io('https://ccarbitrage.azurewebsites.net/'); + let socket = io('localhost:3000'); let numberOfLoads = 0; //Number of final results loads let numberOfMLoads = 0; //Number of Market loadss diff --git a/index.html b/index.html index 48d23522..a770130e 100644 --- a/index.html +++ b/index.html @@ -24,7 +24,8 @@ socket.on('news', function (data) { $('#messages').empty(); - for(var i = data.length-1; i >= 0 ; i--) { + let length = data.length + for(var i = 0; i < length ; i++) { $('#messages').append($('
  • ').text(data[i])); } }); diff --git a/main.js b/main.js index 031ef16b..66f2193f 100644 --- a/main.js +++ b/main.js @@ -2,12 +2,16 @@ * Created by Manu Masson on 6/27/2017. * */ - 'use strict'; -const request = require('request'), Promise = require("bluebird"); //request for pulling JSON from api. Bluebird for Promises. +const request = require('request'), + Promise = require("bluebird"); //request for pulling JSON from api. Bluebird for Promises. -const app = require('express')(), helmet = require('helmet'), http = require('http').Server(app), io = require('socket.io')(http); // For websocket server functionality +const app = require('express')(), + helmet = require('helmet'), + http = require('http').Server(app), + io = require('socket.io')(http); +// For websocket server functionality app.use(helmet.hidePoweredBy({setTo: 'PHP/5.4.0'})); // app.use(cors({credentials: false})); const port = process.env.PORT || 3000; @@ -21,60 +25,56 @@ http.listen(port, function () { console.log('listening on', port); }); - -require('./settings.js')(); //Includes settings file. +require('./settings.js')(); //Includes settings file. (Market info) let coinNames = []; +// coin_prices is an object with data on price differences between markets. = {BTC : {market1 : 2000, market2: 4000, p : 2}, } (P for percentage difference) +// results is a 2D array with coin name and percentage difference, sorted from low to high. +let coin_prices = {}, + numberOfRequests = 0, + results = []; // GLOBAL variables to get pushed to browser. io.on('connection', function (socket) { socket.emit('coinsAndMarkets', [marketNames, coinNames]); socket.emit('results', results); }); -// coin_prices is an object with data on price differences between markets. = {BTC : {market1 : 2000, market2: 4000, p : 2}, } (P for percentage difference) -// results is a 2D array with coin name and percentage difference, sorted from low to high. -let coin_prices = {}, numberOfRequests = 0, results = []; // GLOBAL variables to get pushed to browser. function getMarketData(options, coin_prices, callback) { //GET JSON DATA - return new Promise(function (resolve, reject) { - request(options.URL, function (error, response, body) { - try { - let data = JSON.parse(body); - console.log("Success", options.marketName); + return new Promise( + function (resolve, reject) { + request(options.URL, function (error, response, body) { + let data + if(error) { + console.log("Error getting JSON response from", options.URL, error); //Throws error + throw new Error('error ' + error) + } + try { + data = JSON.parse(body); + } catch(error) { + console.log("Error getting JSON response from", options.URL, error); //Throws error + throw new Error(error) + } if (options.marketName) { - let newCoinPrices; - newCoinPrices = options.last(data, coin_prices, options.toBTCURL); numberOfRequests++; - if (numberOfRequests >= 1) computePrices(coin_prices); resolve(newCoinPrices); - } - else { - resolve(data); - } - - } catch (error) { - console.log("Error getting JSON response from", options.URL, error); //Throws error - reject(error); - } - - }); - - - }); + }) + }) } -function computePrices(data) { +async function computePrices(data) { + //console.log('computiing price ' + data ) if (numberOfRequests >= 2) { results = []; - for (let coin in data) { + for (let coin in data) { if (Object.keys(data[coin]).length > 1){ - if(coinNames.includes(coin) == false) coinNames.push(coin); - - - let arr = []; + if(coinNames.includes(coin) == false) { + coinNames.push(coin); + } + let arr = []; for (let market in data[coin]) { arr.push([data[coin][market], market]); } @@ -86,34 +86,43 @@ function computePrices(data) { results.push([coin, arr[i][0] / arr[j][0], arr[i][0], arr[j][0], arr[i][1], arr[j][1] ], [coin, arr[j][0] / arr[i][0], arr[j][0], arr[i][0], arr[j][1], arr[i][1]]); } } - } } results.sort(function (a, b) { return a[1] - b[1]; }); - - io.emit('news', results); + return results } } +async function getTickerData(urls) { + return Promise.all(urls.map(function(url) { + return getMarketData(url, coin_prices).reflect() + })).filter(function(promise) { + return promise.isFulfilled(); + }) +} +async function computePrice(tickers) { + return Promise.all(tickers.map((ticker) => { + return computePrices(ticker.value()) + }) + ) +} -(async function main() { - let arrayOfRequests = []; - - for (let i = 0; i < markets.length; i++) { - arrayOfRequests.push(getMarketData(markets[i], coin_prices)); - } - - await Promise.all(arrayOfRequests.map(p => p.catch(e => e))) - - .then(results => computePrices(coin_prices)) - - .catch(e => console.log(e)); - - setTimeout(main, 10000); -})(); - -// .then(v => { -// // console.log(v); -// }); +async function main() { + Promise.all( + getTickerData(markets)) + .then(results => { + console.log('numberOfRequests ' + numberOfRequests); + return computePrice(results) + }) + .catch(error => console.log( error)) + .then(results => { + results.map((result)=> { + io.emit('results', result); + }) + }).catch(error => console.log( error)) + + setTimeout(main, 20000); +}; +main() diff --git a/package.json b/package.json index a0b1afc6..458f7106 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,8 @@ }, "scripts": { "test": "node main", - "start": "node main" + "start": "pm2 start main.js", + "dev": "pm2 start main.js --watch" }, "repository": { "type": "git", diff --git a/settings.js b/settings.js index 2ba55ae0..a39f9462 100644 --- a/settings.js +++ b/settings.js @@ -25,11 +25,13 @@ let markets = [ - { - marketName: 'cryptowatchAPI', + +/* { + marketName: 'cryptowatchAPI', URL: 'https://api.cryptowat.ch/markets/summaries', //URL To Fetch API From. toBTCURL: false, //URL, if needed for an external bitcoin price api. - + link: 'https://cryptowat.ch', + ref: '', last: function (data, coin_prices, toBTCURL) { //Where to find the last price of coin in JSON data return new Promise(function (res, rej) { try { @@ -60,12 +62,14 @@ let markets = [ }) } - }, + },*/ { marketName: 'c-cex', URL: 'https://c-cex.com/t/prices.json', //URL To Fetch API From. toBTCURL: false, //URL, if needed for an external bitcoin price api. - + link: 'https://c-cex.com/', + ref: '?rf=FECEAFAABCEB70DC', + //https://c-cex.com/?rf=FECEAFAABCEB70DC last: function (data, coin_prices) { return new Promise(function (res, rej) { try { @@ -88,6 +92,8 @@ let markets = [ marketName: 'bittrex', URL: 'https://bittrex.com/api/v1.1/public/getmarketsummaries', toBTCURL: false, + link: 'https://bittrex.com/', + ref: '', last: function (data, coin_prices) { //Where to find the last price of coin in JSON data return new Promise(function (res, rej) { try { @@ -113,6 +119,8 @@ let markets = [ marketName: 'btc38', URL: 'http://api.btc38.com/v1/ticker.php?c=all&mk_type=cny', toBTCURL: false, + link: 'https://btc38.com/', + ref: '', last: function (data, coin_prices, toBTCURL) { //Where to find the last price of coin in JSON data return new Promise(function (res, rej) { @@ -139,6 +147,8 @@ let markets = [ marketName: 'jubi', URL: 'https://www.jubi.com/api/v1/allticker/', //URL To Fetch API From. toBTCURL: false, //URL, if needed for an external bitcoin price api. + link: 'https://jubi.com/', + ref: '', last: function (data, coin_prices, toBTCURL) { //Where to find the last price of coin in JSON data return new Promise(function (res, rej) { @@ -166,6 +176,8 @@ let markets = [ marketName: 'poloniex', URL: 'https://poloniex.com/public?command=returnTicker', toBTCURL: false, + link: 'https://poloniex.com/', + ref: '', last: function (data, coin_prices) { //Where to find the last price of coin in JSON data return new Promise(function (res, rej) { try { @@ -191,6 +203,8 @@ let markets = [ marketName: 'cryptopia', URL: 'https://www.cryptopia.co.nz/api/GetMarkets/BTC', //URL To Fetch API From. toBTCURL: false, //URL, if needed for an external bitcoin price api. + ref: '?referrer=ScreamingMoose', + link: 'https://www.cryptopia.co.nz/', last: function (data, coin_prices) { //Get the last price of coins in JSON data return new Promise(function (res, rej) { try { @@ -202,7 +216,6 @@ let markets = [ } } res(coin_prices); - } catch (err) { console.log(err); @@ -216,6 +229,8 @@ let markets = [ marketName: 'bleutrade', URL: 'https://bleutrade.com/api/v2/public/getmarketsummaries', //URL To Fetch API From. toBTCURL: false, //URL, if needed for an external bitcoin price api. + link: 'https://bleutrade.com/', + ref: '', last: function (data, coin_prices) { //Get the last price of coins in JSON data return new Promise(function (res, rej) { try { @@ -237,11 +252,14 @@ let markets = [ }) }, }, + { marketName: 'kraken', // kraken has no one size fits all market summery so each pair has to be entered as param in GET - will need to add new coins as they are added to exchange URL: 'https://api.kraken.com/0/public/Ticker?pair=DASHXBT,EOSXBT,GNOXBT,ETCXBT,ETHXBT,ICNXBT,LTCXBT,MLNXBT,REPXBT,XDGXBT,XLMXBT,XMRXBT,XRPXBT,ZECXBT', //URL To Fetch API From. toBTCURL: false, //URL, if needed for an external bitcoin price api. + link: 'https://bikraken.com/', + ref: '', last: function (data, coin_prices) { //Get the last price of coins in JSON data return new Promise(function (res, rej) { try { @@ -276,7 +294,7 @@ let markets = [ let marketNames = []; let marketLen = markets.length //assiging len to variable so that evey loop it wont look up the makert length -for(let i = 1; i < marketLen; i++) { // Loop except cryptowatch +for(let i = 0; i < marketLen; i++) { // Loop except cryptowatch marketNames.push(markets[i].marketName); } console.log("Markets:", marketNames); From 3a9bf8f94dad58de09819808a89fbf765c5d419e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Art=C5=ABras=20Sotni=C4=8Denko?= Date: Mon, 24 Jul 2017 01:30:30 +0300 Subject: [PATCH 05/10] readed cryptowatchAPI --- settings.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/settings.js b/settings.js index a39f9462..0382a905 100644 --- a/settings.js +++ b/settings.js @@ -26,7 +26,7 @@ let markets = [ -/* { + { marketName: 'cryptowatchAPI', URL: 'https://api.cryptowat.ch/markets/summaries', //URL To Fetch API From. toBTCURL: false, //URL, if needed for an external bitcoin price api. @@ -62,7 +62,7 @@ let markets = [ }) } - },*/ + }, { marketName: 'c-cex', URL: 'https://c-cex.com/t/prices.json', //URL To Fetch API From. @@ -294,7 +294,7 @@ let markets = [ let marketNames = []; let marketLen = markets.length //assiging len to variable so that evey loop it wont look up the makert length -for(let i = 0; i < marketLen; i++) { // Loop except cryptowatch +for(let i = 1; i < marketLen; i++) { // Loop except cryptowatch marketNames.push(markets[i].marketName); } console.log("Markets:", marketNames); From 5d7993a28e011fc3e2d30390d01d3414ddd34238 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Art=C5=ABras=20Sotni=C4=8Denko?= Date: Mon, 24 Jul 2017 01:33:49 +0300 Subject: [PATCH 06/10] reverted original docs --- docs/index.html | 7 ++++--- docs/js/script.js | 7 +++---- settings.js | 3 ++- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/docs/index.html b/docs/index.html index 095ed1eb..0ad4c48d 100644 --- a/docs/index.html +++ b/docs/index.html @@ -6,12 +6,12 @@ - Altcoin Arbitrage + Cryptocurrency Arbitrage - + @@ -55,6 +55,7 @@ + diff --git a/docs/js/script.js b/docs/js/script.js index a0abf115..42988c94 100644 --- a/docs/js/script.js +++ b/docs/js/script.js @@ -6,9 +6,8 @@ function history(coin1, coin2) { var checkedMarkets = { showAll: true, - cexio: true, - 'c-cex': true, - cryptopia: true, + bittrex: true, + poloniex: true }, checkedCoins = { @@ -105,7 +104,7 @@ $(window).load(function () { $('#header').show(); - let socket = io('localhost:3000'); + let socket = io('https://ccarbitrage.azurewebsites.net/'); let numberOfLoads = 0; //Number of final results loads let numberOfMLoads = 0; //Number of Market loadss diff --git a/settings.js b/settings.js index 0382a905..29f5e1bd 100644 --- a/settings.js +++ b/settings.js @@ -74,8 +74,9 @@ let markets = [ return new Promise(function (res, rej) { try { for (let ticker in data) { + let ticker = ticker.toUpperCase() if(ticker.includes('-BTC')) { - let coinName = ticker.replace("-BTC", '').toUpperCase(); + let coinName = ticker.replace("-BTC", ''); if (!coin_prices[coinName]) coin_prices[coinName] = {}; coin_prices[coinName].ccex = data[ticker].lastprice; } From be77c4493ae6db65740a7ad9795e70a772942f2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Art=C5=ABras=20Sotni=C4=8Denko?= Date: Mon, 24 Jul 2017 02:10:42 +0300 Subject: [PATCH 07/10] reverted setting to last --- settings.js | 676 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 398 insertions(+), 278 deletions(-) diff --git a/settings.js b/settings.js index b8e90e08..fd313b9e 100644 --- a/settings.js +++ b/settings.js @@ -1,294 +1,414 @@ -// -// let boilerPlateMarket = -// { -// marketName: '', -// URL: '', //API URL To Fetch market prices from. -// toBTCURL: false, //URL, if needed for an external bitcoin price api. -// last: function (data, coin_prices) { //Get the last price of coins in JSON data -// return new Promise(function (res, rej) { -// try { -// for (x in / of data) { -// price = ...; -// coin_prices[coinName][marketName] = price; -// } -// res(coin_prices); -// } -// catch (err) { -// rej(err); -// } -// -// }) -// }, -// -// -// } -// { -// marketName: 'cryptowatchAPI', -// URL: 'https://api.cryptowat.ch/markets/summaries', //URL To Fetch API From. -// toBTCURL: false, //URL, if needed for an external bitcoin price api. -// last: function (data, coin_prices, toBTCURL) { //Where to find the last price of coin in JSON data -// return new Promise(function (res, rej) { -// try { -// data = data.result; -// for (let key in data) { -// let marketPair = key.split(':'); -// let market = marketPair[0], pair = marketPair[1]; -// let indexOfBTC = pair.indexOf('btc'); -// if (indexOfBTC > 0 && !pair.includes('future') && !market.includes('qryptos') && !market.includes('quoine') && !market.includes('poloniex') && !market.includes('kraken')) { -// if(marketNames.indexOf(market) === -1 ){ -// marketNames.push(market); -// console.log(marketNames); -// } -// let coin = pair.replace(/btc/i, '').toUpperCase(); -// let price = data[key].price.last; -// if(price > 0) { -// if (!coin_prices[coin]) coin_prices[coin] = {}; -// coin_prices[coin][market] = price; -// -// } -// } -// } -// res(coin_prices); -// } -// catch (err) { -// console.log(err); -// rej(err) -// } -// }) -// } -// -// }, - -let markets = [ - - +// +// let boilerPlateMarket = +// { +// marketName: '', +// URL: '', //API URL To Fetch market prices from. +// toBTCURL: false, //URL, if needed for an external bitcoin price api. +// last: function (data, coin_prices) { //Get the last price of coins in JSON data +// return new Promise(function (res, rej) { +// try { +// for (x in / of data) { +// price = ...; +// coin_prices[coinName][marketName] = price; +// } +// res(coin_prices); +// } +// catch (err) { +// rej(err); +// } +// +// }) +// }, +// +// +// } +// { +// marketName: 'cryptowatchAPI', +// URL: 'https://api.cryptowat.ch/markets/summaries', //URL To Fetch API From. +// toBTCURL: false, //URL, if needed for an external bitcoin price api. +// last: function (data, coin_prices, toBTCURL) { //Where to find the last price of coin in JSON data +// return new Promise(function (res, rej) { +// try { +// data = data.result; +// for (let key in data) { +// let marketPair = key.split(':'); +// let market = marketPair[0], pair = marketPair[1]; +// let indexOfBTC = pair.indexOf('btc'); +// if (indexOfBTC > 0 && !pair.includes('future') && !market.includes('qryptos') && !market.includes('quoine') && !market.includes('poloniex') && !market.includes('kraken')) { +// if(marketNames.indexOf(market) === -1 ){ +// marketNames.push(market); +// console.log(marketNames); +// } +// let coin = pair.replace(/btc/i, '').toUpperCase(); +// let price = data[key].price.last; +// if(price > 0) { +// if (!coin_prices[coin]) coin_prices[coin] = {}; +// coin_prices[coin][market] = price; +// +// } +// } +// } +// res(coin_prices); +// } +// catch (err) { +// console.log(err); +// rej(err) +// } +// }) +// } +// +// }, + +let markets = [ + + { + marketName: 'cryptowatchAPI', + URL: 'https://api.cryptowat.ch/markets/summaries', //URL To Fetch API From. + toBTCURL: false, //URL, if needed for an external bitcoin price api. + link: 'https://cryptowat.ch', + ref: '', + last: function (data, coin_prices, toBTCURL) { //Where to find the last price of coin in JSON data + return new Promise(function (res, rej) { + try { + data = data.result; + for (let key in data) { + let marketPair = key.split(':'); + let market = marketPair[0], pair = marketPair[1]; + let indexOfBTC = pair.indexOf('btc'); + if (indexOfBTC > 0 && !pair.includes('future') && !market.includes('qryptos') && !market.includes('quoine') && !market.includes('poloniex') && !market.includes('kraken')) { + if(marketNames.indexOf(market) === -1 ){ + marketNames.push(market); + } + let coin = pair.replace(/btc/i, '').toUpperCase(); + let price = data[key].price.last; + if(price > 0) { + if (!coin_prices[coin]) coin_prices[coin] = {}; + coin_prices[coin][market] = price; + + + { + marketName: 'c-cex', + URL: 'https://c-cex.com/t/prices.json', //URL To Fetch API From. + toBTCURL: false, //URL, if needed for an external bitcoin price api. + link: 'https://c-cex.com/', + ref: '?rf=FECEAFAABCEB70DC', + //https://c-cex.com/?rf=FECEAFAABCEB70DC + last: function (data, coin_prices) { + return new Promise(function (res, rej) { + try { + for (let ticker in data) { + let ticker = ticker.toUpperCase() + if(ticker.includes('-BTC')) { + let coinName = ticker.replace("-BTC", ''); + if (!coin_prices[coinName]) coin_prices[coinName] = {}; + coin_prices[coinName].ccex = data[ticker].lastprice; + } + } + res(coin_prices); + } catch(err) { + console.log(err); + rej(err); + } + }) + } + }, +======= + + +>>>>>>> master + { + marketName: 'bittrex', + URL: 'https://bittrex.com/api/v1.1/public/getmarketsummaries', + toBTCURL: false, + link: 'https://bittrex.com/', + ref: '', + last: function (data, coin_prices) { //Where to find the last price of coin in JSON data + return new Promise(function (res, rej) { + try { + for (let obj of data.result) { + if(obj["MarketName"].includes('BTC-')) { + let coinName = obj["MarketName"].replace("BTC-", ''); + if (!coin_prices[coinName]) coin_prices[coinName] = {}; + coin_prices[coinName].bittrex = obj.Last; + } + } + res(coin_prices); + } + catch (err) { + console.log(err); + rej(err); + } + + }) + }, + + }, + { + marketName: 'btc38', + URL: 'http://api.btc38.com/v1/ticker.php?c=all&mk_type=cny', + toBTCURL: false, + link: 'https://btc38.com/', + ref: '', + + last: function (data, coin_prices, toBTCURL) { //Where to find the last price of coin in JSON data + return new Promise(function (res, rej) { + let priceOfBTC = data.btc.ticker.last; + try { + for (let key in data) { + let coinName = key.toUpperCase(); + let price = data[key]['ticker'].last; + if (!coin_prices[coinName]) coin_prices[coinName] = {}; + + coin_prices[coinName]["btc38"] = data[key]['ticker'].last / priceOfBTC; + } + res(coin_prices); + } + + catch (err) { + console.log(err); + rej(err) + } + }) + } + }, + { + marketName: 'jubi', + URL: 'https://www.jubi.com/api/v1/allticker/', //URL To Fetch API From. + toBTCURL: false, //URL, if needed for an external bitcoin price api. + link: 'https://jubi.com/', + ref: '', + + last: function (data, coin_prices, toBTCURL) { //Where to find the last price of coin in JSON data + return new Promise(function (res, rej) { + let priceOfBTC = data.btc.last; + //console.log(priceOfBTC); + try { + for (let key in data) { + let coinName = key.toUpperCase(); + let price = data[key].last; + if (!coin_prices[coinName]) coin_prices[coinName] = {}; + + coin_prices[coinName]["jubi"] = data[key].last / priceOfBTC; + } + res(coin_prices); + } + catch (err) { + console.log(err); + rej(err) + } + }) + } + + }, + { + marketName: 'poloniex', + URL: 'https://poloniex.com/public?command=returnTicker', + toBTCURL: false, + link: 'https://poloniex.com/', + ref: '', + last: function (data, coin_prices) { //Where to find the last price of coin in JSON data + return new Promise(function (res, rej) { + try { + for (var obj in data) { + if(obj.includes('BTC_')&&obj!=="BTC_EMC2") { + let coinName = obj.replace("BTC_", ''); + if (!coin_prices[coinName]) coin_prices[coinName] = {}; + coin_prices[coinName].poloniex = data[obj].last; + } + } + res(coin_prices); + } + catch (err) { + console.log(err); + rej(err); + } + + }) + }, + + }, + { + marketName: 'cryptopia', + URL: 'https://www.cryptopia.co.nz/api/GetMarkets/BTC', //URL To Fetch API From. + toBTCURL: false, //URL, if needed for an external bitcoin price api. + ref: '?referrer=ScreamingMoose', + link: 'https://www.cryptopia.co.nz/', + last: function (data, coin_prices) { //Get the last price of coins in JSON data + return new Promise(function (res, rej) { + try { + for (let obj of data.Data) { + if(obj["Label"].includes('/BTC')) { + let coinName = obj["Label"].replace("/BTC", ''); + if (!coin_prices[coinName]) coin_prices[coinName] = {}; + coin_prices[coinName].cryptopia = obj.LastPrice; + } + } + res(coin_prices); + } + catch (err) { + console.log(err); + rej(err); + } + + }) + }, + }, + { + marketName: 'bleutrade', + URL: 'https://bleutrade.com/api/v2/public/getmarketsummaries', //URL To Fetch API From. + toBTCURL: false, //URL, if needed for an external bitcoin price api. + link: 'https://bleutrade.com/', + ref: '', + last: function (data, coin_prices) { //Get the last price of coins in JSON data + return new Promise(function (res, rej) { + try { + for (let obj of data.result) { + if(obj["MarketName"].includes('_BTC')) { + let coinName = obj["MarketName"].replace("_BTC", ''); + if (!coin_prices[coinName]) coin_prices[coinName] = {}; + coin_prices[coinName].bleutrade = obj.Last; + } + } + res(coin_prices); + + } + catch (err) { + console.log(err); + rej(err); + } + + }) + }, + }, + + { + + marketName: 'kraken', // kraken has no one size fits all market summery so each pair has to be entered as param in GET - will need to add new coins as they are added to exchange + URL: 'https://api.kraken.com/0/public/Ticker?pair=DASHXBT,EOSXBT,GNOXBT,ETCXBT,ETHXBT,ICNXBT,LTCXBT,MLNXBT,REPXBT,XDGXBT,XLMXBT,XMRXBT,XRPXBT,ZECXBT', //URL To Fetch API From. + toBTCURL: false, //URL, if needed for an external bitcoin price api. + link: 'https://bikraken.com/', + ref: '', + last: function (data, coin_prices) { //Get the last price of coins in JSON data + return new Promise(function (res, rej) { + try { + for (let key in data.result) { + let arr = key.match(/DASH|EOS|GNO|ETC|ETH|ICN|LTC|MLN|REP|XDG|XLM|XMR|XRP|ZEC/); // matching real names to weird kraken api coin pairs like "XETCXXBT" etc + let name = key; + let matchedName = arr[0]; + if (matchedName === "XDG") { //kraken calls DOGE "XDG" for whatever reason + let matchedName = "DOGE"; + var coinName = matchedName; + } else { + var coinName = matchedName; + } + + if (!coin_prices[coinName]) coin_prices[coinName] = {}; + + coin_prices[coinName].kraken = data.result[name].c[0]; + + } + res(coin_prices); + + } + catch (err) { + console.log(err); + rej(err); + } + + }) + }, + }, +]; + +let marketNames = []; +let marketLen = markets.length //assiging len to variable so that evey loop it wont look up the makert length +for(let i = 1; i < marketLen; i++) { // Loop except cryptowatch + marketNames.push(markets[i].marketName); +} +console.log("Markets:", marketNames); +module.exports = function () { + this.markets = markets; + this.marketNames = marketNames; +}; + +<<<<<<< HEAD + { - marketName: 'c-cex', - URL: 'https://c-cex.com/t/prices.json', //URL To Fetch API From. - toBTCURL: false, //URL, if needed for an external bitcoin price api. - link: 'https://c-cex.com/', - ref: '?rf=FECEAFAABCEB70DC', - //https://c-cex.com/?rf=FECEAFAABCEB70DC - last: function (data, coin_prices) { - return new Promise(function (res, rej) { - try { - for (let ticker in data) { - let ticker = ticker.toUpperCase() - if(ticker.includes('-BTC')) { - let coinName = ticker.replace("-BTC", ''); - if (!coin_prices[coinName]) coin_prices[coinName] = {}; - coin_prices[coinName].ccex = data[ticker].lastprice; - } - } - res(coin_prices); - } catch(err) { - console.log(err); - rej(err); - } - }) - } - }, - { - marketName: 'bittrex', - URL: 'https://bittrex.com/api/v1.1/public/getmarketsummaries', - toBTCURL: false, - pairURL : '', - last: function (data, coin_prices) { //Where to find the last price of coin in JSON data - return new Promise(function (res, rej) { - try { - for (let obj of data.result) { - if(obj["MarketName"].includes('BTC-')) { - let coinName = obj["MarketName"].replace("BTC-", ''); - if (!coin_prices[coinName]) coin_prices[coinName] = {}; - coin_prices[coinName].bittrex = obj.Last; - } - } - res(coin_prices); - } - catch (err) { - console.log(err); - rej(err); - } - - }) - }, - - }, - { - marketName: 'btc38', - URL: 'http://api.btc38.com/v1/ticker.php?c=all&mk_type=cny', - toBTCURL: false, - pairURL : '', - last: function (data, coin_prices, toBTCURL) { //Where to find the last price of coin in JSON data - return new Promise(function (res, rej) { - let priceOfBTC = data.btc.ticker.last; - try { - for (let key in data) { - let coinName = key.toUpperCase(); - let price = data[key]['ticker'].last; - if (!coin_prices[coinName]) coin_prices[coinName] = {}; - - coin_prices[coinName]["btc38"] = data[key]['ticker'].last / priceOfBTC; - } - res(coin_prices); - } - - catch (err) { - console.log(err); - rej(err) - } - }) - } - }, - { - marketName: 'jubi', - URL: 'https://www.jubi.com/api/v1/allticker/', //URL To Fetch API From. + marketName: 'cryptowatchAPI', + URL: 'https://api.cryptowat.ch/markets/summaries', //URL To Fetch API From. toBTCURL: false, //URL, if needed for an external bitcoin price api. - pairURL : '', + link: 'https://cryptowat.ch', + ref: '', last: function (data, coin_prices, toBTCURL) { //Where to find the last price of coin in JSON data return new Promise(function (res, rej) { - let priceOfBTC = data.btc.last; - //console.log(priceOfBTC); try { + data = data.result; for (let key in data) { - let coinName = key.toUpperCase(); - let price = data[key].last; - if (!coin_prices[coinName]) coin_prices[coinName] = {}; - - coin_prices[coinName]["jubi"] = data[key].last / priceOfBTC; - } - res(coin_prices); - } - catch (err) { - console.log(err); - rej(err) - } - }) - } - - }, - { - marketName: 'poloniex', - URL: 'https://poloniex.com/public?command=returnTicker', - toBTCURL: false, + let marketPair = key.split(':'); + let market = marketPair[0], pair = marketPair[1]; + let indexOfBTC = pair.indexOf('btc'); + if (indexOfBTC > 0 && !pair.includes('future') && !market.includes('qryptos') && !market.includes('quoine') && !market.includes('poloniex') && !market.includes('kraken')) { + if(marketNames.indexOf(market) === -1 ){ + marketNames.push(market); + } + let coin = pair.replace(/btc/i, '').toUpperCase(); + let price = data[key].price.last; + if(price > 0) { + if (!coin_prices[coin]) coin_prices[coin] = {}; + coin_prices[coin][market] = price; +<<<<<<< HEAD + link: 'https://bittrex.com/', + ref: '', +======= pairURL : '', - last: function (data, coin_prices) { //Where to find the last price of coin in JSON data - return new Promise(function (res, rej) { - try { - for (var obj in data) { - if(obj.includes('BTC_')&&obj!=="BTC_EMC2") { - let coinName = obj.replace("BTC_", ''); - if (!coin_prices[coinName]) coin_prices[coinName] = {}; - coin_prices[coinName].poloniex = data[obj].last; - } - } - res(coin_prices); - } - catch (err) { - console.log(err); - rej(err); - } +>>>>>>> master +<<<<<<< HEAD + link: 'https://btc38.com/', + ref: '', - }) - }, - - }, - { - marketName: 'cryptopia', - URL: 'https://www.cryptopia.co.nz/api/GetMarkets/BTC', //URL To Fetch API From. - toBTCURL: false, //URL, if needed for an external bitcoin price api. +======= pairURL : '', - last: function (data, coin_prices) { //Get the last price of coins in JSON data - return new Promise(function (res, rej) { - try { - for (let obj of data.Data) { - if(obj["Label"].includes('/BTC')) { - let coinName = obj["Label"].replace("/BTC", ''); - if (!coin_prices[coinName]) coin_prices[coinName] = {}; - coin_prices[coinName].cryptopia = obj.LastPrice; - } - } - res(coin_prices); - } - catch (err) { - console.log(err); - rej(err); - } +>>>>>>> master +<<<<<<< HEAD + link: 'https://jubi.com/', + ref: '', - }) - }, - }, - { - marketName: 'bleutrade', - URL: 'https://bleutrade.com/api/v2/public/getmarketsummaries', //URL To Fetch API From. - toBTCURL: false, //URL, if needed for an external bitcoin price api. +======= + pairURL : '', +>>>>>>> master +<<<<<<< HEAD + link: 'https://poloniex.com/', + ref: '', +======= + pairURL : '', +>>>>>>> master +<<<<<<< HEAD + ref: '?referrer=ScreamingMoose', + link: 'https://www.cryptopia.co.nz/', + last: function (data, coin_prices) { //Get the last price of coins in JSON data +======= pairURL : '', last: function (data, coin_prices) { //Get the last price of coins in JSON data - return new Promise(function (res, rej) { - try { - for (let obj of data.result) { - if(obj["MarketName"].includes('_BTC')) { - let coinName = obj["MarketName"].replace("_BTC", ''); - if (!coin_prices[coinName]) coin_prices[coinName] = {}; - coin_prices[coinName].bleutrade = obj.Last; - } - } - res(coin_prices); - - } - catch (err) { - console.log(err); - rej(err); - } - - }) - }, - }, - - { - - marketName: 'kraken', // kraken has no one size fits all market summery so each pair has to be entered as param in GET - will need to add new coins as they are added to exchange - URL: 'https://api.kraken.com/0/public/Ticker?pair=DASHXBT,EOSXBT,GNOXBT,ETCXBT,ETHXBT,ICNXBT,LTCXBT,MLNXBT,REPXBT,XDGXBT,XLMXBT,XMRXBT,XRPXBT,ZECXBT', //URL To Fetch API From. - toBTCURL: false, //URL, if needed for an external bitcoin price api. +>>>>>>> master +<<<<<<< HEAD + link: 'https://bleutrade.com/', + ref: '', + last: function (data, coin_prices) { //Get the last price of coins in JSON data +======= pairURL : '', last: function (data, coin_prices) { //Get the last price of coins in JSON data - return new Promise(function (res, rej) { - try { - for (let key in data.result) { - let arr = key.match(/DASH|EOS|GNO|ETC|ETH|ICN|LTC|MLN|REP|XDG|XLM|XMR|XRP|ZEC/); // matching real names to weird kraken api coin pairs like "XETCXXBT" etc - let name = key; - let matchedName = arr[0]; - if (matchedName === "XDG") { //kraken calls DOGE "XDG" for whatever reason - let matchedName = "DOGE"; - var coinName = matchedName; - } else { - var coinName = matchedName; - } - - if (!coin_prices[coinName]) coin_prices[coinName] = {}; - - coin_prices[coinName].kraken = data.result[name].c[0]; - - } - res(coin_prices); - - } - catch (err) { - console.log(err); - rej(err); - } - - }) - }, - }, -]; - -let marketNames = []; +>>>>>>> master +<<<<<<< HEAD + link: 'https://bikraken.com/', + ref: '', +======= + pairURL : '', +>>>>>>> master +<<<<<<< HEAD +let marketLen = markets.length //assiging len to variable so that evey loop it wont look up the makert length +for(let i = 1; i < marketLen; i++) { // Loop except cryptowatch + marketNames.push(markets[i].marketName); +======= for(let i = 0; i < markets.length; i++) { // Loop except ~~cryptowatch~~ disable cryptowatch marketNames.push([[markets[i].marketName], [markets[i].pairURL]]); -} -console.log("Markets:", marketNames); -module.exports = function () { - this.markets = markets; - this.marketNames = marketNames; -}; +>>>>>>> master \ No newline at end of file From 246848c63db5f5cc5ac4e235c9325c058c772163 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Art=C5=ABras=20Sotni=C4=8Denko?= Date: Mon, 24 Jul 2017 02:14:06 +0300 Subject: [PATCH 08/10] merget settings.js --- settings.js | 659 +++++++++++++++++++++------------------------------- 1 file changed, 261 insertions(+), 398 deletions(-) diff --git a/settings.js b/settings.js index fd313b9e..c0d5b554 100644 --- a/settings.js +++ b/settings.js @@ -1,414 +1,277 @@ -// -// let boilerPlateMarket = -// { -// marketName: '', -// URL: '', //API URL To Fetch market prices from. -// toBTCURL: false, //URL, if needed for an external bitcoin price api. -// last: function (data, coin_prices) { //Get the last price of coins in JSON data -// return new Promise(function (res, rej) { -// try { -// for (x in / of data) { -// price = ...; -// coin_prices[coinName][marketName] = price; -// } -// res(coin_prices); -// } -// catch (err) { -// rej(err); -// } -// -// }) -// }, -// -// -// } -// { -// marketName: 'cryptowatchAPI', -// URL: 'https://api.cryptowat.ch/markets/summaries', //URL To Fetch API From. -// toBTCURL: false, //URL, if needed for an external bitcoin price api. -// last: function (data, coin_prices, toBTCURL) { //Where to find the last price of coin in JSON data -// return new Promise(function (res, rej) { -// try { -// data = data.result; -// for (let key in data) { -// let marketPair = key.split(':'); -// let market = marketPair[0], pair = marketPair[1]; -// let indexOfBTC = pair.indexOf('btc'); -// if (indexOfBTC > 0 && !pair.includes('future') && !market.includes('qryptos') && !market.includes('quoine') && !market.includes('poloniex') && !market.includes('kraken')) { -// if(marketNames.indexOf(market) === -1 ){ -// marketNames.push(market); -// console.log(marketNames); -// } -// let coin = pair.replace(/btc/i, '').toUpperCase(); -// let price = data[key].price.last; -// if(price > 0) { -// if (!coin_prices[coin]) coin_prices[coin] = {}; -// coin_prices[coin][market] = price; -// -// } -// } -// } -// res(coin_prices); -// } -// catch (err) { -// console.log(err); -// rej(err) -// } -// }) -// } -// -// }, - -let markets = [ - - { - marketName: 'cryptowatchAPI', - URL: 'https://api.cryptowat.ch/markets/summaries', //URL To Fetch API From. - toBTCURL: false, //URL, if needed for an external bitcoin price api. - link: 'https://cryptowat.ch', - ref: '', - last: function (data, coin_prices, toBTCURL) { //Where to find the last price of coin in JSON data - return new Promise(function (res, rej) { - try { - data = data.result; - for (let key in data) { - let marketPair = key.split(':'); - let market = marketPair[0], pair = marketPair[1]; - let indexOfBTC = pair.indexOf('btc'); - if (indexOfBTC > 0 && !pair.includes('future') && !market.includes('qryptos') && !market.includes('quoine') && !market.includes('poloniex') && !market.includes('kraken')) { - if(marketNames.indexOf(market) === -1 ){ - marketNames.push(market); - } - let coin = pair.replace(/btc/i, '').toUpperCase(); - let price = data[key].price.last; - if(price > 0) { - if (!coin_prices[coin]) coin_prices[coin] = {}; - coin_prices[coin][market] = price; - - - { - marketName: 'c-cex', - URL: 'https://c-cex.com/t/prices.json', //URL To Fetch API From. - toBTCURL: false, //URL, if needed for an external bitcoin price api. - link: 'https://c-cex.com/', - ref: '?rf=FECEAFAABCEB70DC', - //https://c-cex.com/?rf=FECEAFAABCEB70DC - last: function (data, coin_prices) { - return new Promise(function (res, rej) { - try { - for (let ticker in data) { - let ticker = ticker.toUpperCase() - if(ticker.includes('-BTC')) { - let coinName = ticker.replace("-BTC", ''); - if (!coin_prices[coinName]) coin_prices[coinName] = {}; - coin_prices[coinName].ccex = data[ticker].lastprice; - } - } - res(coin_prices); - } catch(err) { - console.log(err); - rej(err); - } - }) - } - }, -======= - - ->>>>>>> master - { - marketName: 'bittrex', - URL: 'https://bittrex.com/api/v1.1/public/getmarketsummaries', - toBTCURL: false, - link: 'https://bittrex.com/', - ref: '', - last: function (data, coin_prices) { //Where to find the last price of coin in JSON data - return new Promise(function (res, rej) { - try { - for (let obj of data.result) { - if(obj["MarketName"].includes('BTC-')) { - let coinName = obj["MarketName"].replace("BTC-", ''); - if (!coin_prices[coinName]) coin_prices[coinName] = {}; - coin_prices[coinName].bittrex = obj.Last; - } - } - res(coin_prices); - } - catch (err) { - console.log(err); - rej(err); - } - - }) - }, - - }, - { - marketName: 'btc38', - URL: 'http://api.btc38.com/v1/ticker.php?c=all&mk_type=cny', - toBTCURL: false, - link: 'https://btc38.com/', - ref: '', - - last: function (data, coin_prices, toBTCURL) { //Where to find the last price of coin in JSON data - return new Promise(function (res, rej) { - let priceOfBTC = data.btc.ticker.last; - try { - for (let key in data) { - let coinName = key.toUpperCase(); - let price = data[key]['ticker'].last; - if (!coin_prices[coinName]) coin_prices[coinName] = {}; - - coin_prices[coinName]["btc38"] = data[key]['ticker'].last / priceOfBTC; - } - res(coin_prices); - } - - catch (err) { - console.log(err); - rej(err) - } - }) - } - }, - { - marketName: 'jubi', - URL: 'https://www.jubi.com/api/v1/allticker/', //URL To Fetch API From. - toBTCURL: false, //URL, if needed for an external bitcoin price api. - link: 'https://jubi.com/', - ref: '', - - last: function (data, coin_prices, toBTCURL) { //Where to find the last price of coin in JSON data - return new Promise(function (res, rej) { - let priceOfBTC = data.btc.last; - //console.log(priceOfBTC); - try { - for (let key in data) { - let coinName = key.toUpperCase(); - let price = data[key].last; - if (!coin_prices[coinName]) coin_prices[coinName] = {}; - - coin_prices[coinName]["jubi"] = data[key].last / priceOfBTC; - } - res(coin_prices); - } - catch (err) { - console.log(err); - rej(err) - } - }) - } - - }, - { - marketName: 'poloniex', - URL: 'https://poloniex.com/public?command=returnTicker', - toBTCURL: false, - link: 'https://poloniex.com/', - ref: '', - last: function (data, coin_prices) { //Where to find the last price of coin in JSON data - return new Promise(function (res, rej) { - try { - for (var obj in data) { - if(obj.includes('BTC_')&&obj!=="BTC_EMC2") { - let coinName = obj.replace("BTC_", ''); - if (!coin_prices[coinName]) coin_prices[coinName] = {}; - coin_prices[coinName].poloniex = data[obj].last; - } - } - res(coin_prices); - } - catch (err) { - console.log(err); - rej(err); - } - - }) - }, - - }, - { - marketName: 'cryptopia', - URL: 'https://www.cryptopia.co.nz/api/GetMarkets/BTC', //URL To Fetch API From. - toBTCURL: false, //URL, if needed for an external bitcoin price api. - ref: '?referrer=ScreamingMoose', - link: 'https://www.cryptopia.co.nz/', - last: function (data, coin_prices) { //Get the last price of coins in JSON data - return new Promise(function (res, rej) { - try { - for (let obj of data.Data) { - if(obj["Label"].includes('/BTC')) { - let coinName = obj["Label"].replace("/BTC", ''); - if (!coin_prices[coinName]) coin_prices[coinName] = {}; - coin_prices[coinName].cryptopia = obj.LastPrice; - } - } - res(coin_prices); - } - catch (err) { - console.log(err); - rej(err); - } - - }) - }, - }, - { - marketName: 'bleutrade', - URL: 'https://bleutrade.com/api/v2/public/getmarketsummaries', //URL To Fetch API From. - toBTCURL: false, //URL, if needed for an external bitcoin price api. - link: 'https://bleutrade.com/', - ref: '', - last: function (data, coin_prices) { //Get the last price of coins in JSON data - return new Promise(function (res, rej) { - try { - for (let obj of data.result) { - if(obj["MarketName"].includes('_BTC')) { - let coinName = obj["MarketName"].replace("_BTC", ''); - if (!coin_prices[coinName]) coin_prices[coinName] = {}; - coin_prices[coinName].bleutrade = obj.Last; - } - } - res(coin_prices); - - } - catch (err) { - console.log(err); - rej(err); - } - - }) - }, - }, - - { - - marketName: 'kraken', // kraken has no one size fits all market summery so each pair has to be entered as param in GET - will need to add new coins as they are added to exchange - URL: 'https://api.kraken.com/0/public/Ticker?pair=DASHXBT,EOSXBT,GNOXBT,ETCXBT,ETHXBT,ICNXBT,LTCXBT,MLNXBT,REPXBT,XDGXBT,XLMXBT,XMRXBT,XRPXBT,ZECXBT', //URL To Fetch API From. - toBTCURL: false, //URL, if needed for an external bitcoin price api. - link: 'https://bikraken.com/', - ref: '', - last: function (data, coin_prices) { //Get the last price of coins in JSON data - return new Promise(function (res, rej) { - try { - for (let key in data.result) { - let arr = key.match(/DASH|EOS|GNO|ETC|ETH|ICN|LTC|MLN|REP|XDG|XLM|XMR|XRP|ZEC/); // matching real names to weird kraken api coin pairs like "XETCXXBT" etc - let name = key; - let matchedName = arr[0]; - if (matchedName === "XDG") { //kraken calls DOGE "XDG" for whatever reason - let matchedName = "DOGE"; - var coinName = matchedName; - } else { - var coinName = matchedName; - } - - if (!coin_prices[coinName]) coin_prices[coinName] = {}; - - coin_prices[coinName].kraken = data.result[name].c[0]; - - } - res(coin_prices); - - } - catch (err) { - console.log(err); - rej(err); - } - - }) - }, - }, -]; - -let marketNames = []; -let marketLen = markets.length //assiging len to variable so that evey loop it wont look up the makert length -for(let i = 1; i < marketLen; i++) { // Loop except cryptowatch - marketNames.push(markets[i].marketName); -} -console.log("Markets:", marketNames); -module.exports = function () { - this.markets = markets; - this.marketNames = marketNames; -}; - -<<<<<<< HEAD - +// +// let boilerPlateMarket = +// { +// marketName: '', +// URL: '', //URL To Fetch API From. +// toBTCURL: false, //URL, if needed for an external bitcoin price api. +// last: function (data, coin_prices) { //Get the last price of coins in JSON data +// return new Promise(function (res, rej) { +// try { +// for (x in / of data) { +// price = ...; +// coin_prices[coinName][marketName] = price; +// } +// res(coin_prices); +// } +// catch (err) { +// rej(err); +// } +// +// }) +// }, +// +// +// } +// { +// marketName: 'cryptowatchAPI', +// URL: 'https://api.cryptowat.ch/markets/summaries', //URL To Fetch API From. +// toBTCURL: false, //URL, if needed for an external bitcoin price api. +// last: function (data, coin_prices, toBTCURL) { //Where to find the last price of coin in JSON data +// return new Promise(function (res, rej) { +// try { +// data = data.result; +// for (let key in data) { +// let marketPair = key.split(':'); +// let market = marketPair[0], pair = marketPair[1]; +// let indexOfBTC = pair.indexOf('btc'); +// if (indexOfBTC > 0 && !pair.includes('future') && !market.includes('qryptos') && !market.includes('quoine') && !market.includes('poloniex') && !market.includes('kraken')) { +// if(marketNames.indexOf(market) === -1 ){ +// marketNames.push(market); +// console.log(marketNames); +// } +// let coin = pair.replace(/btc/i, '').toUpperCase(); +// let price = data[key].price.last; +// if(price > 0) { +// if (!coin_prices[coin]) coin_prices[coin] = {}; +// coin_prices[coin][market] = price; +// +// } +// } +// } +// res(coin_prices); +// } +// catch (err) { +// console.log(err); +// rej(err) +// } +// }) +// } +// +// }, + +let markets = [ + + { - marketName: 'cryptowatchAPI', - URL: 'https://api.cryptowat.ch/markets/summaries', //URL To Fetch API From. - toBTCURL: false, //URL, if needed for an external bitcoin price api. - link: 'https://cryptowat.ch', - ref: '', + marketName: 'bittrex', + URL: 'https://bittrex.com/api/v1.1/public/getmarketsummaries', + toBTCURL: false, + pairURL : '', + last: function (data, coin_prices) { //Where to find the last price of coin in JSON data + return new Promise(function (res, rej) { + try { + for (let obj of data.result) { + if(obj["MarketName"].includes('BTC-')) { + let coinName = obj["MarketName"].replace("BTC-", ''); + if (!coin_prices[coinName]) coin_prices[coinName] = {}; + coin_prices[coinName].bittrex = obj.Last; + } + } + res(coin_prices); + } + catch (err) { + console.log(err); + rej(err); + } + + }) + }, + + }, + + { + marketName: 'btc38', + URL: 'http://api.btc38.com/v1/ticker.php?c=all&mk_type=cny', + toBTCURL: false, + pairURL : '', last: function (data, coin_prices, toBTCURL) { //Where to find the last price of coin in JSON data return new Promise(function (res, rej) { + let priceOfBTC = data.btc.ticker.last; try { - data = data.result; for (let key in data) { - let marketPair = key.split(':'); - let market = marketPair[0], pair = marketPair[1]; - let indexOfBTC = pair.indexOf('btc'); - if (indexOfBTC > 0 && !pair.includes('future') && !market.includes('qryptos') && !market.includes('quoine') && !market.includes('poloniex') && !market.includes('kraken')) { - if(marketNames.indexOf(market) === -1 ){ - marketNames.push(market); - } - let coin = pair.replace(/btc/i, '').toUpperCase(); - let price = data[key].price.last; - if(price > 0) { - if (!coin_prices[coin]) coin_prices[coin] = {}; - coin_prices[coin][market] = price; -<<<<<<< HEAD - link: 'https://bittrex.com/', - ref: '', -======= - pairURL : '', ->>>>>>> master -<<<<<<< HEAD - link: 'https://btc38.com/', - ref: '', + let coinName = key.toUpperCase(); + let price = data[key]['ticker'].last; + if (!coin_prices[coinName]) coin_prices[coinName] = {}; -======= - pairURL : '', ->>>>>>> master -<<<<<<< HEAD - link: 'https://jubi.com/', - ref: '', + coin_prices[coinName]["btc38"] = data[key]['ticker'].last / priceOfBTC; + } + res(coin_prices); + } + + catch (err) { + console.log(err); + rej(err) + } + }) + } + }, -======= + { + marketName: 'jubi', + URL: 'https://www.jubi.com/api/v1/allticker/', //URL To Fetch API From. + toBTCURL: false, //URL, if needed for an external bitcoin price api. pairURL : '', ->>>>>>> master -<<<<<<< HEAD - link: 'https://poloniex.com/', - ref: '', -======= + last: function (data, coin_prices, toBTCURL) { //Where to find the last price of coin in JSON data + return new Promise(function (res, rej) { + let priceOfBTC = data.btc.last; + console.log(priceOfBTC); + try { + for (let key in data) { + let coinName = key.toUpperCase(); + let price = data[key].last; + if (!coin_prices[coinName]) coin_prices[coinName] = {}; + + coin_prices[coinName]["jubi"] = data[key].last / priceOfBTC; + } + res(coin_prices); + } + + catch (err) { + console.log(err); + rej(err) + } + }) + } + + }, + + + { + marketName: 'poloniex', + URL: 'https://poloniex.com/public?command=returnTicker', + toBTCURL: false, pairURL : '', ->>>>>>> master -<<<<<<< HEAD - ref: '?referrer=ScreamingMoose', - link: 'https://www.cryptopia.co.nz/', - last: function (data, coin_prices) { //Get the last price of coins in JSON data -======= + last: function (data, coin_prices) { //Where to find the last price of coin in JSON data + return new Promise(function (res, rej) { + try { + for (var obj in data) { + if(obj.includes('BTC_')&&obj!=="BTC_EMC2") { + let coinName = obj.replace("BTC_", ''); + if (!coin_prices[coinName]) coin_prices[coinName] = {}; + coin_prices[coinName].poloniex = data[obj].last; + } + } + res(coin_prices); + } + catch (err) { + console.log(err); + rej(err); + } + + }) + }, + + }, + + { + marketName: 'cryptopia', + URL: 'https://www.cryptopia.co.nz/api/GetMarkets/BTC', //URL To Fetch API From. + toBTCURL: false, //URL, if needed for an external bitcoin price api. pairURL : '', last: function (data, coin_prices) { //Get the last price of coins in JSON data ->>>>>>> master -<<<<<<< HEAD - link: 'https://bleutrade.com/', - ref: '', - last: function (data, coin_prices) { //Get the last price of coins in JSON data -======= + return new Promise(function (res, rej) { + try { + for (let obj of data.Data) { + if(obj["Label"].includes('/BTC')) { + let coinName = obj["Label"].replace("/BTC", ''); + if (!coin_prices[coinName]) coin_prices[coinName] = {}; + coin_prices[coinName].cryptopia = obj.LastPrice; + } + } + res(coin_prices); + + } + catch (err) { + console.log(err); + rej(err); + } + + }) + }, + }, + + { + marketName: 'bleutrade', + URL: 'https://bleutrade.com/api/v2/public/getmarketsummaries', //URL To Fetch API From. + toBTCURL: false, //URL, if needed for an external bitcoin price api. pairURL : '', last: function (data, coin_prices) { //Get the last price of coins in JSON data ->>>>>>> master -<<<<<<< HEAD - link: 'https://bikraken.com/', - ref: '', -======= + return new Promise(function (res, rej) { + try { + for (let obj of data.result) { + if(obj["MarketName"].includes('_BTC')) { + let coinName = obj["MarketName"].replace("_BTC", ''); + if (!coin_prices[coinName]) coin_prices[coinName] = {}; + coin_prices[coinName].bleutrade = obj.Last; + } + } + res(coin_prices); + + } + catch (err) { + console.log(err); + rej(err); + } + + }) + }, + }, + + { + + marketName: 'kraken', // kraken has no one size fits all market summery so each pair has to be entered as param in GET - will need to add new coins as they are added to exchange + URL: 'https://api.kraken.com/0/public/Ticker?pair=DASHXBT,EOSXBT,GNOXBT,ETCXBT,ETHXBT,ICNXBT,LTCXBT,MLNXBT,REPXBT,XDGXBT,XLMXBT,XMRXBT,XRPXBT,ZECXBT', //URL To Fetch API From. + toBTCURL: false, //URL, if needed for an external bitcoin price api. pairURL : '', ->>>>>>> master -<<<<<<< HEAD -let marketLen = markets.length //assiging len to variable so that evey loop it wont look up the makert length -for(let i = 1; i < marketLen; i++) { // Loop except cryptowatch - marketNames.push(markets[i].marketName); -======= + last: function (data, coin_prices) { //Get the last price of coins in JSON data + return new Promise(function (res, rej) { + try { + for (let key in data.result) { + let arr = key.match(/DASH|EOS|GNO|ETC|ETH|ICN|LTC|MLN|REP|XDG|XLM|XMR|XRP|ZEC/); // matching real names to weird kraken api coin pairs like "XETCXXBT" etc + let name = key; + let matchedName = arr[0]; + if (matchedName === "XDG") { //kraken calls DOGE "XDG" for whatever reason + let matchedName = "DOGE"; + var coinName = matchedName; + } else { + var coinName = matchedName; + } + + if (!coin_prices[coinName]) coin_prices[coinName] = {}; + + coin_prices[coinName].kraken = data.result[name].c[0]; + + } + res(coin_prices); + + } + catch (err) { + console.log(err); + rej(err); + } + + }) + }, + }, + +]; + +let marketNames = []; for(let i = 0; i < markets.length; i++) { // Loop except ~~cryptowatch~~ disable cryptowatch marketNames.push([[markets[i].marketName], [markets[i].pairURL]]); ->>>>>>> master \ No newline at end of file +} +console.log("Markets:", marketNames); +module.exports = function () { + this.markets = markets; + this.marketNames = marketNames; +}; From 403a41b89d96278570d6ac08604ebbec1ad39145 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Art=C5=ABras=20Sotni=C4=8Denko?= Date: Mon, 24 Jul 2017 09:27:11 +0300 Subject: [PATCH 09/10] broke some stuff, but its readable now --- .gitignore | 4 +- docs/fonts/cryptocoins.css | 1 - docs/index.html | 22 +++++++ docs/js/script.js | 132 ++++++++++++++++++++++++------------- index.html | 4 +- main.js | 47 +++++++------ package.json | 5 +- settings.js | 28 +++++++- 8 files changed, 169 insertions(+), 74 deletions(-) diff --git a/.gitignore b/.gitignore index 9bbc2987..b7cb2980 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,6 @@ logs *.log npm-debug.log* node_modules/ -package-lock.json \ No newline at end of file +package-lock.json +.pm2-log +pm2-log \ No newline at end of file diff --git a/docs/fonts/cryptocoins.css b/docs/fonts/cryptocoins.css index 4a403da7..3d251d74 100644 --- a/docs/fonts/cryptocoins.css +++ b/docs/fonts/cryptocoins.css @@ -4,7 +4,6 @@ font-family: "cryptocoins-icons"; src: url('./cryptocoins-icons.eot'); src: url('./cryptocoins-icons.eot?#iefix') format('eot'), - url('./cryptocoins-icons.woff2') format('woff2'), url('./cryptocoins-icons.woff') format('woff'), url('./cryptocoins-icons.ttf') format('truetype'), url('./cryptocoins-icons.svg#cryptocoins-icons') format('svg'); diff --git a/docs/index.html b/docs/index.html index 11ea7555..1f455fc0 100644 --- a/docs/index.html +++ b/docs/index.html @@ -159,6 +159,7 @@

    Cryptocurrency Arbitrage Calcula
    +
    @@ -270,6 +271,27 @@

    sell for {{pair.coin}} and transfer back to {{pair this opportunity

  • +