mirror of https://github.com/BTCPrivate/z-nomp.git
profit data working
This commit is contained in:
parent
9ad11516d2
commit
4469cf546c
|
@ -70,9 +70,12 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
"profitSwitch": {
|
"profitSwitch": {
|
||||||
"enabled": false,
|
"enabled": false,
|
||||||
"updateInterval": 60,
|
"updateInterval": 600,
|
||||||
"depth": 0.80
|
"depth": 0.90,
|
||||||
|
"usePoloniex": true,
|
||||||
|
"useCryptsy": true,
|
||||||
|
"useMintpal": true
|
||||||
},
|
},
|
||||||
|
|
||||||
"redisBlockNotifyListener": {
|
"redisBlockNotifyListener": {
|
||||||
|
|
|
@ -8,19 +8,19 @@ module.exports = function() {
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
var version = '0.1.0',
|
var version = '0.1.0',
|
||||||
PUBLIC_API_URL = 'http://pubapi.cryptsy.com/api.php',
|
PUBLIC_API_URL = 'https://api.mintpal.com/v2/market',
|
||||||
PRIVATE_API_URL = 'https://api.cryptsy.com/api',
|
PRIVATE_API_URL = 'https://api.mintpal.com/v2/market',
|
||||||
USER_AGENT = 'nomp/node-open-mining-portal'
|
USER_AGENT = 'nomp/node-open-mining-portal'
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
function Cryptsy(key, secret){
|
function Mintpal(key, secret){
|
||||||
// Generate headers signed by this user's key and secret.
|
// Generate headers signed by this user's key and secret.
|
||||||
// The secret is encapsulated and never exposed
|
// The secret is encapsulated and never exposed
|
||||||
this._getPrivateHeaders = function(parameters){
|
this._getPrivateHeaders = function(parameters){
|
||||||
var paramString, signature;
|
var paramString, signature;
|
||||||
|
|
||||||
if (!key || !secret){
|
if (!key || !secret){
|
||||||
throw 'Cryptsy: Error. API key and secret required';
|
throw 'Mintpal: Error. API key and secret required';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort parameters alphabetically and convert to `arg1=foo&arg2=bar`
|
// Sort parameters alphabetically and convert to `arg1=foo&arg2=bar`
|
||||||
|
@ -38,7 +38,7 @@ module.exports = function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// If a site uses non-trusted SSL certificates, set this value to false
|
// If a site uses non-trusted SSL certificates, set this value to false
|
||||||
Cryptsy.STRICT_SSL = true;
|
Mintpal.STRICT_SSL = true;
|
||||||
|
|
||||||
// Helper methods
|
// Helper methods
|
||||||
function joinCurrencies(currencyA, currencyB){
|
function joinCurrencies(currencyA, currencyB){
|
||||||
|
@ -46,8 +46,8 @@ module.exports = function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prototype
|
// Prototype
|
||||||
Cryptsy.prototype = {
|
Mintpal.prototype = {
|
||||||
constructor: Cryptsy,
|
constructor: Mintpal,
|
||||||
|
|
||||||
// Make an API request
|
// Make an API request
|
||||||
_request: function(options, callback){
|
_request: function(options, callback){
|
||||||
|
@ -57,7 +57,7 @@ module.exports = function() {
|
||||||
|
|
||||||
options.headers['User-Agent'] = USER_AGENT;
|
options.headers['User-Agent'] = USER_AGENT;
|
||||||
options.json = true;
|
options.json = true;
|
||||||
options.strictSSL = Cryptsy.STRICT_SSL;
|
options.strictSSL = Mintpal.STRICT_SSL;
|
||||||
|
|
||||||
request(options, function(err, response, body) {
|
request(options, function(err, response, body) {
|
||||||
callback(err, body);
|
callback(err, body);
|
||||||
|
@ -99,11 +99,13 @@ module.exports = function() {
|
||||||
// PUBLIC METHODS
|
// PUBLIC METHODS
|
||||||
|
|
||||||
getTicker: function(callback){
|
getTicker: function(callback){
|
||||||
var parameters = {
|
var options = {
|
||||||
method: 'marketdatav2'
|
method: 'GET',
|
||||||
};
|
url: PUBLIC_API_URL + '/summary',
|
||||||
|
qs: null
|
||||||
|
};
|
||||||
|
|
||||||
return this._public(parameters, callback);
|
return this._request(options, callback);
|
||||||
},
|
},
|
||||||
|
|
||||||
getOrderBook: function(currencyA, currencyB, callback){
|
getOrderBook: function(currencyA, currencyB, callback){
|
||||||
|
@ -200,5 +202,5 @@ module.exports = function() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return Cryptsy;
|
return Mintpal;
|
||||||
}();
|
}();
|
||||||
|
|
|
@ -2,6 +2,7 @@ var async = require('async');
|
||||||
|
|
||||||
var Cryptsy = require('./apiCryptsy.js');
|
var Cryptsy = require('./apiCryptsy.js');
|
||||||
var Poloniex = require('./apiPoloniex.js');
|
var Poloniex = require('./apiPoloniex.js');
|
||||||
|
var Mintpal = require('./apiMintpal.js');
|
||||||
var Stratum = require('stratum-pool');
|
var Stratum = require('stratum-pool');
|
||||||
|
|
||||||
module.exports = function(logger){
|
module.exports = function(logger){
|
||||||
|
@ -64,6 +65,10 @@ module.exports = function(logger){
|
||||||
// 'API_KEY',
|
// 'API_KEY',
|
||||||
// 'API_SECRET'
|
// 'API_SECRET'
|
||||||
);
|
);
|
||||||
|
var mintpalApi = new Mintpal(
|
||||||
|
// 'API_KEY',
|
||||||
|
// 'API_SECRET'
|
||||||
|
);
|
||||||
|
|
||||||
//
|
//
|
||||||
// market data collection from Poloniex
|
// market data collection from Poloniex
|
||||||
|
@ -253,6 +258,50 @@ module.exports = function(logger){
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
this.getProfitDataMintpal = function(callback){
|
||||||
|
async.series([
|
||||||
|
function(taskCallback){
|
||||||
|
mintpalApi.getTicker(function(err, response){
|
||||||
|
if (err){
|
||||||
|
taskCallback(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Object.keys(symbolToAlgorithmMap).forEach(function(symbol){
|
||||||
|
response.data.forEach(function(market){
|
||||||
|
var exchangeInfo = profitStatus[symbolToAlgorithmMap[symbol]][symbol].exchangeInfo;
|
||||||
|
if (!exchangeInfo.hasOwnProperty('Mintpal'))
|
||||||
|
exchangeInfo['Mintpal'] = {};
|
||||||
|
|
||||||
|
var marketData = exchangeInfo['Mintpal'];
|
||||||
|
|
||||||
|
if (market.exchange == 'BTC' && market.code == symbol) {
|
||||||
|
if (!marketData.hasOwnProperty('BTC'))
|
||||||
|
marketData['BTC'] = {};
|
||||||
|
|
||||||
|
marketData['BTC'].last = new Number(market.last_price);
|
||||||
|
marketData['BTC'].baseVolume = new Number(market['24hvol']);
|
||||||
|
marketData['BTC'].quoteVolume = new Number(market['24hvol'] / market.last_price);
|
||||||
|
marketData['BTC'].ask = new Number(market.top_ask);
|
||||||
|
marketData['BTC'].bid = new Number(market.top_bid);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
|
taskCallback();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
], function(err){
|
||||||
|
if (err){
|
||||||
|
callback(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
callback(null);
|
||||||
|
});
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
this.getCoindDaemonInfo = function(callback){
|
this.getCoindDaemonInfo = function(callback){
|
||||||
var daemonTasks = [];
|
var daemonTasks = [];
|
||||||
Object.keys(profitStatus).forEach(function(algo){
|
Object.keys(profitStatus).forEach(function(algo){
|
||||||
|
@ -320,11 +369,19 @@ module.exports = function(logger){
|
||||||
var checkProfitability = function(){
|
var checkProfitability = function(){
|
||||||
logger.debug(logSystem, 'Check', 'Running mining profitability check.');
|
logger.debug(logSystem, 'Check', 'Running mining profitability check.');
|
||||||
|
|
||||||
async.parallel([
|
profitabilityTasks = [];
|
||||||
_this.getProfitDataPoloniex,
|
if (portalConfig.profitSwitch.usePoloniex)
|
||||||
_this.getProfitDataCryptsy,
|
profitabilityTasks.push(_this.getProfitDataPoloniex);
|
||||||
_this.getCoindDaemonInfo
|
|
||||||
], function(err){
|
if (portalConfig.profitSwitch.useCryptsy)
|
||||||
|
profitabilityTasks.push(_this.getProfitDataCryptsy);
|
||||||
|
|
||||||
|
if (portalConfig.profitSwitch.useMintpal)
|
||||||
|
profitabilityTasks.push(_this.getProfitDataMintpal);
|
||||||
|
|
||||||
|
profitabilityTasks.push(_this.getCoindDaemonInfo);
|
||||||
|
|
||||||
|
async.parallel(profitabilityTasks, function(err){
|
||||||
if (err){
|
if (err){
|
||||||
logger.error(logSystem, 'Check', 'Error while checking profitability: ' + err);
|
logger.error(logSystem, 'Check', 'Error while checking profitability: ' + err);
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in New Issue