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": {
|
||||
"enabled": false,
|
||||
"updateInterval": 60,
|
||||
"depth": 0.80
|
||||
"enabled": false,
|
||||
"updateInterval": 600,
|
||||
"depth": 0.90,
|
||||
"usePoloniex": true,
|
||||
"useCryptsy": true,
|
||||
"useMintpal": true
|
||||
},
|
||||
|
||||
"redisBlockNotifyListener": {
|
||||
|
|
|
@ -8,19 +8,19 @@ module.exports = function() {
|
|||
|
||||
// Constants
|
||||
var version = '0.1.0',
|
||||
PUBLIC_API_URL = 'http://pubapi.cryptsy.com/api.php',
|
||||
PRIVATE_API_URL = 'https://api.cryptsy.com/api',
|
||||
PUBLIC_API_URL = 'https://api.mintpal.com/v2/market',
|
||||
PRIVATE_API_URL = 'https://api.mintpal.com/v2/market',
|
||||
USER_AGENT = 'nomp/node-open-mining-portal'
|
||||
|
||||
// Constructor
|
||||
function Cryptsy(key, secret){
|
||||
function Mintpal(key, secret){
|
||||
// Generate headers signed by this user's key and secret.
|
||||
// The secret is encapsulated and never exposed
|
||||
this._getPrivateHeaders = function(parameters){
|
||||
var paramString, signature;
|
||||
|
||||
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`
|
||||
|
@ -38,7 +38,7 @@ module.exports = function() {
|
|||
}
|
||||
|
||||
// If a site uses non-trusted SSL certificates, set this value to false
|
||||
Cryptsy.STRICT_SSL = true;
|
||||
Mintpal.STRICT_SSL = true;
|
||||
|
||||
// Helper methods
|
||||
function joinCurrencies(currencyA, currencyB){
|
||||
|
@ -46,8 +46,8 @@ module.exports = function() {
|
|||
}
|
||||
|
||||
// Prototype
|
||||
Cryptsy.prototype = {
|
||||
constructor: Cryptsy,
|
||||
Mintpal.prototype = {
|
||||
constructor: Mintpal,
|
||||
|
||||
// Make an API request
|
||||
_request: function(options, callback){
|
||||
|
@ -57,7 +57,7 @@ module.exports = function() {
|
|||
|
||||
options.headers['User-Agent'] = USER_AGENT;
|
||||
options.json = true;
|
||||
options.strictSSL = Cryptsy.STRICT_SSL;
|
||||
options.strictSSL = Mintpal.STRICT_SSL;
|
||||
|
||||
request(options, function(err, response, body) {
|
||||
callback(err, body);
|
||||
|
@ -99,11 +99,13 @@ module.exports = function() {
|
|||
// PUBLIC METHODS
|
||||
|
||||
getTicker: function(callback){
|
||||
var parameters = {
|
||||
method: 'marketdatav2'
|
||||
};
|
||||
var options = {
|
||||
method: 'GET',
|
||||
url: PUBLIC_API_URL + '/summary',
|
||||
qs: null
|
||||
};
|
||||
|
||||
return this._public(parameters, callback);
|
||||
return this._request(options, 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 Poloniex = require('./apiPoloniex.js');
|
||||
var Mintpal = require('./apiMintpal.js');
|
||||
var Stratum = require('stratum-pool');
|
||||
|
||||
module.exports = function(logger){
|
||||
|
@ -64,6 +65,10 @@ module.exports = function(logger){
|
|||
// 'API_KEY',
|
||||
// 'API_SECRET'
|
||||
);
|
||||
var mintpalApi = new Mintpal(
|
||||
// 'API_KEY',
|
||||
// 'API_SECRET'
|
||||
);
|
||||
|
||||
//
|
||||
// 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){
|
||||
var daemonTasks = [];
|
||||
Object.keys(profitStatus).forEach(function(algo){
|
||||
|
@ -320,11 +369,19 @@ module.exports = function(logger){
|
|||
var checkProfitability = function(){
|
||||
logger.debug(logSystem, 'Check', 'Running mining profitability check.');
|
||||
|
||||
async.parallel([
|
||||
_this.getProfitDataPoloniex,
|
||||
_this.getProfitDataCryptsy,
|
||||
_this.getCoindDaemonInfo
|
||||
], function(err){
|
||||
profitabilityTasks = [];
|
||||
if (portalConfig.profitSwitch.usePoloniex)
|
||||
profitabilityTasks.push(_this.getProfitDataPoloniex);
|
||||
|
||||
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){
|
||||
logger.error(logSystem, 'Check', 'Error while checking profitability: ' + err);
|
||||
return;
|
||||
|
|
Loading…
Reference in New Issue