Skip to content

Commit

Permalink
Merge pull request #33 from Someguy123/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Rishi556 authored Jan 23, 2024
2 parents 42e3c0e + c075d11 commit 3b26760
Show file tree
Hide file tree
Showing 12 changed files with 209 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/adapters/BTCEAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var BTCEAdapter = {

request(ticker_url, function(error,response,body) {
if(error || response.statusCode != 200) {
console.error('Invalid response code or server error:',error,response.statusCode);
console.error('Invalid response code or server error:',error,response);
return callback(true,null);
}
var ticker_data = JSON.parse(body);
Expand Down
1 change: 1 addition & 0 deletions lib/adapters/BinanceAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var BinanceAdapter = {
name: 'Binance',
code: 'binance',
provides: [
['hive','usdt'],
['btc','usdt'],
['hive','btc'],
],
Expand Down
41 changes: 41 additions & 0 deletions lib/adapters/BitfinexAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
var request = require('request'),
BaseAdapter = require('./base');

var BitfinexAdapter = {
name: 'Bitfinex',
code: 'bitfinex',
provides: [
['usdt','usd'],
['btc','usd']
],

has_pair: (from, to) => BaseAdapter.has_pair_ext(from, to, BitfinexAdapter.provides),

get_pair: function(from,to,callback) {
if (!BitfinexAdapter.has_pair(from, to)) {
return callback(`Pair ${from}/${to} is not supported by this adapter.`, null);
}

if (from === 'usdt')
from = 'ust'

var pair = [from,to].join('').toUpperCase(),
ticker_url = `https://api-pub.bitfinex.com/v2/ticker/t${pair}`;
request(ticker_url, function(error,response,body) {
if(error || response.statusCode !== 200) {
return callback(true,null);
}
try {
let ticker_data = JSON.parse(body);
if(!ticker_data || !ticker_data[6]) {
return callback(true,null);
}
return callback(false, ticker_data[6])
} catch {
return callback(true, null)
}
});
},
}

module.exports = BitfinexAdapter;
38 changes: 38 additions & 0 deletions lib/adapters/CoinbaseAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
var request = require('request'),
BaseAdapter = require('./base');

var CoinbaseAdapter = {
name: 'Coinbase',
code: 'coinbase',
provides: [
['usdt','usd'],
['btc','usd']
],

has_pair: (from, to) => BaseAdapter.has_pair_ext(from, to, CoinbaseAdapter.provides),

get_pair: function(from,to,callback) {
if (!CoinbaseAdapter.has_pair(from, to)) {
return callback(`Pair ${from}/${to} is not supported by this adapter.`, null);
}

var pair = [from,to].join('-').toUpperCase(),
ticker_url = `https://api.exchange.coinbase.com/products/${pair}/ticker`;
request(ticker_url, function(error,response,body) {
if(error || response.statusCode !== 200) {
return callback(true,null);
}
try {
let ticker_data = JSON.parse(body);
if(!ticker_data || !ticker_data.price) {
return callback(true,null);
}
return callback(false, ticker_data.price)
} catch {
return callback(true, null)
}
});
},
}

module.exports = CoinbaseAdapter;
37 changes: 37 additions & 0 deletions lib/adapters/GateIOAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
var request = require('request'),
BaseAdapter = require('./base');

var GateIOAdapter = {
name: 'GateIO',
code: 'gateio',
provides: [
['hive','usdt']
],

has_pair: (from, to) => BaseAdapter.has_pair_ext(from, to, GateIOAdapter.provides),

get_pair: function(from,to,callback) {
if (!GateIOAdapter.has_pair(from, to)) {
return callback(`Pair ${from}/${to} is not supported by this adapter.`, null);
}

var pair = [from,to].join('_'),
ticker_url = `https://api.gateio.ws/api/v4/spot/tickers?currency_pair=${pair}`;
request(ticker_url, function(error,response,body) {
if(error || response.statusCode !== 200) {
return callback(true,null);
}
try {
let ticker_data = JSON.parse(body);
if(!ticker_data || ticker_data.length === 0 || !ticker_data[0].last) {
return callback(true,null);
}
return callback(false, ticker_data[0].last)
} catch {
return callback(true, null)
}
});
},
}

module.exports = GateIOAdapter;
3 changes: 1 addition & 2 deletions lib/adapters/HuobiAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ var HuobiAdapter = {
name: 'Huobi',
code: 'huobi',
provides: [
['hive','btc'],
['btc', 'usdt']
['hive','usdt']
],
has_pair: (from, to) => BaseAdapter.has_pair_ext(from, to, HuobiAdapter.provides),

Expand Down
1 change: 0 additions & 1 deletion lib/adapters/IonomyAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ var IonomyAdapter = {
ticker_url = `https://ionomy.com/api/v1/public/market-summary?market=${pair}`;
request(ticker_url, function(error,response,body) {
if(error || response.statusCode != 200) {
console.error('Invalid response code or server error:',error,response.statusCode);
return callback(true,null);
}
var ticker_data = JSON.parse(body);
Expand Down
1 change: 0 additions & 1 deletion lib/adapters/KrakenAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ var KrakenAdapter = {
ticker_url = `https://api.kraken.com/0/public/Ticker?pair=${pair}`;
request(ticker_url, function(error,response,body) {
if(error || response.statusCode != 200) {
console.error('Invalid response code or server error:',error,response.statusCode);
return callback(true,null);
}
var ticker_data = JSON.parse(body);
Expand Down
38 changes: 38 additions & 0 deletions lib/adapters/MEXCAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
var request = require('request'),
BaseAdapter = require('./base');

var MEXCAdapter = {
name: 'MEXC',
code: 'mexc',
provides: [
['hive','usdt'],
['hive','btc']
],

has_pair: (from, to) => BaseAdapter.has_pair_ext(from, to, MEXCAdapter.provides),

get_pair: function(from,to,callback) {
if (!MEXCAdapter.has_pair(from, to)) {
return callback(`Pair ${from}/${to} is not supported by this adapter.`, null);
}

var pair = [from,to].join('').toUpperCase(),
ticker_url = `https://api.mexc.com/api/v3/ticker/price?symbol=${pair}`;
request(ticker_url, function(error,response,body) {
if(error || response.statusCode !== 200) {
return callback(true,null);
}
try {
let ticker_data = JSON.parse(body);
if(!ticker_data.price) {
return callback(true,null);
}
return callback(false, ticker_data.price)
} catch {
return callback(true, null)
}
});
},
}

module.exports = MEXCAdapter;
38 changes: 38 additions & 0 deletions lib/adapters/ProbitAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
var request = require('request'),
BaseAdapter = require('./base');

var ProbitAdapter = {
name: 'Probit',
code: 'probit',
provides: [
['hive','usdt'],
['hive','btc']
],

has_pair: (from, to) => BaseAdapter.has_pair_ext(from, to, ProbitAdapter.provides),

get_pair: function(from,to,callback) {
if (!ProbitAdapter.has_pair(from, to)) {
return callback(`Pair ${from}/${to} is not supported by this adapter.`, null);
}

var pair = [from,to].join('-').toUpperCase(),
ticker_url = `https://api.probit.com/api/exchange/v1/ticker?market_ids=${pair}`;
request(ticker_url, function(error,response,body) {
if(error || response.statusCode !== 200) {
return callback(true,null);
}
try {
let ticker_data = JSON.parse(body);
if(!ticker_data.data || ticker_data.data.length === 0 || !ticker_data.data[0].last) {
return callback(true,null);
}
return callback(false, ticker_data.data[0].last)
} catch {
return callback(true, null)
}
});
},
}

module.exports = ProbitAdapter;
16 changes: 13 additions & 3 deletions lib/exchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ var PoloniexAdapter = require('./adapters/PoloniexAdapter'),
IonomyAdapter = require('./adapters/IonomyAdapter'),
KrakenAdapter = require('./adapters/KrakenAdapter'),
BinanceAdapter = require('./adapters/BinanceAdapter'),
HuobiAdapter = require('./adapters/HuobiAdapter')
HuobiAdapter = require('./adapters/HuobiAdapter'),
MEXCAdapter = require('./adapters/MEXCAdapter'),
ProbitAdapter = require('./adapters/ProbitAdapter'),
GateIOAdapter = require('./adapters/GateIOAdapter'),
CoinbaseAdapter = require('./adapters/CoinbaseAdapter'),
BitfinexAdapter = require('./adapters/BitfinexAdapter')
;

var available_adapters = [
Expand All @@ -29,7 +34,12 @@ var available_adapters = [
BinanceAdapter,
KrakenAdapter,
IonomyAdapter,
HuobiAdapter
HuobiAdapter,
MEXCAdapter,
ProbitAdapter,
GateIOAdapter,
CoinbaseAdapter,
BitfinexAdapter
];


Expand Down Expand Up @@ -58,7 +68,7 @@ var _AdapterList = {};

// What coins should we proxy through if we can't find
// a certain pair? Prevents needless proxying
var _Proxies = ['btc','usd', 'usdt'];
var _Proxies = ['usdt','btc', 'usd'];

/**
* Allows a pair such as USD_BTC to work for BTC_USD
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hivefeed-js",
"version": "4.3.3",
"version": "4.4.0",
"description": "Hive Price Feed in JS with automatic retry for down nodes",
"repository": "https://github.com/someguy123/hivefeed-js",
"main": "app.js",
Expand Down

0 comments on commit 3b26760

Please sign in to comment.