= 1) { $ethsellprice = getETHSellPriceKraken(); sendToDB('ethereumsellprice value='.$ethsellprice); $ethminingearnings = 0; $hashratesum = 0; if($ethsellprice && is_array($ethwallets)) foreach($ethwallets as $ethwallet) { $eth = wei2eth(getETHBalance($ethwallet)); if(!$eth || $eth=='0' || !$ethsellprice) return; $worth = ($eth*$ethsellprice); $worthsum+=$worth; echo "[ETH] $ethwallet: Got: ".money_format('%n', $worth)." ".CURRENCY."\n"; sendToDB('ethereumworth,addr='.$ethwallet.' value='.$worth); sendToDB('ethereumcoins,addr='.$ethwallet.' value='.$eth); $hashratesum += getHashRateNanopool($ethwallet); } $ethminingearnings=calculateETHMiningEarnings($hashratesum,'bitcoins','month'); if(!$ethminingearnings) $ethminingearnings = 0; echo "[ETH] Hashrate: $hashratesum MH/s\n"; sendToDB('ethereumhashrate value='.$hashratesum); if($hashratesum >= 1) { sendToDB('ethereumapproxearnings value='.$ethminingearnings); echo "[ETH] Approx mining earnings: ".money_format('%n', $ethminingearnings)." ".CURRENCY."\n"; } } // Bitcoin stuff starts here if(is_array($btcwallets) && count($btcwallets) >= 1) { $btcsellprice = getBTCSellPriceKraken(); sendToDB('btcsellprice value='.$btcsellprice); if($btcsellprice && is_array($btcwallets)) foreach($btcwallets as $btcwallet) { $btc = satoshi2btc(getBTCBalance($btcwallet)); if(!$btc || $btc=='0' || !$btcsellprice) return; $worth = ($btc*$btcsellprice); $worthsum+=$worth; echo "[BTC] $btcwallet: Got: ".money_format('%n', $worth)." ".CURRENCY."\n"; sendToDB('btcworth,addr='.$btcwallet.' value='.$worth); sendToDB('btccoins,addr='.$btcwallet.' value='.$btc); } } sendToDB('combinedworth value='.$worthsum); echo "[i] Worth of all wallets combined: ".money_format('%n', $worthsum)." ".CURRENCY."\n"; function getETHBalance($address) { $json = json_decode(file_get_contents('https://api.etherscan.io/api?module=account&action=balance&address='.$address.'&tag=latest'),true); return $json['result']; } function bchexdec($hex) { if(strlen($hex) == 1) { return hexdec($hex); } else { $remain = substr($hex, 0, -1); $last = substr($hex, -1); return bcadd(bcmul(16, bchexdec($remain)), hexdec($last)); } } function wei2eth($wei) { return bcdiv($wei,1000000000000000000,18); } function getHashRateNanopool($addr) { $json = json_decode(file_get_contents('https://api.nanopool.org/v1/eth/hashrate/'.$addr),true); return $json['data']; } function calculateETHMiningEarnings($mhs,$currency='dollars',$timespan='month') { $json = json_decode(file_get_contents('https://api.nanopool.org/v1/eth/approximated_earnings/'.$mhs),true); return $json['data'][$timespan][$currency]; } function getETHSellPriceKraken() { $json = json_decode(file_get_contents('https://api.kraken.com/0/public/Ticker?pair=ETH'.CURRENCY),true); return $json['result']['XETHZ'.CURRENCY]['c'][0]; } function sendToDB($data) { //var_dump($data); return; $socket = stream_socket_client("udp://".INFLUX_IP.":".INFLUX_PORT.""); stream_socket_sendto($socket, $data); stream_socket_shutdown($socket, STREAM_SHUT_RDWR); } function satoshi2btc($satoshi) { return bcdiv($satoshi,100000000,8); } function getBTCBalance($addr) { return file_get_contents('https://blockchain.info/de/q/addressbalance/'.$addr.'?confirmations=3'); } function getBTCSellPriceKraken() { //if(CURRENCY=='USD') // $json = json_decode(file_get_contents('https://api.kraken.com/0/public/Ticker?pair=XBTUSD'),true); //else $json = json_decode(file_get_contents('https://api.kraken.com/0/public/Ticker?pair=XBT'.CURRENCY),true); return $json['result']['XXBTZ'.CURRENCY]['c'][0]; }