From 94edb82564d85e008c4aaf6dd9878c5ca93e79fd Mon Sep 17 00:00:00 2001 From: Gil Rosenthal Date: Wed, 26 Jul 2017 21:23:52 -0400 Subject: [PATCH 1/3] Add bid/ask system for more accurate prices --- main.js | 18 ++++++++++++------ settings.js | 43 ++++++++++++++++++++++++++++++------------- 2 files changed, 42 insertions(+), 19 deletions(-) diff --git a/main.js b/main.js index e658194e..c22bd26f 100644 --- a/main.js +++ b/main.js @@ -76,17 +76,23 @@ function computePrices(data) { if(coinNames.includes(coin) == false) coinNames.push(coin); - let arr = []; + let asks = []; + let bids = []; for (let market in data[coin]) { - arr.push([data[coin][market], market]); + asks.push([data[coin][market].ask, market]); + bids.push([data[coin][market].bid, market]); } - arr.sort(function (a, b) { + asks.sort(function (a, b) { return a[0] - b[0]; }); - for (let i = 0; i < arr.length; i++) { - for (let j = i + 1; j < arr.length; j++) { - 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]]); + bids.sort(function(a,b){ + return b[0] - a[0]; + }); + for (let i = 0; i < asks.length; i++) { + for (let j = i; j < asks.length; j++) { + results.push([coin,bids[i][0]/asks[j][0],bids[i][0],asks[j][0],bids[i][1],asks[j][1] ]); } + } } diff --git a/settings.js b/settings.js index 9c5d4ada..9bb87a39 100644 --- a/settings.js +++ b/settings.js @@ -74,7 +74,10 @@ let markets = [ if(obj["MarketName"].includes('BTC-')) { let coinName = obj["MarketName"].replace("BTC-", ''); if (!coin_prices[coinName]) coin_prices[coinName] = {}; - coin_prices[coinName].bittrex = obj.Last; + coin_prices[coinName]['bittrex'] = { + bid: obj.Bid, + ask: obj.Ask + }; } } res(coin_prices); @@ -102,8 +105,10 @@ let markets = [ 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; + coin_prices[coinName]['btc38'] = { + bid: data[key]['ticker'].buy / priceOfBTC, + ask: data[key]['ticker'].sell / priceOfBTC + }; } res(coin_prices); } @@ -130,8 +135,10 @@ let markets = [ let coinName = key.toUpperCase(); let price = data[key].last; if (!coin_prices[coinName]) coin_prices[coinName] = {}; - - coin_prices[coinName]["jubi"] = data[key].last / priceOfBTC; + coin_prices[coinName]['jubi'] = { + bid: data[key].buy / priceOfBTC, + ask: data[key].sell / priceOfBTC + }; } res(coin_prices); } @@ -158,7 +165,10 @@ let markets = [ 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; + coin_prices[coinName]['poloniex'] = { + bid: data[obj].highestBid, + ask: data[obj].lowestAsk + }; } } res(coin_prices); @@ -184,8 +194,11 @@ let markets = [ 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; + if (!coin_prices[coinName]) coin_prices[coinName] = {}; + coin_prices[coinName]['cryptopia'] = { + bid: obj.BidPrice, + ask: obj.AskPrice + }; } } res(coin_prices); @@ -211,8 +224,11 @@ let markets = [ 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; + if (!coin_prices[coinName]) coin_prices[coinName] = {}; + coin_prices[coinName]['bleutrade'] = { + bid: obj.Bid, + ask: obj.Ask + }; } } res(coin_prices); @@ -248,9 +264,10 @@ let markets = [ } if (!coin_prices[coinName]) coin_prices[coinName] = {}; - - coin_prices[coinName].kraken = data.result[name].c[0]; - + coin_prices[coinName]['kraken'] = { + bid: data.result[name].b[0], + ask: data.result[name].a[0] + }; } res(coin_prices); From fcbc84156de30ab6041af9c2b9da88f02293242b Mon Sep 17 00:00:00 2001 From: Gil Rosenthal Date: Wed, 26 Jul 2017 21:41:55 -0400 Subject: [PATCH 2/3] Make exchange name link to coin pair on said exchange, resolves #11 --- docs/index.html | 2 +- docs/js/script.js | 27 ++++++++++++++++++++++----- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/docs/index.html b/docs/index.html index 11ea7555..32b72f74 100644 --- a/docs/index.html +++ b/docs/index.html @@ -237,7 +237,7 @@

Highest price differences + pairs