Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const request = require('request');
- const _ = require('underscore');
- const moment = require('moment');
- const util = require('util');
- const get = util.promisify(request.get);
- const CURRENCY_CODE = 'USD';
- const ALGORITHM_MAP = { 20 : 'DaggerHashimoto', 21 : 'Decred' };
- const WALLET_ADDR = '1G73qGRBHqG5SjxCB9gg1jzPghy51ViTgP';
- function parseInput() {
- const input = {};
- const minutes = _.isUndefined(process.argv[2]) ? 60 : parseInt(process.argv[2], 10);
- const endTime = _.isUndefined(process.argv[3]) ? moment().unix() : moment().unix() - (parseInt(process.argv[3], 10) * 60);
- input.end = endTime / 300;
- input.start = (moment().unix() - (minutes * 60)) / 300;
- input.minutes = minutes;
- return input;
- }
- async function getConversion() {
- const response = await get('https://blockchain.info/ticker');
- const body = JSON.parse(response.body)
- return body[CURRENCY_CODE].last
- }
- async function getNiceHashData() {
- const uri = 'http://api.nicehash.com/api?method=stats.provider.ex&addr=' + WALLET_ADDR;
- const response = await get(uri);
- return JSON.parse(response.body);
- }
- async function parseData(input) {
- let total = 0;
- const conversion = await getConversion();
- const data = await getNiceHashData();
- const result = data.result;
- process.stdout.write('\033c');
- console.log('Getting average over the last %d minutes\n', input.minutes);
- _.each(result.past, function(algo) {
- const algorithm = _.isUndefined(ALGORITHM_MAP[algo.algo]) ? algo.algo : ALGORITHM_MAP[algo.algo];
- console.log('Algorithm: %s', algorithm);
- const applicable = _.filter(algo.data, function(report) {
- return report[0] > input.start && report[0] < input.end && !_.isUndefined(report[1].a);
- });
- const idleTime = _.filter(algo.data, function(report) {
- return report[0] > input.start && report[0] < input.end && _.isUndefined(report[1].a);
- }).length * 5;
- const sum = _.reduce(applicable, function(aggr,report) {
- return aggr + parseFloat(report[1].a);
- }, 0);
- const average = sum / applicable.length;
- const extraInfo = _.find(result.current, function(miner) {
- return miner.algo === algo.algo;
- });
- const profitability = average * parseFloat(extraInfo.profitability);
- const suffix = extraInfo.suffix;
- total += profitability;
- console.log('Average hashrate: %d %s', average.toFixed(3), suffix);
- console.log('Profitability: %d mBTC/Day', (profitability * 1000).toFixed(2));
- console.log('Profitability: %d %s/Day', (profitability * conversion).toFixed(2), CURRENCY_CODE);
- console.log('Idle time: %d\n', idleTime);
- });
- console.log('Total profitability: %d mBTC/Day', (total * 1000).toFixed(2));
- console.log('Total profitability: %d %s/Day', (total * conversion).toFixed(2), CURRENCY_CODE);
- }
- async function start() {
- const input = parseInput();
- parseData(input);
- setInterval(() => { parseData(input); }, 11000);
- }
- start();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement