Add TradeSatoshi Support

This commit is contained in:
joeuhren
2020-11-20 13:37:25 -07:00
parent e500a40192
commit dc683a8970
5 changed files with 203 additions and 1 deletions
+7 -1
View File
@@ -16,7 +16,8 @@ var mongoose = require('mongoose')
, stex = require('./markets/stex')
, crex = require('./markets/crex')
, coindesk = require('./apis/coindesk')
, altmarkets = require('./markets/altmarkets');
, altmarkets = require('./markets/altmarkets')
, tradesatoshi = require('./markets/tradesatoshi');
function find_address(hash, caseSensitive, cb) {
if (caseSensitive) {
@@ -244,6 +245,11 @@ function get_market_data(market, cb) {
return cb(err, obj);
});
break;
case 'tradesatoshi':
tradesatoshi.get_data(settings.markets.coin, settings.markets.exchange, function (err, obj){
return cb(err, obj);
});
break;
default:
return cb(null);
}
+1
View File
@@ -148,6 +148,7 @@ exports.bleutrade = "Bleutrade",
exports.yobit = "Yobit",
exports.stex = "Stex",
exports.crex = "Crex24",
exports.tradesatoshi = "TradeSatoshi",
exports.reloadLocale = function reloadLocale(locale) {
// Discover where the locale file lives
+81
View File
@@ -0,0 +1,81 @@
var request = require('request');
var base_url = 'https://tradesatoshi.com/api/public/';
function get_summary(coin, exchange, cb) {
var summary = {};
request({ uri: base_url + 'getmarketsummary?market=' + coin + '_' + exchange, json: true }, function (error, response, body) {
if (error) {
return cb(error, null);
} else {
summary['bid'] = body.result['bid'];
summary['ask'] = body.result['ask'];
summary['volume'] = body.result['volume'];
summary['high'] = body.result['high'];
summary['low'] = body.result['low'];
summary['last'] = body.result['last'];
summary['change'] = body.result['change'];
return cb(null, summary);
}
});
}
function get_trades(coin, exchange, cb) {
var req_url = base_url + 'getmarkethistory?market=' + coin + '_' + exchange + '&count=1000';
request({uri: req_url, json: true}, function (error, response, body) {
if (body.success == true) {
return cb (null, body['result']);
} else {
return cb(body.message, null);
}
});
}
function get_orders(coin, exchange, cb) {
var req_url = base_url + 'getorderbook?market=' + coin + '_' + exchange + '&type=both&depth=1000';
request({ uri: req_url, json: true }, function (error, response, body) {
if (body.success) {
var orders = body.result;
var buys = [];
var sells = [];
if (orders['buy'].length > 0){
for (var i = 0; i < orders['buy'].length; i++) {
var order = {
amount: parseFloat(orders.buy[i].quantity).toFixed(8),
price: parseFloat(orders.buy[i].rate).toFixed(8),
total: (parseFloat(orders.buy[i].quantity).toFixed(8) * parseFloat(orders.buy[i].rate)).toFixed(8)
}
buys.push(order);
}
}
if (orders['sell'].length > 0) {
for (var x = 0; x < orders['sell'].length; x++) {
var order = {
amount: parseFloat(orders.sell[x].quantity).toFixed(8),
price: parseFloat(orders.sell[x].rate).toFixed(8),
total: (parseFloat(orders.sell[x].quantity).toFixed(8) * parseFloat(orders.sell[x].rate)).toFixed(8)
}
sells.push(order);
}
}
return cb(null, buys, sells);
} else {
return cb(body.Message, [], [])
}
});
}
module.exports = {
get_data: function(coin, exchange, cb) {
var error = null;
get_orders(coin, exchange, function(err, buys, sells) {
if (err) { error = err; }
get_trades(coin, exchange, function(err, trades) {
if (err) { error = err; }
get_summary(coin, exchange, function(err, stats) {
if (err) { error = err; }
return cb(error, {buys: buys, sells: sells, chartdata: [], trades: trades, stats: stats});
});
});
});
}
};