示例#1
0
 public function actionStatus()
 {
     if (!LimitRequest('api-status', 10)) {
         return;
     }
     echo "{";
     foreach (yaamp_get_algos() as $i => $algo) {
         if ($i) {
             echo ", ";
         }
         $coins = controller()->memcache->get_database_count_ex("api_status_coins-{$algo}", 'db_coins', "enable and visible and auto_ready and algo=:algo", array(':algo' => $algo));
         $hashrate = controller()->memcache->get_database_scalar("api_status_hashrate-{$algo}", "select hashrate from hashrate where algo=:algo order by time desc limit 1", array(':algo' => $algo));
         $price = controller()->memcache->get_database_scalar("api_status_price-{$algo}", "select price from hashrate where algo=:algo order by time desc limit 1", array(':algo' => $algo));
         $price = bitcoinvaluetoa(take_yaamp_fee($price / 1000, $algo));
         $rental = controller()->memcache->get_database_scalar("api_status_price-{$algo}", "select rent from hashrate where algo=:algo order by time desc limit 1", array(':algo' => $algo));
         $rental = bitcoinvaluetoa($rental);
         $t = time() - 24 * 60 * 60;
         $avgprice = controller()->memcache->get_database_scalar("api_status_avgprice-{$algo}", "select avg(price) from hashrate where algo=:algo and time>{$t}", array(':algo' => $algo));
         $avgprice = bitcoinvaluetoa(take_yaamp_fee($avgprice / 1000, $algo));
         $total1 = controller()->memcache->get_database_scalar("api_status_total-{$algo}", "select sum(amount*price) from blocks where category!='orphan' and time>{$t} and algo=:algo", array(':algo' => $algo));
         $hashrate1 = controller()->memcache->get_database_scalar("api_status_avghashrate-{$algo}", "select avg(hashrate) from hashrate where time>{$t} and algo=:algo", array(':algo' => $algo));
         //			$btcmhday1 = $hashrate1 != 0? bitcoinvaluetoa($total1 / $hashrate1 * 1000000): '0.00000000';
         if ($algo == 'sha256') {
             $btcmhday1 = $hashrate1 != 0 ? mbitcoinvaluetoa($total1 / $hashrate1 * 1000000 * 1000000) : '0';
         } else {
             $btcmhday1 = $hashrate1 != 0 ? mbitcoinvaluetoa($total1 / $hashrate1 * 1000000 * 1000) : '0';
         }
         $fees = yaamp_fee($algo);
         $port = getAlgoPort($algo);
         if ($port == '-') {
             $port = 0;
         }
         echo "\"{$algo}\": ";
         echo "{";
         echo "\"name\": \"{$algo}\", ";
         echo "\"port\": {$port}, ";
         echo "\"coins\": {$coins}, ";
         echo "\"fees\": {$fees}, ";
         echo "\"hashrate\": {$hashrate}, ";
         echo "\"estimate_current\": {$price}, ";
         echo "\"estimate_last24h\": {$avgprice}, ";
         echo "\"actual_last24h\": {$btcmhday1}, ";
         echo "\"rental_current\": {$rental}";
         echo "}";
     }
     echo "}";
 }
示例#2
0
function BackendUpdateServices()
{
    //	debuglog(__FUNCTION__);
    $table = array(0 => 'scrypt', 1 => 'sha256', 2 => 'scryptn', 3 => 'x11', 4 => 'x13', 5 => 'keccak', 6 => 'x15', 7 => 'nist5', 8 => 'neoscrypt', 9 => 'lyra2', 10 => 'whirlx', 11 => 'qubit', 12 => 'quark', 111 => 'c11');
    $res = fetch_url('https://www.nicehash.com/api?method=stats.global.current');
    if (!$res) {
        return;
    }
    $a = json_decode($res);
    if (!$a || !isset($a->result)) {
        return;
    }
    foreach ($a->result->stats as $stat) {
        if ($stat->price <= 0) {
            continue;
        }
        if (!isset($table[$stat->algo])) {
            continue;
        }
        $algo = $table[$stat->algo];
        $service = getdbosql('db_services', "name='Nicehash' and algo=:algo", array(':algo' => $algo));
        if (!$service) {
            $service = new db_services();
            $service->name = 'Nicehash';
            $service->algo = $algo;
        }
        $service->price = $stat->price / 1000;
        $service->speed = $stat->speed * 1000000000;
        $service->save();
        $list = getdbolist('db_jobs', "percent>0 and algo=:algo and (host='stratum.westhash.com' or host='stratum.nicehash.com')", array(':algo' => $algo));
        foreach ($list as $job) {
            $job->price = round($service->price * 1000 * (100 - $job->percent) / 100, 2);
            $job->save();
        }
    }
    $list = getdbolist('db_renters', "custom_address is not null and custom_server is not null");
    foreach ($list as $renter) {
        $res = fetch_url("https://{$renter->custom_server}/api?method=stats.provider&addr={$renter->custom_address}");
        if (!$res) {
            continue;
        }
        $renter->custom_balance = 0;
        $renter->custom_accept = 0;
        $renter->custom_reject = 0;
        $a = json_decode($res);
        foreach ($a->result->stats as $stat) {
            if (!isset($table[$stat->algo])) {
                continue;
            }
            $algo = $table[$stat->algo];
            $renter->custom_balance += $stat->balance;
            $renter->custom_accept += $stat->accepted_speed * 1000000000;
            $renter->custom_reject += $stat->rejected_speed * 1000000000;
        }
        $renter->save();
    }
    ///////////////////////////////////////////////////////////////////////////
    // renting from nicehash
    if (!YAAMP_PRODUCTION) {
        return;
    }
    return;
    $apikey = 'c9534a11-0e4e-4d00-be64-a00e34cd927a';
    $apiid = '7215';
    $deposit = '1C23KmLeCaQSLLyKVykHEUse1R7jRDv9j9';
    $amount = '0.01';
    $res = fetch_url("https://www.nicehash.com/api?method=balance&id={$apiid}&key={$apikey}");
    $a = json_decode($res);
    $balance = $a->result->balance_confirmed;
    foreach ($table as $i => $algo) {
        $nicehash = getdbosql('db_nicehash', "algo=:algo", array(':algo' => $algo));
        if (!$nicehash) {
            $nicehash = new db_nicehash();
            $nicehash->active = false;
            $nicehash->algo = $algo;
        }
        if (!$nicehash->active) {
            if ($nicehash->orderid) {
                $res = fetch_url("https://www.nicehash.com/api?method=orders.remove&id={$apiid}&key={$apikey}&algo={$i}&order={$nicehash->orderid}");
                debuglog($res);
                $nicehash->orderid = null;
            }
            $nicehash->btc = null;
            $nicehash->price = null;
            $nicehash->speed = null;
            $nicehash->last_decrease = null;
            $nicehash->save();
            continue;
        }
        $price = dboscalar("select price from hashrate where algo=:algo order by time desc limit 1", array(':algo' => $algo));
        $minprice = $price * 0.5;
        $setprice = $price * 0.7;
        $maxprice = $price * 0.9;
        $cancelprice = $price * 1.1;
        $res = fetch_url("https://www.nicehash.com/api?method=orders.get&my&id={$apiid}&key={$apikey}&algo={$i}");
        if (!$res) {
            break;
        }
        $a = json_decode($res);
        if (count($a->result->orders) == 0) {
            if ($balance < $amount) {
                continue;
            }
            $port = getAlgoPort($algo);
            $res = fetch_url("https://www.nicehash.com/api?method=orders.create&id={$apiid}&key={$apikey}&algo={$i}&amount={$amount}&price={$setprice}&limit=0&pool_host=yaamp.com&pool_port={$port}&pool_user={$deposit}&pool_pass=xx");
            debuglog($res);
            $nicehash->last_decrease = time();
            $nicehash->save();
            continue;
        }
        $order = $a->result->orders[0];
        debuglog("{$algo} {$order->price} {$minprice} {$setprice} {$maxprice} {$cancelprice}");
        $nicehash->orderid = $order->id;
        $nicehash->btc = $order->btc_avail;
        $nicehash->workers = $order->workers;
        $nicehash->price = $order->price;
        $nicehash->speed = $order->limit_speed;
        $nicehash->accepted = $order->accepted_speed;
        $nicehash->rejected = $order->rejected_speed;
        if ($order->price > $cancelprice && $order->workers > 0) {
            debuglog("* cancel order {$algo}");
            $res = fetch_url("https://www.nicehash.com/api?method=orders.remove&id={$apiid}&key={$apikey}&algo={$i}&order={$order->id}");
            debuglog($res);
        } else {
            if ($order->price > $maxprice && $order->limit_speed == 0) {
                debuglog("* decrease speed {$algo}");
                $res = fetch_url("https://www.nicehash.com/api?method=orders.set.limit&id={$apiid}&key={$apikey}&algo={$i}&order={$order->id}&limit=0.05");
                debuglog($res);
            } else {
                if ($order->price > $maxprice && $nicehash->last_decrease + 10 * 60 < time()) {
                    debuglog("* decrease price {$algo}");
                    $res = fetch_url("https://www.nicehash.com/api?method=orders.set.price.decrease&id={$apiid}&key={$apikey}&algo={$i}&order={$order->id}");
                    debuglog($res);
                    $nicehash->last_decrease = time();
                } else {
                    if ($order->price < $minprice && $order->workers <= 0) {
                        debuglog("* increase price {$algo}");
                        $res = fetch_url("https://www.nicehash.com/api?method=orders.set.price&id={$apiid}&key={$apikey}&algo={$i}&order={$order->id}&price={$setprice}");
                        debuglog($res);
                    } else {
                        if ($order->price < $maxprice && $order->limit_speed == 0.05) {
                            debuglog("* increase speed {$algo}");
                            $res = fetch_url("https://www.nicehash.com/api?method=orders.set.limit&id={$apiid}&key={$apikey}&algo={$i}&order={$order->id}&limit=0");
                            debuglog($res);
                        }
                    }
                }
            }
        }
        $nicehash->save();
    }
}
示例#3
0
 $price = controller()->memcache->get_database_scalar("current_price-{$algo}", "select price from hashrate where algo=:algo order by time desc limit 1", array(':algo' => $algo));
 $price = $price ? mbitcoinvaluetoa(take_yaamp_fee($price, $algo)) : '-';
 $norm = mbitcoinvaluetoa($norm);
 $t = time() - 24 * 60 * 60;
 $avgprice = controller()->memcache->get_database_scalar("current_avgprice-{$algo}", "select avg(price) from hashrate where algo=:algo and time>{$t}", array(':algo' => $algo));
 $avgprice = $avgprice ? mbitcoinvaluetoa(take_yaamp_fee($avgprice, $algo)) : '-';
 $total1 = controller()->memcache->get_database_scalar("current_total-{$algo}", "select sum(amount*price) from blocks where category!='orphan' and time>{$t} and algo=:algo", array(':algo' => $algo));
 $hashrate1 = controller()->memcache->get_database_scalar("current_hashrate1-{$algo}", "select avg(hashrate) from hashrate where time>{$t} and algo=:algo", array(':algo' => $algo));
 //	$btcmhday1 = $hashrate1 != 0? mbitcoinvaluetoa($total1 / $hashrate1 * 1000000 * 1000): '-';
 if ($algo == 'sha256') {
     $btcmhday1 = $hashrate1 != 0 ? mbitcoinvaluetoa($total1 / $hashrate1 * 1000000 * 1000000) : '';
 } else {
     $btcmhday1 = $hashrate1 != 0 ? mbitcoinvaluetoa($total1 / $hashrate1 * 1000000 * 1000) : '';
 }
 $fees = yaamp_fee($algo);
 $port = getAlgoPort($algo);
 if ($defaultalgo == $algo) {
     echo "<tr style='cursor: pointer; background-color: #e0d3e8;' onclick='javascript:select_algo(\"{$algo}\")'>";
 } else {
     echo "<tr style='cursor: pointer' class='ssrow' onclick='javascript:select_algo(\"{$algo}\")'>";
 }
 echo "<td><b>{$algo}</b></td>";
 echo "<td align=right style='font-size: .8em;'>{$port}</td>";
 echo "<td align=right style='font-size: .8em;'>{$coins}</td>";
 echo "<td align=right style='font-size: .8em;'>{$count}</td>";
 echo "<td align=right style='font-size: .8em;'>{$hashrate}</td>";
 echo "<td align=right style='font-size: .8em;'>{$fees}%</td>";
 if ($algo == $best_algo) {
     echo "<td align=right style='font-size: .8em;' title='normalized {$norm}'><b>{$price}*</b></td>";
 } else {
     if ($norm > 0) {