import * as WhatToMine from "." ; import { logger } from "../../logger" ; import { request } from "../../utils" ; interface IBaseCoin { id : number ; tag : string ; algorithm : string ; lagging : boolean ; status : string ; } interface IAPICalculator extends IBaseCoin { listed : boolean ; testing : boolean ; name : string ; } interface IAPICalculators { coins : { [ s ] : IAPICalculator ; } ; } interface IAPICoin extends IBaseCoin { name : string ; block_time : string ; block_reward : number ; block_reward24 : number ; block_reward3 : number ; block_reward7 : number ; last_block : number ; difficulty : number ; difficulty24 : number ; difficulty3 : number ; difficulty7 : number ; nethash : number ; exchange_rate : number ; exchange_rate24 : number ; exchange_rate3 : number ; exchange_rate7 : number ; exchange_rate_vol : number ; exchange_rate_curr : string ; market_cap : string ; pool_fee : string ; estimated_rewards : string ; btc_revenue : string ; btc_revenue24 : string ; revenue : string ; cost : string ; profit : string ; timestamp : number ; } interface IAPICoins { coins : { [ s ] : IAPICoin ; } ; } export interface IRevenueResponse { revenue : number ; timestamp : number ; } interface IGetMassRevenueCacheAlgo { algorithm : WhatToMine . Algorithm ; hashrate : number ; } /**
 * Get the raw calculator list JSON
 * https://whattomine.com/calculators.json
 */ export async function getRawCalculators ( ) { const raw = await request ( "https://whattomine.com/calculators.json" ) ; const data = JSON . parse ( raw . data ) as IAPICalculators ; return data ; } param id param hashrate export async function getRawRevenue ( id , hashrate ) { const raw = await request ( `https://whattomine.com/coins/${ id }.json?hr=${ hashrate }` ) ; const data = JSON . parse ( raw . data ) as IAPICoin ; return data ; } param algos export async function getRawListedCoins ( algos ) { let url = "http://whattomine.com/coins.json?" ; for ( const algo of algos ) { if ( algo . algorithm . cacheNames === null ) { continue ; } const names = algo . algorithm . cacheNames ; url += `&${ names [ 0 ] }=true&factor[${ names [ 1 ] }_hr]=${ algo . hashrate }` ; } const raw = await request ( url ) ; const data = JSON . parse ( raw . data ) as IAPICoins ; return data ; } param opts export async function getListedCoins ( algos ) { const data = await getRawListedCoins ( algos ) ; const result = [ ] ; for ( const key of Object . keys ( data . coins ) ) { const value = data . coins [ key ] ; if ( value . lagging ) { continue ; } if ( key . startsWith ( "Nicehash" ) ) { continue ; } result [ value . id ] = { timestamp : value . timestamp * 1000 , revenue : + value . btc_revenue24 , } ; } return result ; } export async function getCalculators ( ) { const data = ( await getRawCalculators ( ) ) . coins ; const coins = [ ] ; for ( const key of Object . keys ( data ) ) { const value = data [ key ] ; const logSkip = ( reason ) => { logger . debug ( `WhatToMine.getCalculators(): skipping ${ key } (${ value . id }): ${ reason }` ) ; } ; if ( value . tag === "NICEHASH" ) { logSkip ( "nicehash" ) ; continue ; } if ( value . status !== "Active" ) { logSkip ( "inactive" ) ; continue ; } value . name = key ; coins . push ( value ) ; } return coins ; } export async function getRevenue ( id , hashrate ) { logger . debug ( "WhatToMine.getRevenue(): returning from web for " + id ) ; const data = await getRawRevenue ( id , hashrate ) ; const revenue = Number ( data . btc_revenue ) ; return { timestamp : data . timestamp * 1000 , revenue , } ; }