Last active
August 1, 2018 13:16
-
-
Save mjoyce91/8e799d0e206fcdafbcd4bb8d0e4a9029 to your computer and use it in GitHub Desktop.
Cryptocurrency Mining Profitability Helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Set the coins you mine: | |
// name: coin name as it appears in whattomine API response | |
// command: full path of the executable you want to run for that coin | |
// args: array of args to be passed to the command | |
const config = [ | |
{ | |
name: 'Electroneum', | |
command: 'C:\\Users\\SomePath\\xmr-stak-cpu-win64-electroneum\\xmr-stak-cpu\\xmr-stak-cpu.exe', | |
args: ['C:\\Users\\Mike\\DownloadsSomePath\\xmr-stak-cpu-win64-electroneum\\xmr-stak-cpu\\config.txt'], | |
}, | |
{ | |
name: 'Sumokoin', | |
command: 'C:\\Users\\SomePath\\xmr-stak-cpu-win64-sumo\\xmr-stak-cpu\\xmr-stak-cpu.exe', | |
args: ['C:\\Users\\SomePath\\xmr-stak-cpu-win64-sumo\\xmr-stak-cpu\\config.txt'], | |
} | |
]; | |
const request = require('request'); | |
const spawn = require('child_process').spawn; | |
// set your default coin | |
let currentCoin = config[0]; | |
// create the child process | |
let child = spawn(currentCoin.command, currentCoin.args); | |
child.stdout.on('data', function (data) { | |
console.log('stdout: ' + data); | |
}); | |
child.stderr.on('data', function (data) { | |
console.log('stderr: ' + data); | |
}); | |
child.on('close', function (code) { | |
console.log('child process exited with code ' + code); | |
}); | |
function checkProfitability() { | |
setTimeout(function () { | |
request.get('http://whattomine.com/coins.json', (error, response, body) => { | |
if (body) { | |
// response | |
let json = JSON.parse(body); | |
// coins | |
let coins = json.coins; | |
// match user defined coins | |
config.forEach((coin, i) => { | |
// set profitability | |
config[i].p = coins[coin.name].profitability; | |
}); | |
// sort coins by profitability | |
const sortedCoins = config.slice().sort(function(a,b) {return (a.p < b.p) ? 1 : ((b.p < a.p) ? -1 : 0);} ); | |
// See if we should change coins based on profitability. | |
if (sortedCoins[0].name !== currentCoin.name) { | |
console.log(`Profitability changed. Switching from ${currentCoin.name} to ${sortedCoins[0].name}`); | |
child.kill('SIGINT'); | |
currentCoin = sortedCoins[0]; | |
child = spawn(currentCoin.command, currentCoin.args); | |
} else { | |
console.log(`Sticking with ${currentCoin.name}`); | |
} | |
console.log(sortedCoins); | |
checkProfitability(); | |
} | |
if (error) { | |
console.log('Error fetching profitability') | |
checkProfitability(); | |
} | |
}); | |
}, 60000); | |
} | |
checkProfitability(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment