@ -19,7 +19,7 @@ module.exports = function(logger){
var logSystem = 'Profit' ;
//
//
// build status tracker for collecting coin market information
//
var profitStatus = { } ;
@ -44,7 +44,7 @@ module.exports = function(logger){
} ) ;
//
//
// ensure we have something to switch
//
Object . keys ( profitStatus ) . forEach ( function ( algo ) {
@ -57,12 +57,12 @@ module.exports = function(logger){
}
} ) ;
if ( Object . keys ( profitStatus ) . length == 0 ) {
logger . debug ( logSystem , 'Config' , 'No alternative coins to switch to in current config, switching disabled.' ) ;
logger . info ( logSystem , 'Config' , 'No alternative coins to switch to in current config, switching disabled.' ) ;
return ;
}
//
//
// setup APIs
//
var poloApi = new Poloniex (
@ -83,7 +83,7 @@ module.exports = function(logger){
// 'API_SECRET'
) ;
//
//
// market data collection from Poloniex
//
this . getProfitDataPoloniex = function ( callback ) {
@ -139,12 +139,12 @@ module.exports = function(logger){
var marketData = profitStatus [ symbolToAlgorithmMap [ symbol ] ] [ symbol ] . exchangeInfo [ 'Poloniex' ] ;
if ( marketData . hasOwnProperty ( 'BTC' ) && marketData [ 'BTC' ] . bid > 0 ) {
depthTasks . push ( function ( callback ) {
_ this . getMarketDepthFromPoloniex ( 'BTC' , symbol , marketData [ 'BTC' ] . bid , callback )
_ this . getMarketDepthFromPoloniex ( 'BTC' , symbol , marketData [ 'BTC' ] . bid , callback )
} ) ;
}
if ( marketData . hasOwnProperty ( 'LTC' ) && marketData [ 'LTC' ] . bid > 0 ) {
depthTasks . push ( function ( callback ) {
_ this . getMarketDepthFromPoloniex ( 'LTC' , symbol , marketData [ 'LTC' ] . bid , callback )
_ this . getMarketDepthFromPoloniex ( 'LTC' , symbol , marketData [ 'LTC' ] . bid , callback )
} ) ;
}
} ) ;
@ -168,7 +168,7 @@ module.exports = function(logger){
}
callback ( null ) ;
} ) ;
} ;
this . getMarketDepthFromPoloniex = function ( symbolA , symbolB , coinPrice , callback ) {
poloApi . getOrderBook ( symbolA , symbolB , function ( err , data ) {
@ -199,7 +199,7 @@ module.exports = function(logger){
} ) ;
} ;
this . getProfitDataCryptsy = function ( callback ) {
async . series ( [
function ( taskCallback ) {
@ -285,7 +285,7 @@ module.exports = function(logger){
}
callback ( null ) ;
} ) ;
} ;
@ -339,12 +339,12 @@ module.exports = function(logger){
var marketData = profitStatus [ symbolToAlgorithmMap [ symbol ] ] [ symbol ] . exchangeInfo [ 'Mintpal' ] ;
if ( marketData . hasOwnProperty ( 'BTC' ) && marketData [ 'BTC' ] . bid > 0 ) {
depthTasks . push ( function ( callback ) {
_ this . getMarketDepthFromMintpal ( 'BTC' , symbol , marketData [ 'BTC' ] . bid , callback )
_ this . getMarketDepthFromMintpal ( 'BTC' , symbol , marketData [ 'BTC' ] . bid , callback )
} ) ;
}
if ( marketData . hasOwnProperty ( 'LTC' ) && marketData [ 'LTC' ] . bid > 0 ) {
depthTasks . push ( function ( callback ) {
_ this . getMarketDepthFromMintpal ( 'LTC' , symbol , marketData [ 'LTC' ] . bid , callback )
_ this . getMarketDepthFromMintpal ( 'LTC' , symbol , marketData [ 'LTC' ] . bid , callback )
} ) ;
}
} ) ;
@ -451,12 +451,12 @@ module.exports = function(logger){
var marketData = profitStatus [ symbolToAlgorithmMap [ symbol ] ] [ symbol ] . exchangeInfo [ 'Bittrex' ] ;
if ( marketData . hasOwnProperty ( 'BTC' ) && marketData [ 'BTC' ] . bid > 0 ) {
depthTasks . push ( function ( callback ) {
_ this . getMarketDepthFromBittrex ( 'BTC' , symbol , marketData [ 'BTC' ] . bid , callback )
_ this . getMarketDepthFromBittrex ( 'BTC' , symbol , marketData [ 'BTC' ] . bid , callback )
} ) ;
}
if ( marketData . hasOwnProperty ( 'LTC' ) && marketData [ 'LTC' ] . bid > 0 ) {
depthTasks . push ( function ( callback ) {
_ this . getMarketDepthFromBittrex ( 'LTC' , symbol , marketData [ 'LTC' ] . bid , callback )
_ this . getMarketDepthFromBittrex ( 'LTC' , symbol , marketData [ 'LTC' ] . bid , callback )
} ) ;
}
} ) ;
@ -554,7 +554,7 @@ module.exports = function(logger){
// some shitcoins dont provide target, only bits, so we need to deal with both
var target = response . target ? bignum ( response . target , 16 ) : util . bignumFromBitsHex ( response . bits ) ;
coinStatus . difficulty = parseFloat ( ( diff1 / target . toNumber ( ) ) . toFixed ( 9 ) ) ;
logger . debug ( logSystem , symbol , 'difficulty is ' + coinStatus . difficulty ) ;
logger . info ( logSystem , symbol , 'difficulty is ' + coinStatus . difficulty ) ;
coinStatus . reward = response . coinbasevalue / 100000000 ;
callback ( null ) ;
@ -596,7 +596,7 @@ module.exports = function(logger){
bestCoin = profitStatus [ algo ] [ symbol ] . name ;
}
coinStatus . btcPerMhPerHour = btcPerMhPerHour ;
logger . debug ( logSystem , 'CALC' , 'BTC/' + symbol + ' on ' + exchange + ' with ' + coinStatus . btcPerMhPerHour . toFixed ( 8 ) + ' BTC/day per Mh/s' ) ;
logger . info ( logSystem , 'CALC' , 'BTC/' + symbol + ' on ' + exchange + ' with ' + coinStatus . btcPerMhPerHour . toFixed ( 8 ) + ' BTC/day per Mh/s' ) ;
}
if ( exchangeData . hasOwnProperty ( 'LTC' ) && exchangeData [ 'LTC' ] . hasOwnProperty ( 'weightedBid' ) ) {
var btcPerMhPerHour = ( exchangeData [ 'LTC' ] . weightedBid * coinStatus . coinsPerMhPerHour ) * exchangeData [ 'LTC' ] . ltcToBtc ;
@ -606,12 +606,11 @@ module.exports = function(logger){
bestCoin = profitStatus [ algo ] [ symbol ] . name ;
}
coinStatus . btcPerMhPerHour = btcPerMhPerHour ;
logger . debug ( logSystem , 'CALC' , 'LTC/' + symbol + ' on ' + exchange + ' with ' + coinStatus . btcPerMhPerHour . toFixed ( 8 ) + ' BTC/day per Mh/s' ) ;
logger . info ( logSystem , 'CALC' , 'LTC/' + symbol + ' on ' + exchange + ' with ' + coinStatus . btcPerMhPerHour . toFixed ( 8 ) + ' BTC/day per Mh/s' ) ;
}
} ) ;
} ) ;
logger . debug ( logSystem , 'RESULT' , 'Best coin for ' + algo + ' is ' + bestCoin + ' on ' + bestExchange + ' with ' + bestBtcPerMhPerHour . toFixed ( 8 ) + ' BTC/day per Mh/s' ) ;
logger . info ( logSystem , 'RESULT' , 'Best coin for ' + algo + ' is ' + bestCoin + ' on ' + bestExchange + ' with ' + bestBtcPerMhPerHour . toFixed ( 8 ) + ' BTC/day per Mh/s' ) ;
var client = net . connect ( portalConfig . cliPort , function ( ) {
client . write ( JSON . stringify ( {
@ -631,7 +630,7 @@ module.exports = function(logger){
var checkProfitability = function ( ) {
logger . debug ( logSystem , 'Check' , 'Collecting profitability data.' ) ;
logger . info ( logSystem , 'Check' , 'Collecting profitability data.' ) ;
profitabilityTasks = [ ] ;
if ( portalConfig . profitSwitch . usePoloniex )
@ -649,7 +648,7 @@ module.exports = function(logger){
profitabilityTasks . push ( _ this . getCoindDaemonInfo ) ;
profitabilityTasks . push ( _ this . getMiningRate ) ;
// has to be series
// has to be series
async . series ( profitabilityTasks , function ( err ) {
if ( err ) {
logger . error ( logSystem , 'Check' , 'Error while checking profitability: ' + err ) ;
@ -657,7 +656,7 @@ module.exports = function(logger){
}
//
// TODO offer support for a userConfigurable function for deciding on coin to override the default
//
//
_ this . switchToMostProfitableCoins ( ) ;
} ) ;
} ;