function doPoloniexTrading()
{
    //	debuglog('-------------- doPoloniexTrading()');
    $flushall = rand(0, 4) == 0;
    $poloniex = new poloniex();
    $tickers = $poloniex->get_ticker();
    if (!$tickers) {
        return;
    }
    // upgrade orders
    $coins = getdbolist('db_coins', "enable and id in (select distinct coinid from markets where name='poloniex')");
    foreach ($coins as $coin) {
        if ($coin->dontsell) {
            continue;
        }
        $pair = "BTC_{$coin->symbol}";
        if (!isset($tickers[$pair])) {
            continue;
        }
        $orders = $poloniex->get_open_orders($pair);
        if (!$orders || !isset($orders[0])) {
            dborun("delete from orders where coinid={$coin->id} and market='poloniex'");
            continue;
        }
        foreach ($orders as $order) {
            if (!isset($order['orderNumber'])) {
                debuglog($order);
                continue;
            }
            if ($order['rate'] > $tickers[$pair]['lowestAsk'] + 5.0E-8 || $flushall) {
                //				debuglog("poloniex cancel order for $pair {$order['orderNumber']}");
                $poloniex->cancel_order($pair, $order['orderNumber']);
                $db_order = getdbosql('db_orders', "uuid=:uuid", array(':uuid' => $order['orderNumber']));
                if ($db_order) {
                    $db_order->delete();
                }
                sleep(1);
            } else {
                $db_order = getdbosql('db_orders', "uuid=:uuid", array(':uuid' => $order['orderNumber']));
                if ($db_order) {
                    continue;
                }
                debuglog("poloniex adding order {$coin->symbol}");
                $db_order = new db_orders();
                $db_order->market = 'poloniex';
                $db_order->coinid = $coin->id;
                $db_order->amount = $order['amount'];
                $db_order->price = $order['rate'];
                $db_order->ask = $tickers[$pair]['lowestAsk'];
                $db_order->bid = $tickers[$pair]['highestBid'];
                $db_order->uuid = $order['orderNumber'];
                $db_order->created = time();
                $db_order->save();
            }
        }
        $list = getdbolist('db_orders', "coinid={$coin->id} and market='poloniex'");
        foreach ($list as $db_order) {
            $found = false;
            foreach ($orders as $order) {
                if (!isset($order['orderNumber'])) {
                    debuglog($order);
                    continue;
                }
                if ($order['orderNumber'] == $db_order->uuid) {
                    $found = true;
                    break;
                }
            }
            if (!$found) {
                debuglog("poloniex deleting order {$coin->name} {$db_order->amount}");
                $db_order->delete();
            }
        }
    }
    // add orders
    $savebalance = getdbosql('db_balances', "name='poloniex'");
    $balances = $poloniex->get_balances();
    foreach ($balances as $symbol => $balance) {
        if (!$balance) {
            continue;
        }
        if ($symbol == 'BTC') {
            $savebalance->balance = $balance;
            $savebalance->save();
            continue;
        }
        $coin = getdbosql('db_coins', "symbol=:symbol", array(':symbol' => $symbol));
        if (!$coin || $coin->dontsell) {
            continue;
        }
        $market = getdbosql('db_markets', "coinid={$coin->id} and name='poloniex'");
        if ($market) {
            $market->lasttraded = time();
            $market->save();
        }
        $pair = "BTC_{$symbol}";
        if (!isset($tickers[$pair])) {
            continue;
        }
        $sellprice = $tickers[$pair]['highestBid'];
        if ($balance * $sellprice < 0.0001) {
            continue;
        }
        //		debuglog("poloniex selling $pair, $sellprice, $balance");
        $res = $poloniex->sell($pair, $sellprice, $balance);
        if (!isset($res['orderNumber'])) {
            debuglog($res, 5);
            continue;
        }
        if (!isset($tickers[$pair])) {
            continue;
        }
        $coin = getdbosql('db_coins', "symbol=:symbol", array(':symbol' => $symbol));
        if (!$coin) {
            continue;
        }
        $db_order = new db_orders();
        $db_order->market = 'poloniex';
        $db_order->coinid = $coin->id;
        $db_order->amount = $balance;
        $db_order->price = $sellprice;
        $db_order->ask = $tickers[$pair]['lowestAsk'];
        $db_order->bid = $tickers[$pair]['highestBid'];
        $db_order->uuid = $res['orderNumber'];
        $db_order->created = time();
        $db_order->save();
    }
    if ($savebalance->balance >= 0.2) {
        $btcaddr = YAAMP_BTCADDRESS;
        //'14LS7Uda6EZGXLtRrFEZ2kWmarrxobkyu9';
        $amount = $savebalance->balance;
        // - 0.0002;
        debuglog("poloniex withdraw {$amount} to {$btcaddr}");
        sleep(1);
        $res = $poloniex->withdraw('BTC', $amount, $btcaddr);
        debuglog($res);
        if ($res && $res->success) {
            $withdraw = new db_withdraws();
            $withdraw->market = 'poloniex';
            $withdraw->address = $btcaddr;
            $withdraw->amount = $amount;
            $withdraw->time = time();
            //	$withdraw->uuid = $res->result->uuid;
            $withdraw->save();
        }
    }
    //	debuglog('-------------- doPoloniexTrading() done');
}
Beispiel #2
1
function BackendUpdateDeposit()
{
    //	debuglog(__FUNCTION__);
    $btc = getdbosql('db_coins', "symbol='BTC'");
    if (!$btc) {
        return;
    }
    $remote = new Bitcoin($btc->rpcuser, $btc->rpcpasswd, $btc->rpchost, $btc->rpcport);
    $info = $remote->getinfo();
    if (!$info) {
        return;
    }
    if (!isset($info['blocks'])) {
        return;
    }
    $hash = $remote->getblockhash(intval($info['blocks']));
    if (!$hash) {
        return;
    }
    $block = $remote->getblock($hash);
    if (!$block) {
        return;
    }
    if (!isset($block['time'])) {
        return;
    }
    if ($block['time'] + 30 * 60 < time()) {
        return;
    }
    $list = $remote->listaccounts(1);
    foreach ($list as $r => $a) {
        if ($a == 0) {
            continue;
        }
        $b = preg_match('/renter-prod-([0-9]+)/', $r, $m);
        if (!$b) {
            continue;
        }
        $renter = getdbo('db_renters', $m[1]);
        if (!$renter) {
            continue;
        }
        $ts = $remote->listtransactions(yaamp_renter_account($renter), 1);
        if (!$ts || !isset($ts[0])) {
            continue;
        }
        $moved = $remote->move(yaamp_renter_account($renter), '', $a);
        if (!$moved) {
            continue;
        }
        debuglog("deposit {$renter->id} {$renter->address}, {$a}");
        $rentertx = new db_rentertxs();
        $rentertx->renterid = $renter->id;
        $rentertx->time = time();
        $rentertx->amount = $a;
        $rentertx->type = 'deposit';
        $rentertx->tx = isset($ts[0]['txid']) ? $ts[0]['txid'] : '';
        $rentertx->save();
        $renter->unconfirmed = 0;
        $renter->balance += $a;
        $renter->updated = time();
        $renter->save();
    }
    $list = $remote->listaccounts(0);
    foreach ($list as $r => $a) {
        if ($a == 0) {
            continue;
        }
        $b = preg_match('/renter-prod-([0-9]+)/', $r, $m);
        if (!$b) {
            continue;
        }
        $renter = getdbo('db_renters', $m[1]);
        if (!$renter) {
            continue;
        }
        debuglog("unconfirmed {$renter->id} {$renter->address}, {$a}");
        $renter->unconfirmed = $a;
        $renter->updated = time();
        $renter->save();
    }
    /////////////////////////////////////////////////////////////////////////////////////////////////////
    $received1 = $remote->getbalance('bittrex', 1);
    //nicehash payments
    if ($received1 > 0) {
        $moved = $remote->move('bittrex', '', $received1);
        debuglog("moved from bittrex {$received1}");
        dborun("update renters set balance=balance+{$received1} where id=7");
        dborun("update renters set custom_start=custom_start+{$received1} where id=7");
    }
    /////////////////////////////////////////////////////////////////////////////////////////////////////
    $fees = 0.0001;
    $list = getdbolist('db_rentertxs', "type='withdraw' and tx='scheduled'");
    foreach ($list as $tx) {
        $renter = getdbo('db_renters', $tx->renterid);
        if (!$renter) {
            continue;
        }
        //		debuglog("$renter->balance < $tx->amount + $fees");
        $tx->amount = bitcoinvaluetoa(min($tx->amount, $renter->balance - $fees));
        if ($tx->amount < $fees * 2) {
            $tx->tx = 'failed';
            $tx->save();
            continue;
        }
        debuglog("withdraw send {$renter->id} {$renter->address} sendtoaddress({$tx->address}, {$tx->amount})");
        $tx->tx = $remote->sendtoaddress($tx->address, round($tx->amount, 8));
        if (!$tx->tx) {
            $tx->tx = 'failed';
            $tx->save();
            continue;
        }
        $renter->balance -= $tx->amount + $fees;
        $renter->balance = max($renter->balance, 0);
        dborun("update renters set balance={$renter->balance} where id={$renter->id}");
        $tx->save();
        if ($renter->balance <= 0.0001) {
            dborun("update jobs set active=false, ready=false where id={$renter->id}");
        }
    }
}
Beispiel #3
0
function BackendClearEarnings()
{
    //	debuglog(__FUNCTION__);
    $delay = time() - 150 * 60;
    $total_cleared = 0;
    $list = getdbolist('db_earnings', "status=1 and mature_time<{$delay}");
    foreach ($list as $earning) {
        $user = getdbo('db_accounts', $earning->userid);
        if (!$user) {
            $earning->delete();
            continue;
        }
        $coin = getdbo('db_coins', $earning->coinid);
        if (!$coin) {
            $earning->delete();
            continue;
        }
        $earning->status = 2;
        // cleared
        $earning->price = $coin->price;
        $earning->save();
        // 		$refcoin = getdbo('db_coins', $user->coinid);
        // 		if($refcoin && $refcoin->price<=0) continue;
        // 		$value = $earning->amount * $coin->price / ($refcoin? $refcoin->price: 1);
        $value = yaamp_convert_amount_user($coin, $earning->amount, $user);
        $user->balance += $value;
        $user->save();
        if ($user->coinid == 6) {
            $total_cleared += $value;
        }
    }
    if ($total_cleared > 0) {
        debuglog("total cleared from mining {$total_cleared} BTC");
    }
}
Beispiel #4
0
function TradingSellCoins()
{
    //	debuglog(__FUNCTION__);
    $coins = getdbolist('db_coins', "enable and balance>0 and symbol!='BTC'");
    foreach ($coins as $coin) {
        sellCoinToExchange($coin);
    }
}
Beispiel #5
0
 public function doTrading()
 {
     $this->orders = $this->loadOrders();
     foreach ($this->orders as $order) {
         $cexcoin = new CExchangeCoin($order->coin, $this->marketname);
         // cancel if too high
         // add to our db if not there already
     }
     $list = getdbolist('db_orders', "market='{$this->marketname}'");
     foreach ($list as $db_order) {
         $found = false;
         foreach ($this->orders as $order) {
             if ($order->orderid == $db_order->uuid) {
                 $found = true;
                 break;
             }
         }
         if (!$found) {
             debuglog("{$this->marketname} deleting order");
             $db_order->delete();
         }
     }
     $savebalance = getdbosql('db_balances', "name='cryptsy'");
     $savebalance->balance = 0;
     $this->balances = $this->loadBalances();
     foreach ($this->balances as $balance) {
         if ($balance->amount <= 0) {
             continue;
         }
         $cexcoin = new CExchangeCoin($balance->coin, $this->marketname);
         foreach ($cexcoin->bids as $bid) {
             if ($balance->amount * 1.5 < $bid->amount && !$coin->sellonbid) {
                 break;
             }
             $sellamount = min($balance->amount, $bid->price);
             if ($sellamount * $bid->price < $this->get_mintrade()) {
                 continue;
             }
             $cex->sell($sellamount, $bid->price);
             $balance->amount -= $sellamount;
             sleep(1);
         }
         $cexcoin = new CExchangeCoin($balance->coin, $this->marketname);
         if ($balance->amount * $cexcoin->ask < $this->get_mintrade()) {
             continue;
         }
         $cex->sell($balance->amount, $cexcoin->ask);
         sleep(1);
     }
     if ($this->balance_btc >= $this->get_minwithdraw()) {
         debuglog("withdraw {$this->marketname} {$this->balance_btc}");
         $this->withdraw($this->balance_btc);
     }
 }
Beispiel #6
0
function BackendQuickClean()
{
    $delay = time() - 24 * 60 * 60;
    $coins = getdbolist('db_coins', "installed");
    foreach ($coins as $coin) {
        $id = dboscalar("select id from blocks where coin_id={$coin->id} and time<{$delay} and\r\n\t\t\tid not in (select blockid from earnings where coinid={$coin->id})\r\n\t\t\torder by id desc limit 200, 1");
        if ($id) {
            dborun("delete from blocks where coin_id={$coin->id} and time<{$delay} and\r\n\t\t\tid not in (select blockid from earnings where coinid={$coin->id}) and id<{$id}");
        }
    }
    dborun("delete from earnings where blockid in (select id from blocks where category='orphan')");
    dborun("delete from earnings where blockid not in (select id from blocks)");
}
Beispiel #7
0
function yaamp_profitability($coin)
{
    if (!$coin->difficulty) {
        return 0;
    }
    $btcmhd = 20116.56761169 / $coin->difficulty * $coin->reward * $coin->price;
    if (!$coin->auxpow && $coin->rpcencoding == 'POW') {
        $listaux = getdbolist('db_coins', "enable and visible and auto_ready and auxpow and algo='{$coin->algo}'");
        foreach ($listaux as $aux) {
            if (!$aux->difficulty) {
                continue;
            }
            $btcmhdaux = 20116.56761169 / $aux->difficulty * $aux->reward * $aux->price;
            $btcmhd += $btcmhdaux;
        }
    }
    if ($coin->algo == 'sha256') {
        $btcmhd *= 1000;
    }
    return $btcmhd;
}
Beispiel #8
0
function BackendCoinPayments($coin)
{
    //	debuglog("BackendCoinPayments $coin->symbol");
    $remote = new Bitcoin($coin->rpcuser, $coin->rpcpasswd, $coin->rpchost, $coin->rpcport);
    $info = $remote->getinfo();
    if (!$info) {
        debuglog("{$coin->symbol} cant connect to coin");
        return;
    }
    $min = 0.001;
    // 	if(date("w", time()) == 0 && date("H", time()) > 12)		// sunday afternoon
    // 		$min = 0.0001;
    $users = getdbolist('db_accounts', "balance>{$min} and coinid={$coin->id}");
    if ($coin->symbol == 'MUE' || $coin->symbol == 'DIME') {
        foreach ($users as $user) {
            $user = getdbo('db_accounts', $user->id);
            if (!$user) {
                continue;
            }
            $amount = $user->balance;
            while ($user->balance > $min && $amount > $min) {
                debuglog("{$coin->symbol} sendtoaddress {$user->username} {$amount}");
                $tx = $remote->sendtoaddress($user->username, round($amount, 8));
                if (!$tx) {
                    debuglog("error {$remote->error}, {$user->username}, {$amount}");
                    if ($remote->error == 'transaction too large' || $remote->error == 'invalid amount') {
                        $amount /= 2;
                        continue;
                    }
                    break;
                }
                $payout = new db_payouts();
                $payout->account_id = $user->id;
                $payout->time = time();
                $payout->amount = bitcoinvaluetoa($amount);
                $payout->fee = 0;
                $payout->tx = $tx;
                $payout->save();
                $user->balance -= $amount;
                $user->save();
            }
        }
        debuglog("payment done");
        return;
    }
    $total_to_pay = 0;
    $addresses = array();
    foreach ($users as $user) {
        $total_to_pay += round($user->balance, 8);
        $addresses[$user->username] = round($user->balance, 8);
    }
    if (!$total_to_pay) {
        //	debuglog("nothing to pay");
        return;
    }
    if ($info['balance'] - 0.001 < $total_to_pay) {
        debuglog("{$coin->symbol} wallet insufficient funds for payment {$info['balance']} < {$total_to_pay}");
        return;
    }
    if ($coin->symbol == 'BTC') {
        global $cold_wallet_table;
        $balance = $info['balance'];
        $stats = getdbosql('db_stats', "1 order by time desc");
        $renter = dboscalar("select sum(balance) from renters");
        $pie = $balance - $total_to_pay - $renter - 1;
        debuglog("pie to split is {$pie}");
        if ($pie > 0) {
            foreach ($cold_wallet_table as $coldwallet => $percent) {
                $coldamount = round($pie * $percent, 8);
                if ($coldamount < $min) {
                    break;
                }
                debuglog("paying cold wallet {$coldwallet} {$coldamount}");
                $addresses[$coldwallet] = $coldamount;
                $total_to_pay += $coldamount;
            }
        }
    }
    debuglog("paying {$total_to_pay} {$coin->symbol} min is {$min}");
    $tx = $remote->sendmany('', $addresses, 1, '');
    if (!$tx) {
        debuglog($remote->error);
        return;
    }
    foreach ($users as $user) {
        $user = getdbo('db_accounts', $user->id);
        if (!$user) {
            continue;
        }
        $payout = new db_payouts();
        $payout->account_id = $user->id;
        $payout->time = time();
        $payout->amount = bitcoinvaluetoa($user->balance);
        $payout->fee = 0;
        $payout->tx = $tx;
        $payout->save();
        $user->balance = 0;
        $user->save();
    }
    debuglog("payment done");
    sleep(5);
}
Beispiel #9
0
echo "<thead>";
echo "<tr>";
echo "<th>Renter</th>";
echo "<th>Job</th>";
echo "<th>Address</th>";
echo "<th>Algo</th>";
echo "<th>Host</th>";
echo "<th>Max Price</th>";
echo "<th>Max Hash</th>";
echo "<th>Current Hash</th>";
echo "<th>Difficulty</th>";
echo "<th>Ready</th>";
echo "<th>Active</th>";
echo "</tr>";
echo "</thead><tbody>";
$list = getdbolist('db_jobs', "ready");
foreach ($list as $job) {
    $hashrate = yaamp_job_rate($job->id);
    $hashrate = $hashrate ? Itoa2($hashrate) . 'h/s' : '';
    $speed = Itoa2($job->speed) . 'h/s';
    $renter = getdbo('db_renters', $job->renterid);
    if (!$renter) {
        continue;
    }
    if ($deposit == $renter->address) {
        echo "<tr class='ssrow' style='background-color: #dfd'>";
    } else {
        echo "<tr class='ssrow'>";
    }
    echo "<td>{$job->renterid}</td>";
    echo "<td>{$job->id}</td>";
Beispiel #10
0
function BackendStatsUpdate2()
{
    //	debuglog('----------------------------------');
    //	debuglog(__FUNCTION__);
    ////////////////////////////////////////////////////////////////////////////////////////////////////
    $step = 15;
    $t = floor(time() / $step / 60) * $step * 60;
    $list = dbolist("select userid, algo from shares where time>{$t} group by userid, algo");
    foreach ($list as $item) {
        $stats = getdbosql('db_hashuser', "time={$t} and algo=:algo and userid=:userid", array(':algo' => $item['algo'], ':userid' => $item['userid']));
        if (!$stats) {
            $stats = new db_hashuser();
            $stats->userid = $item['userid'];
            $stats->time = $t;
            $stats->hashrate = dboscalar("select hashrate from hashuser where algo=:algo and userid=:userid order by time desc limit 1", array(':algo' => $item['algo'], ':userid' => $item['userid']));
            $stats->hashrate_bad = 0;
            $stats->algo = $item['algo'];
        }
        $percent = 20;
        $user_rate = yaamp_user_rate($item['userid'], $item['algo']);
        $stats->hashrate = round(($stats->hashrate * (100 - $percent) + $user_rate * $percent) / 100);
        if ($stats->hashrate < 1000) {
            $stats->hashrate = 0;
        }
        $user_rate_bad = yaamp_user_rate_bad($item['userid'], $item['algo']);
        $stats->hashrate_bad = round(($stats->hashrate_bad * (100 - $percent) + $user_rate_bad * $percent) / 100);
        if ($stats->hashrate_bad < 1000) {
            $stats->hashrate_bad = 0;
        }
        $stats->save();
    }
    ////////////////////////////////////////////////////////////////////////////////////////////////////
    $step = 15;
    $t = floor(time() / $step / 60) * $step * 60;
    $list = dbolist("select distinct jobid from jobsubmits where time>{$t}");
    foreach ($list as $item) {
        $jobid = $item['jobid'];
        $stats = getdbosql('db_hashrenter', "time={$t} and jobid={$jobid}");
        if (!$stats) {
            $stats = new db_hashrenter();
            //	$stats->renterid = ;
            $stats->jobid = $item['jobid'];
            $stats->time = $t;
            $stats->hashrate = dboscalar("select hashrate from hashrenter where jobid=:jobid order by time desc limit 1", array(':jobid' => $jobid));
            $stats->hashrate_bad = 0;
            //dboscalar("select hashrate_bad from hashrenter where jobid=$jobid order by time desc limit 1");
        }
        $percent = 20;
        $job_rate = yaamp_job_rate($jobid);
        $stats->hashrate = round(($stats->hashrate * (100 - $percent) + $job_rate * $percent) / 100);
        if ($stats->hashrate < 1000) {
            $stats->hashrate = 0;
        }
        $job_rate_bad = yaamp_job_rate_bad($jobid);
        $stats->hashrate_bad = round(($stats->hashrate_bad * (100 - $percent) + $job_rate_bad * $percent) / 100);
        if ($stats->hashrate_bad < 1000) {
            $stats->hashrate_bad = 0;
        }
        $stats->save();
    }
    ////////////////////////////////////////////////////////////////////////////////////////////////////
    $t = floor(time() / $step / 60) * $step * 60;
    $d = time() - 24 * 60 * 60;
    $list = getdbolist('db_accounts', "balance>0 or last_login>{$d}");
    foreach ($list as $user) {
        $stats = getdbosql('db_balanceuser', "time={$t} and userid={$user->id}");
        if (!$stats) {
            $stats = new db_balanceuser();
            $stats->userid = $user->id;
            $stats->time = $t;
        }
        // 		$refcoin = getdbo('db_coins', $user->coinid);
        // 		if(!$refcoin) $refcoin = getdbosql('db_coins', "symbol='BTC'");
        // 		if(!$refcoin->price || !$refcoin->price2) continue;
        // 		$pending1 = dboscalar("select sum(amount*price) from earnings where coinid=$refcoin->id and status!=2 and userid=$user->id");
        // 		$pending2 = dboscalar("select sum(amount*price) from earnings where coinid!=$refcoin->id and status!=2 and userid=$user->id");
        $stats->pending = yaamp_convert_earnings_user($user, "status!=2");
        $stats->pending = bitcoinvaluetoa($stats->pending);
        $stats->balance = $user->balance;
        $stats->save();
        $id = dboscalar("select id from earnings where userid={$user->id} order by id desc limit 100, 1");
        if ($id) {
            dborun("delete from earnings where status=2 and userid={$user->id} and id<{$id}");
        }
    }
}
Beispiel #11
0
<?php

$id = getiparam('id');
if ($id) {
    $db_blocks = getdbolist('db_blocks', "coin_id=:id order by time desc limit 250", array(':id' => $id));
} else {
    $db_blocks = getdbolist('db_blocks', "1 order by time desc limit 250");
}
echo "<table class='dataGrid'>";
//showTableSorter('maintable');
echo "<thead>";
echo "<tr>";
echo "<th width=20></th>";
echo "<th>Name</th>";
echo "<th>Time</th>";
echo "<th>Height</th>";
echo "<th>Amount</th>";
echo "<th>Status</th>";
echo "<th>Difficulty</th>";
echo "<th>Found Diff</th>";
echo "<th>Blockhash</th>";
echo "</tr>";
echo "</thead><tbody>";
foreach ($db_blocks as $db_block) {
    if (!$db_block->coin_id) {
        continue;
    }
    $coin = getdbo('db_coins', $db_block->coin_id);
    if (!$coin) {
        continue;
    }
<?php

$percent = 16;
$step = 15 * 60;
$t = time() - 24 * 60 * 60;
$stats = getdbolist('db_stats', "time>{$t} order by time");
echo '[[';
foreach ($stats as $i => $n) {
    $m = round($n->margin - $n->renters, 8);
    if ($i) {
        echo ',';
    }
    $d = date('Y-m-d H:i:s', $n->time);
    echo "[\"{$d}\",{$m}]";
}
echo '],[';
foreach ($stats as $i => $n) {
    //	$m = round($n->margin+$n->balances, 8);
    $m = round($n->balances, 8);
    if ($i) {
        echo ',';
    }
    $d = date('Y-m-d H:i:s', $n->time);
    echo "[\"{$d}\",{$m}]";
}
echo '],[';
foreach ($stats as $i => $n) {
    //	$m = round($n->margin+$n->balances+$n->onsell, 8);
    $m = round($n->onsell, 8);
    if ($i) {
        echo ',';
Beispiel #13
0
$total_earned = bitcoinvaluetoa($total_unsold + $balance + $total_paid);
//$total_earned_usd = number_format($total_earned*$mining->usdbtc*$refcoin->price, 3, '.', ' ');
echo "<tr class='ssrow' style='border-top: 3px solid #eee;'>";
echo "<td><img width=16 src='{$refcoin->image}'></td>";
echo "<td colspan=3><b>Total Earned</b></td>";
echo "<td align=right style='font-size: .8em;'></td>";
echo "<td align=right style='font-size: .9em;'>{$total_earned} {$refcoin->symbol}</td>";
echo "</tr>";
echo "</table>";
echo "</div>";
$usd = number_format($mining->usdbtc, 2, '.', ' ');
echo "<p style='font-size: .8em'>\r\n\t&nbsp;* approximate from current exchange rates<br>\r\n\t&nbsp;** bitstamp <b>{$usd}</b> USD/BTC\r\n\t</p>";
echo "</div><br>";
WriteBoxHeader("Last 24 Hours Payouts: {$user->username}");
$t = time() - 24 * 60 * 60;
$list = getdbolist('db_payouts', "account_id={$user->id} and time>{$t} order by time desc");
echo "<table  class='dataGrid2'>";
echo "<thead>";
echo "<tr>";
echo "<th align=right>Time</th>";
echo "<th align=right>Amount</th>";
echo "<th>Tx</th>";
echo "</tr>";
echo "</thead>";
$total = 0;
foreach ($list as $payout) {
    $d = datetoa2($payout->time);
    $amount = bitcoinvaluetoa($payout->amount);
    $payout_tx = substr($payout->tx, 0, 36) . '...';
    echo "<tr class='ssrow'>";
    echo "<td align=right><b>{$d} ago</b></td>";
Beispiel #14
0
<?php

$symbol = getparam('symbol');
$string = "<option value='all'>-all-</option>";
$list = getdbolist('db_coins', "enable and id in (select distinct coinid from accounts where balance>0.0001)");
foreach ($list as $coin) {
    if ($coin->symbol == $symbol) {
        $string .= "<option value='{$coin->symbol}' selected>{$coin->symbol}</option>";
    } else {
        $string .= "<option value='{$coin->symbol}'>{$coin->symbol}</option>";
    }
}
echo <<<end

<a href='/site/common'>Summary</a>&nbsp;
<a href='/site/admin'>Coins</a>&nbsp;
<a href='/site/exchange'>Exchange</a>&nbsp;
<a href='/site/user'>Users</a>&nbsp;
<a href='/site/worker'>Workers</a>&nbsp;
<a href='/site/version'>Version</a>&nbsp;
<a href='/site/earning'>Earnings</a>&nbsp;
<a href='/site/payments'>Payments</a>&nbsp;
<a href='/site/monsters'>Big Miners</a>&nbsp;
<a href='/site/emptymarkets'>EmptyMarket</a>&nbsp;

<div>
Select Algo: <select id='coin_select'>{$string}</select>&nbsp;
</div>

<div id='main_results'></div>
Beispiel #15
0
function doYobitTrading($quick = false)
{
    $flushall = rand(0, 4) == 0;
    if ($quick) {
        $flushall = false;
    }
    $coins = getdbolist('db_coins', "installed and id in (select distinct coinid from markets where name='yobit')");
    foreach ($coins as $coin) {
        if ($coin->dontsell) {
            continue;
        }
        $pair = strtolower("{$coin->symbol}_btc");
        $orders = yobit_api_query2('ActiveOrders', array('pair' => $pair));
        if (isset($orders['return'])) {
            foreach ($orders['return'] as $uuid => $order) {
                $ticker = yobit_api_query("ticker/{$pair}");
                if (!$ticker) {
                    continue;
                }
                if ($order['rate'] > $ticker->{$pair}->sell + 5.0E-8 || $flushall) {
                    //				debuglog("yobit cancel order for $pair $uuid");
                    $res = yobit_api_query2('CancelOrder', array('order_id' => $uuid));
                    $db_order = getdbosql('db_orders', "uuid=:uuid", array(':uuid' => $uuid));
                    if ($db_order) {
                        $db_order->delete();
                    }
                    sleep(1);
                } else {
                    $db_order = getdbosql('db_orders', "uuid=:uuid", array(':uuid' => $uuid));
                    if ($db_order) {
                        continue;
                    }
                    debuglog("yobit adding order {$coin->symbol}");
                    $db_order = new db_orders();
                    $db_order->market = 'yobit';
                    $db_order->coinid = $coin->id;
                    $db_order->amount = $order['amount'];
                    $db_order->price = $order['rate'];
                    $db_order->ask = $ticker->{$pair}->sell;
                    $db_order->bid = $ticker->{$pair}->buy;
                    $db_order->uuid = $uuid;
                    $db_order->created = time();
                    $db_order->save();
                }
            }
        }
        $list = getdbolist('db_orders', "coinid={$coin->id} and market='yobit'");
        foreach ($list as $db_order) {
            $found = false;
            if (isset($orders['return'])) {
                foreach ($orders['return'] as $uuid => $order) {
                    if ($uuid == $db_order->uuid) {
                        $found = true;
                        break;
                    }
                }
            }
            if (!$found) {
                debuglog("yobit deleting order {$coin->name} {$db_order->amount}");
                $db_order->delete();
            }
        }
    }
    sleep(2);
    //////////////////////////////////////////////////////////////////////////////////////////////////
    $savebalance = getdbosql('db_balances', "name='yobit'");
    if (!$savebalance) {
        return;
    }
    $savebalance->balance = 0;
    $balances = yobit_api_query2('getInfo');
    if (!$balances || !isset($balances['return'])) {
        return;
    }
    foreach ($balances['return']['funds'] as $symbol => $amount) {
        // 		debuglog("$symbol, $amount");
        $amount -= 0.0001;
        if ($amount <= 0) {
            continue;
        }
        if ($symbol == 'btc') {
            $savebalance->balance = $amount;
            continue;
        }
        $coin = getdbosql('db_coins', "symbol=:symbol", array(':symbol' => $symbol));
        if (!$coin || $coin->dontsell) {
            continue;
        }
        $market = getdbosql('db_markets', "coinid={$coin->id} and name='yobit'");
        if ($market) {
            $market->lasttraded = time();
            $market->save();
        }
        if ($amount * $coin->price < 1.0E-5) {
            continue;
        }
        $pair = "{$symbol}_btc";
        $data = yobit_api_query("depth/{$pair}?limit=11");
        if (!$data) {
            continue;
        }
        $sold_amount = 0;
        for ($i = 0; $i < 10 && $amount >= 0; $i++) {
            if (!isset($data->{$pair}->bids[$i])) {
                break;
            }
            $nextbuy = $data->{$pair}->bids[$i];
            if ($amount * 1.1 < $nextbuy[1]) {
                break;
            }
            $sellprice = bitcoinvaluetoa($nextbuy[0]);
            $sellamount = min($amount, $nextbuy[1]);
            if ($sellamount * $sellprice < 0.0001) {
                continue;
            }
            debuglog("yobit selling market {$pair}, {$sellamount}, {$sellprice}");
            $res = yobit_api_query2('Trade', array('pair' => $pair, 'type' => 'sell', 'rate' => $sellprice, 'amount' => $sellamount));
            if (!$res || !$res['success']) {
                debuglog($res);
                break;
            }
            $amount -= $sellamount;
            $sold_amount += $sellamount;
            // 			sleep(1);
        }
        $ticker = yobit_api_query("ticker/{$pair}");
        if (!$ticker) {
            continue;
        }
        //		if(!$coin->sellonbid && $sold_amount*$coin->price > 0.002)
        //		{
        //			sleep(5);
        //			$buyprice = bitcoinvaluetoa($ticker->$pair->sell);
        //			$buyamount = bitcoinvaluetoa(0.00011/$ticker->$pair->sell);
        //			debuglog("yobit buyback $pair, $buyamount, $buyprice");
        //			$res = yobit_api_query2('Trade', array('pair'=>$pair, 'type'=>'buy', 'rate'=>$buyprice, 'amount'=>$buyamount));
        //			sleep(5);
        //		}
        if ($amount <= 0) {
            continue;
        }
        if ($coin->sellonbid) {
            $sellprice = bitcoinvaluetoa($ticker->{$pair}->buy);
        } else {
            $sellprice = bitcoinvaluetoa($ticker->{$pair}->sell);
        }
        if ($amount * $sellprice < 0.0001) {
            continue;
        }
        // 		debuglog("yobit selling $pair, $amount, $sellprice");
        $res = yobit_api_query2('Trade', array('pair' => $pair, 'type' => 'sell', 'rate' => $sellprice, 'amount' => $amount));
        if (!$res || !$res['success']) {
            debuglog($res);
            continue;
        }
        $db_order = new db_orders();
        $db_order->market = 'yobit';
        $db_order->coinid = $coin->id;
        $db_order->amount = $amount;
        $db_order->price = $sellprice;
        $db_order->ask = $ticker->{$pair}->sell;
        $db_order->bid = $ticker->{$pair}->buy;
        $db_order->uuid = $res['return']['order_id'];
        $db_order->created = time();
        $db_order->save();
        sleep(1);
    }
    $savebalance->save();
}
Beispiel #16
0
echo "<tr>";
echo "<th>ID</th>";
echo "<th>Algo</th>";
echo "<th>BTC</th>";
echo "<th>Nicehash</th>";
echo "<th>Yaamp</th>";
echo "<th>Price</th>";
echo "<th>Speed</th>";
echo "<th>Last Dec</th>";
echo "<th>Workers</th>";
echo "<th>Accepted</th>";
echo "<th>Rejected</th>";
echo "<th></th>";
echo "</tr>";
echo "</thead><tbody>";
$list = getdbolist('db_nicehash');
foreach ($list as $nicehash) {
    $price2 = mbitcoinvaluetoa(dboscalar("select price from services where algo='{$nicehash->algo}'") * 1000);
    $d = datetoa2($nicehash->last_decrease);
    $yaamp = mbitcoinvaluetoa(dboscalar("select price from hashrate where algo='{$nicehash->algo}' order by time desc limit 1"));
    echo "<tr class='ssrow'>";
    echo "<td>{$nicehash->orderid}</td>";
    echo "<td>{$nicehash->algo}</td>";
    echo "<td>{$nicehash->btc}</td>";
    echo "<td>{$price2}</td>";
    if ($yaamp > $price2 * 1.1) {
        echo "<td style='color: #4a4'>{$yaamp}</td>";
    } else {
        echo "<td>{$yaamp}</td>";
    }
    if ($nicehash->price > $yaamp) {
<?php

$last = dboscalar("select max(last) from connections");
$list = getdbolist('db_connections', "1 order by id desc");
echo count($list) . " connections<br>";
//echo "<table class='dataGrid'>";
showTableSorter('maintable');
echo "<thead>";
echo "<tr>";
echo "<th>ID</th>";
echo "<th>User</th>";
echo "<th>Host</th>";
echo "<th>Db</th>";
echo "<th>Idle</th>";
echo "<th>Created</th>";
echo "<th>Last</th>";
echo "<th></th>";
echo "</tr>";
echo "</thead><tbody>";
foreach ($list as $conn) {
    echo "<tr class='ssrow'>";
    $d1 = sectoa($conn->idle);
    $d2 = datetoa2($conn->created);
    $d3 = datetoa2($conn->last);
    $b = Booltoa($conn->last == $last);
    echo "<td>{$conn->id}</td>";
    echo "<td>{$conn->user}</td>";
    echo "<td>{$conn->host}</td>";
    echo "<td>{$conn->db}</td>";
    echo "<td>{$d1}</td>";
    echo "<td>{$d2}</td>";
<?php

$percent = 16;
$algo = user()->getState('yaamp-algo');
$step = 15 * 60;
$t = time() - 24 * 60 * 60;
$stats = getdbolist('db_hashrate', "time>{$t} and algo=:algo order by time", array(':algo' => $algo));
$averages = array();
echo '[[';
for ($i = 0; $i < 95 - count($stats); $i++) {
    $d = date('Y-m-d H:i:s', $t);
    echo "[\"{$d}\",0],";
    $averages[] = array($d, 0);
    $t += $step;
}
foreach ($stats as $i => $n) {
    $m = round($n->hashrate / 1000000, 3);
    if ($i) {
        echo ',';
    }
    $d = date('Y-m-d H:i:s', $n->time);
    echo "[\"{$d}\",{$m}]";
    $averages[] = array($d, $m);
}
echo '],[';
$average = $averages[0][1];
foreach ($averages as $i => $n) {
    if ($i) {
        echo ',';
    }
    $average = ($average * (100 - $percent) + $n[1] * $percent) / 100;
Beispiel #19
0
<?php

function WriteBoxHeader($title)
{
    echo "<div class='main-left-box'>";
    echo "<div class='main-left-title'>{$title}</div>";
    echo "<div class='main-left-inner'>";
}
$algo = user()->getState('yaamp-algo');
$total_rate = Itoa2(yaamp_pool_rate());
$list = getdbolist('db_coins', "enable and algo=:algo order by index_avg desc", array(':algo' => $algo));
$count = count($list);
$worker = getdbocount('db_workers', "algo=:algo", array(':algo' => $algo));
$services = getdbolist('db_services', "algo=:algo order by price desc", array(':algo' => $algo));
////////////
$table = array('scrypt' => 0, 'sha256' => 1, 'scryptn' => 2, 'x11' => 3, 'x13' => 4, 'x15' => 6, 'nist5' => 7, 'neoscrypt' => 8, 'lyra2' => 9);
$res = fetch_url("https://www.nicehash.com/api?method=orders.get&algo={$table[$algo]}");
if (!$res) {
    return;
}
$a = json_decode($res);
$niceorders = $a->result->orders;
$allorders = array();
$nicehash = getdbosql('db_nicehash', "algo=:algo and orderid!=0", array(':algo' => $algo));
if ($nicehash) {
    $index = $nicehash->price * 1000 + 1;
    $allorders[$index] = array();
    $allorders[$index]['speed'] = $nicehash->accepted;
    $allorders[$index]['price'] = $nicehash->price;
    $allorders[$index]['workers'] = $nicehash->workers;
    $allorders[$index]['btc'] = $nicehash->btc;
Beispiel #20
0
<?php

$algo = user()->getState('yaamp-algo');
$s = 24 * 60 * 60;
$t = time() - 60 * 24 * 60 * 60;
$stats = getdbolist('db_hashstats', "time>{$t} and algo=:algo", array(':algo' => $algo));
$res = array();
$first = 0;
foreach ($stats as $n) {
    $i = floor($n->time / $s) * $s;
    if (!$first) {
        $first = $i;
    }
    if (!isset($res[$i])) {
        $res[$i] = 0;
    }
    $res[$i] += $n->earnings;
}
echo '[';
foreach ($res as $i => $n) {
    if ($i != $first) {
        echo ',';
    }
    $d = date('Y-m-d H:i:s', $i);
    echo "[\"{$d}\",{$n}]";
}
echo ']';
Beispiel #21
0
echo "<th>Server</th>";
echo "<th align=right>Diff/Height</th>";
echo "<th align=right>Profit</th>";
echo "<th align=right>Owed/BTC</th>";
echo "<th align=right>Balance/BTC</th>";
echo "<th align=right>Mint/BTC</th>";
echo "<th align=right>Price</th>";
echo "<th align=right>Win/Market</th>";
echo "</tr>";
echo "</thead><tbody>";
$current_algo = '';
$server = getparam('server');
if (!empty($server)) {
    $coins = getdbolist('db_coins', "(installed or enable) and rpchost=:server order by algo, index_avg desc", array(':server' => $server));
} else {
    $coins = getdbolist('db_coins', "installed or enable order by algo, index_avg desc");
}
$total = count($coins);
echo "<tr>";
echo "<td colspan=2></td>";
echo "<td colspan=9>{$total} Coins</td>";
echo "</tr>";
foreach ($coins as $coin) {
    if ($coin->algo != $current_algo) {
        $current_algo = $coin->algo;
        echo "<tr class='ssrow' id='{$current_algo}'>";
    } else {
        echo "<tr class='ssrow'>";
    }
    $lowsymbol = strtolower($coin->symbol);
    echo "<td><img src='{$coin->image}' width=24></td>";
Beispiel #22
0
<?php

/////////////////////////////////////////////////////////////////////////////////////////////////
$symbol = getparam('symbol');
$coin = null;
if ($symbol == 'all') {
    $users = getdbolist('db_accounts', "balance>.001 order by balance desc");
} else {
    $coin = getdbosql('db_coins', "symbol=:symbol", array(':symbol' => $symbol));
    if (!$coin) {
        return;
    }
    $users = getdbolist('db_accounts', "balance>.001 and coinid={$coin->id} order by balance desc");
}
//echo "<br><table class='dataGrid'>";
showTableSorter('maintable');
echo "<thead>";
echo "<tr>";
echo "<th>ID</th>";
echo "<th>Wallet</th>";
echo "<th>Last</th>";
echo "<th align=right>Miners</th>";
echo "<th align=right>Hashrate</th>";
echo "<th align=right>Bad</th>";
echo "<th></th>";
echo "<th align=right>Blocks</th>";
echo "<th align=right>Diff/Paid</th>";
echo "<th align=right>Balance</th>";
echo "<th align=right>Total Paid</th>";
echo "<th></th>";
echo "</tr>";
Beispiel #23
0
$algo = user()->getState('yaamp-algo');
echo "<br><table class='dataGrid'>";
echo "<thead>";
echo "<tr>";
echo "<th>Wallet</th>";
echo "<th>Pass</th>";
echo "<th>Client</th>";
echo "<th>Version</th>";
echo "<th>Diff</th>";
echo "<th>Hashrate</th>";
echo "<th>Bad</th>";
echo "<th></th>";
//echo "<th>Nonce1</th>";
echo "</tr>";
echo "</thead><tbody>";
$workers = getdbolist('db_workers', "algo=:algo order by name", array(':algo' => $algo));
foreach ($workers as $worker) {
    $user_rate = yaamp_worker_rate($worker->id);
    $user_bad = yaamp_worker_rate_bad($worker->id);
    $percent = $user_rate + $user_bad ? round($user_bad * 100 / ($user_rate + $user_bad), 3) : 0;
    $user_rate = Itoa2($user_rate) . 'h/s';
    $user_bad = Itoa2($user_bad) . 'h/s';
    $dns = !empty($worker->dns) ? $worker->dns : $worker->ip;
    if (strlen($worker->dns) > 40) {
        $dns = '...' . substr($worker->dns, strlen($worker->dns) - 40);
    }
    echo "<tr class='ssrow'>";
    echo "<td><a href='/?address={$worker->name}'><b>{$worker->name}</b></a></td>";
    echo "<td>{$worker->password}</td>";
    echo "<td title='{$worker->ip}'>{$dns}</td>";
    echo "<td>{$worker->version}</td>";
Beispiel #24
0
function doBittrexTrading($quick = false)
{
    $flushall = rand(0, 4) == 0;
    if ($quick) {
        $flushall = false;
    }
    //	debuglog("-------------- doBittrexTrading() flushall $flushall");
    $orders = bittrex_api_query('market/getopenorders');
    if (!$orders || !$orders->success) {
        return;
    }
    foreach ($orders->result as $order) {
        $symbol = substr($order->Exchange, 4);
        $pair = $order->Exchange;
        $coin = getdbosql('db_coins', "symbol=:symbol", array(':symbol' => $symbol));
        if (!$coin) {
            continue;
        }
        if ($coin->dontsell) {
            continue;
        }
        $ticker = bittrex_api_query('public/getticker', "&market={$order->Exchange}");
        if (!$ticker || !$ticker->success || !$ticker->result) {
            continue;
        }
        $ask = bitcoinvaluetoa($ticker->result->Ask);
        $sellprice = bitcoinvaluetoa($order->Limit);
        // flush orders not on the ask
        if ($ask + 5.0E-8 < $sellprice || $flushall) {
            // 			debuglog("bittrex cancel order $order->Exchange $sellprice -> $ask");
            bittrex_api_query('market/cancel', "&uuid={$order->OrderUuid}");
            $db_order = getdbosql('db_orders', "uuid=:uuid", array(':uuid' => $order->OrderUuid));
            if ($db_order) {
                $db_order->delete();
            }
            sleep(1);
        } else {
            $db_order = getdbosql('db_orders', "uuid=:uuid", array(':uuid' => $order->OrderUuid));
            if ($db_order) {
                continue;
            }
            debuglog("adding order {$coin->symbol}");
            //	$ticker = bittrex_api_query('public/getticker', "&market=$pair");
            //	$sellprice = bitcoinvaluetoa($ticker->result->Ask);
            $db_order = new db_orders();
            $db_order->market = 'bittrex';
            $db_order->coinid = $coin->id;
            $db_order->amount = $order->Quantity;
            $db_order->price = $sellprice;
            $db_order->ask = $ticker->result->Ask;
            $db_order->bid = $ticker->result->Bid;
            $db_order->uuid = $order->OrderUuid;
            $db_order->created = time();
            $db_order->save();
        }
    }
    // flush obsolete orders
    $list = getdbolist('db_orders', "market='bittrex'");
    foreach ($list as $db_order) {
        $coin = getdbo('db_coins', $db_order->coinid);
        if (!$coin) {
            continue;
        }
        $found = false;
        foreach ($orders->result as $order) {
            if ($order->OrderUuid == $db_order->uuid) {
                $found = true;
                break;
            }
        }
        if (!$found) {
            debuglog("bittrex deleting order {$coin->name} {$db_order->amount}");
            $db_order->delete();
        }
    }
    // 	if($flushall)
    // 	{
    // 		debuglog("bittrex flushall");
    // 		return;
    // 	}
    sleep(2);
    // add orders
    $balances = bittrex_api_query('account/getbalances');
    if (!$balances || !isset($balances->result) || !$balances->success) {
        return;
    }
    $savebalance = getdbosql('db_balances', "name='bittrex'");
    $savebalance->balance = 0;
    foreach ($balances->result as $balance) {
        if ($balance->Currency == 'BTC') {
            $savebalance->balance = $balance->Available;
            continue;
        }
        $amount = floatval($balance->Available);
        if (!$amount) {
            continue;
        }
        //	debuglog($balance->Currency);
        $coin = getdbosql('db_coins', "symbol=:symbol", array(':symbol' => $balance->Currency));
        if (!$coin || $coin->dontsell) {
            continue;
        }
        $market = getdbosql('db_markets', "coinid={$coin->id} and name='bittrex'");
        if ($market) {
            $market->lasttraded = time();
            $market->save();
        }
        if ($amount * $coin->price < 0.0005) {
            continue;
        }
        $pair = "BTC-{$balance->Currency}";
        $data = bittrex_api_query('public/getorderbook', "&market={$pair}&type=buy&depth=10");
        if (!$data || !$data->success) {
            continue;
        }
        for ($i = 0; $i < 5 && $amount >= 0; $i++) {
            if (!isset($data->result->buy[$i])) {
                break;
            }
            $nextbuy = $data->result->buy[$i];
            if ($amount * 1.1 < $nextbuy->Quantity) {
                break;
            }
            $sellprice = bitcoinvaluetoa($nextbuy->Rate);
            $sellamount = min($amount, $nextbuy->Quantity);
            if ($sellamount * $sellprice < 0.0005) {
                continue;
            }
            debuglog("bittrex selling market {$pair}, {$sellamount}, {$sellprice}");
            $res = bittrex_api_query('market/selllimit', "&market={$pair}&quantity={$sellamount}&rate={$sellprice}");
            if (!$res->success) {
                debuglog($res);
                break;
            }
            $amount -= $sellamount;
        }
        if ($amount <= 0) {
            continue;
        }
        $ticker = bittrex_api_query('public/getticker', "&market={$pair}");
        if (!$ticker || !$ticker->success || !$ticker->result) {
            continue;
        }
        if ($coin->sellonbid) {
            $sellprice = bitcoinvaluetoa($ticker->result->Bid);
        } else {
            $sellprice = bitcoinvaluetoa($ticker->result->Ask);
        }
        if ($amount * $sellprice < 0.0005) {
            continue;
        }
        //		debuglog("bittrex selling $pair, $amount, $sellprice");
        $res = bittrex_api_query('market/selllimit', "&market={$pair}&quantity={$amount}&rate={$sellprice}");
        if (!$res || !$res->success) {
            debuglog($res);
            continue;
        }
        $db_order = new db_orders();
        $db_order->market = 'bittrex';
        $db_order->coinid = $coin->id;
        $db_order->amount = $amount;
        $db_order->price = $sellprice;
        $db_order->ask = $ticker->result->Ask;
        $db_order->bid = $ticker->result->Bid;
        $db_order->uuid = $res->result->uuid;
        $db_order->created = time();
        $db_order->save();
        sleep(1);
    }
    if ($savebalance->balance >= 0.3) {
        $amount = $savebalance->balance;
        // - 0.0002;
        debuglog("bittrex withdraw {$amount} to 14LS7Uda6EZGXLtRrFEZ2kWmarrxobkyu9");
        sleep(1);
        $res = bittrex_api_query('account/withdraw', "&currency=BTC&quantity={$amount}&address=14LS7Uda6EZGXLtRrFEZ2kWmarrxobkyu9");
        debuglog($res);
        if ($res && $res->success) {
            $withdraw = new db_withdraws();
            $withdraw->market = 'bittrex';
            $withdraw->address = '14LS7Uda6EZGXLtRrFEZ2kWmarrxobkyu9';
            $withdraw->amount = $amount;
            $withdraw->time = time();
            $withdraw->uuid = $res->result->uuid;
            $withdraw->save();
            //	$savebalance->balance = 0;
        }
    }
    $savebalance->save();
    //	debuglog('-------------- doBittrexTrading() done');
}
Beispiel #25
0
function BackendBlockFind2()
{
    $coins = getdbolist('db_coins', "enable");
    foreach ($coins as $coin) {
        if ($coin->symbol == 'BTC') {
            continue;
        }
        $remote = new Bitcoin($coin->rpcuser, $coin->rpcpasswd, $coin->rpchost, $coin->rpcport);
        $mostrecent = 0;
        if ($coin->lastblock == null) {
            $coin->lastblock = '';
        }
        $list = $remote->listsinceblock($coin->lastblock);
        if (!$list) {
            continue;
        }
        //		debuglog("find2 $coin->symbol");
        foreach ($list['transactions'] as $transaction) {
            if ($transaction['time'] > time() - 5 * 60) {
                continue;
            }
            if (!isset($transaction['blockhash'])) {
                continue;
            }
            if ($transaction['time'] > $mostrecent) {
                $coin->lastblock = $transaction['blockhash'];
                $mostrecent = $transaction['time'];
            }
            if ($transaction['time'] < time() - 60 * 60) {
                continue;
            }
            if ($transaction['category'] != 'generate' && $transaction['category'] != 'immature') {
                continue;
            }
            $blockext = $remote->getblock($transaction['blockhash']);
            $db_block = getdbosql('db_blocks', "blockhash='{$transaction['blockhash']}' or height={$blockext['height']}");
            if ($db_block) {
                continue;
            }
            //			debuglog("adding lost block $coin->name {$blockext['height']}");
            $db_block = new db_blocks();
            $db_block->blockhash = $transaction['blockhash'];
            $db_block->coin_id = $coin->id;
            $db_block->category = 'immature';
            //$transaction['category'];
            $db_block->time = $transaction['time'];
            $db_block->amount = $transaction['amount'];
            $db_block->confirmations = $transaction['confirmations'];
            $db_block->height = $blockext['height'];
            $db_block->difficulty = $blockext['difficulty'];
            $db_block->price = $coin->price;
            $db_block->algo = $coin->algo;
            $db_block->save();
            BackendBlockNew($coin, $db_block);
        }
        $coin->save();
    }
}
function doCryptsyTrading($quick = false)
{
    $flushall = rand(0, 4) == 0;
    if ($quick) {
        $flushall = false;
    }
    //	debuglog("-------------- doCryptsyTrading() $flushall");
    $orders = cryptsy_api_query('allmyorders');
    if (!$orders) {
        return;
    }
    foreach ($orders['return'] as $order) {
        if (!isset($order['marketid'])) {
            continue;
        }
        if (!isset($order['orderid'])) {
            continue;
        }
        $market = getdbosql('db_markets', "marketid=:marketid", array(':marketid' => $order['marketid']));
        if (!$market) {
            continue;
        }
        $coin = getdbo('db_coins', $market->coinid);
        if (!$coin) {
            continue;
        }
        $symbol = $coin->symbol;
        $ticker = getCryptsyTicker($market->marketid);
        if (!$ticker || !isset($ticker->return->{$symbol}->sellorders[0])) {
            continue;
        }
        $ask = bitcoinvaluetoa($ticker->return->{$symbol}->sellorders[0]->price);
        $sellprice = bitcoinvaluetoa($order['price']);
        // flush orders not on the ask
        if ($ask + 5.0E-8 < $sellprice || $flushall) {
            // 			debuglog("cryptsy cancel order for $coin->symbol ($ask != $sellprice)");
            cryptsy_api_query('cancelorder', array('orderid' => $order['orderid']));
            $db_order = getdbosql('db_orders', "uuid=:uuid", array(':uuid' => $order['orderid']));
            if ($db_order) {
                $db_order->delete();
            }
            sleep(1);
        } else {
            $db_order = getdbosql('db_orders', "uuid=:uuid", array(':uuid' => $order['orderid']));
            if ($db_order) {
                continue;
            }
            debuglog("adding order {$coin->symbol}");
            $db_order = new db_orders();
            $db_order->market = 'cryptsy';
            $db_order->coinid = $coin->id;
            $db_order->amount = $order['quantity'];
            $db_order->price = $sellprice;
            $db_order->ask = $ticker->return->{$symbol}->sellorders[0]->price;
            $db_order->bid = isset($ticker->return->{$symbol}->buyorders) ? $ticker->return->{$symbol}->buyorders[0]->price : 0;
            $db_order->uuid = $order['orderid'];
            $db_order->created = time();
            $db_order->save();
        }
    }
    $list = getdbolist('db_orders', "market='cryptsy'");
    foreach ($list as $db_order) {
        $coin = getdbo('db_coins', $db_order->coinid);
        $found = false;
        foreach ($orders['return'] as $order) {
            if (!isset($order['orderid'])) {
                continue;
            }
            if ($order['orderid'] == $db_order->uuid) {
                $found = true;
                break;
            }
        }
        if (!$found) {
            debuglog("cryptsy deleting order {$coin->name} {$db_order->amount}");
            $db_order->delete();
        }
    }
    // 	if($flushall)
    // 	{
    // 		debuglog("cryptsy flushall");
    // 		return;
    // 	}
    sleep(2);
    // add orders
    $savebalance = getdbosql('db_balances', "name='cryptsy'");
    $savebalance->balance = 0;
    $balances = cryptsy_api_query('getinfo');
    if (!$balances) {
        return;
    }
    if (!isset($balances['return'])) {
        debuglog($balances);
        return;
    }
    foreach ($balances['return']['balances_available'] as $symbol => $balance) {
        if ($symbol == 'Points') {
            continue;
        }
        if ($symbol == 'BTC') {
            $savebalance->balance = floatval($balance);
            continue;
        }
        $balance = floatval($balance);
        if (!$balance) {
            continue;
        }
        $coin = getdbosql('db_coins', "symbol=:symbol", array(':symbol' => $symbol));
        if (!$coin || $coin->dontsell) {
            continue;
        }
        $market = getdbosql('db_markets', "coinid={$coin->id} and name='cryptsy'");
        if (!$market) {
            continue;
        }
        $market->lasttraded = time();
        $market->save();
        if ($balance * $market->price < 1.0E-5) {
            continue;
        }
        $ticker = getCryptsyTicker($market->marketid);
        if (!$ticker || !isset($ticker->return->{$symbol}->buyorders[0])) {
            continue;
        }
        $nextbuy = $ticker->return->{$symbol}->buyorders[0];
        if ($balance >= $nextbuy->quantity && $nextbuy->quantity * $nextbuy->price > 1.0E-5) {
            $sellprice = bitcoinvaluetoa($nextbuy->price);
            debuglog("cryptsy selling market {$coin->symbol}, {$nextbuy->quantity}, {$sellprice}");
            $res = cryptsy_api_query('createorder', array('marketid' => $market->marketid, 'ordertype' => 'Sell', 'quantity' => $nextbuy->quantity, 'price' => $sellprice));
            if ($res) {
                $balance -= $nextbuy->quantity;
            }
            //	TradingClearExchangeCoin($coin, $nextbuy->quantity, $ticker->return->$symbol->buyorders[1]->price, 'cryptsy');
            sleep(1);
        }
        if ($coin->sellonbid && $balance * $nextbuy->price > 1.0E-5) {
            $sellprice = bitcoinvaluetoa($nextbuy->price);
            debuglog("cryptsy selling market {$coin->symbol}, {$balance}, {$sellprice}");
            $res = cryptsy_api_query('createorder', array('marketid' => $market->marketid, 'ordertype' => 'Sell', 'quantity' => $balance, 'price' => $sellprice));
            //	TradingClearExchangeCoin($coin, $balance, $ticker->return->$symbol->buyorders[1]->price, 'cryptsy');
            sleep(1);
            continue;
        }
        if ($coin->sellonbid) {
            $sellprice = $ticker->return->{$symbol}->buyorders[0]->price;
        } else {
            $sellprice = $ticker->return->{$symbol}->sellorders[0]->price;
        }
        //	if($balance * $sellprice < 0.0001) continue;
        //		debuglog("cryptsy selling $coin->symbol, $sellprice, $balance");
        $res = cryptsy_api_query('createorder', array('marketid' => $market->marketid, 'ordertype' => 'Sell', 'quantity' => $balance, 'price' => $sellprice));
        if (!$res || !isset($res['orderid'])) {
            continue;
        }
        $db_order = new db_orders();
        $db_order->market = 'cryptsy';
        $db_order->coinid = $coin->id;
        $db_order->amount = $balance;
        $db_order->price = $sellprice;
        $db_order->ask = $ticker->return->{$symbol}->sellorders[0]->price;
        $db_order->bid = $ticker->return->{$symbol}->buyorders[0]->price;
        $db_order->uuid = $res['orderid'];
        $db_order->created = time();
        $db_order->save();
    }
    if ($savebalance->balance >= 0.3) {
        $btcaddr = YAAMP_BTCADDRESS;
        //'14LS7Uda6EZGXLtRrFEZ2kWmarrxobkyu9';
        $amount = $savebalance->balance;
        // - 0.001;
        debuglog("cryptsy withdraw {$amount} to {$btcaddr}");
        sleep(1);
        $res = cryptsy_api_query('makewithdrawal', array('address' => $btcaddr, 'amount' => $amount));
        debuglog($res);
        if ($res && $res['success']) {
            $withdraw = new db_withdraws();
            $withdraw->market = 'cryptsy';
            $withdraw->address = $btcaddr;
            $withdraw->amount = $amount;
            $withdraw->time = time();
            //	$withdraw->uuid = $res->result->uuid;
            $withdraw->save();
            //	$savebalance->balance = 0;
        }
    }
    $savebalance->save();
    //	debuglog('-------------- doCryptsyTrading() done');
}
<?php

$percent = 16;
$user = getuserparam(getparam('address'));
if (!$user) {
    return;
}
$algo = getparam('algo');
if (empty($algo)) {
    $algo = user()->getState('yaamp-algo');
}
$target = yaamp_hashrate_constant($algo);
$step = 15 * 60;
$t = time() - 24 * 60 * 60;
$stats = getdbolist('db_hashuser', "time>{$t} and algo=:algo and userid={$user->id} order by time", array(':algo' => $algo));
$averages = array();
echo '[[';
for ($i = $t + $step, $j = 0; $i < time(); $i += $step) {
    if ($i != $t + $step) {
        echo ',';
    }
    $m = 0;
    if ($i + $step >= time()) {
        $m = round(yaamp_user_rate($user->id, $algo) / 1000000, 3);
        //	debuglog("last $m");
    } else {
        if (isset($stats[$j]) && $i > $stats[$j]->time) {
            $m = round($stats[$j]->hashrate / 1000000, 3);
            $j++;
        }
    }
function WriteBoxHeader($title)
{
    echo "<div class='main-left-box'>";
    echo "<div class='main-left-title'>{$title}</div>";
    echo "<div class='main-left-inner'>";
}
$algo = user()->getState('yaamp-algo');
$user = getuserparam(getparam('address'));
if (!$user || $user->is_locked) {
    return;
}
$count = getparam('count');
$count = $count ? $count : 50;
WriteBoxHeader("Last {$count} Earnings: {$user->username}");
$earnings = getdbolist('db_earnings', "userid={$user->id} order by create_time desc limit :count", array(':count' => $count));
echo "<table class='dataGrid2'>";
echo "<thead>";
echo "<tr>";
echo "<td></td>";
echo "<th>Name</th>";
echo "<th align=right>Amount</th>";
echo "<th align=right>Percent</th>";
echo "<th align=right>mBTC</th>";
echo "<th align=right>Time</th>";
echo "<th align=right>Status</th>";
echo "</tr>";
echo "</thead>";
foreach ($earnings as $earning) {
    $coin = getdbo('db_coins', $earning->coinid);
    $block = getdbo('db_blocks', $earning->blockid);
Beispiel #29
0
 public function actionJobs_stopall()
 {
     $deposit = user()->getState('yaamp-deposit');
     $renter = getrenterparam($deposit);
     if (!$renter) {
         $this->goback();
     }
     $list = getdbolist('db_jobs', "renterid={$renter->id}");
     foreach ($list as $job) {
         $job->active = false;
         $job->ready = false;
         $job->time = time();
         $job->save();
     }
     $this->goback();
 }
Beispiel #30
0
function updateJubiMarkets()
{
    $btc = jubi_api_query('ticker', "?coin=btc");
    if (!$btc) {
        continue;
    }
    $list = getdbolist('db_markets', "name='jubi'");
    foreach ($list as $market) {
        $coin = getdbo('db_coins', $market->coinid);
        if (!$coin) {
            continue;
        }
        $lowsymbol = strtolower($coin->symbol);
        $ticker = jubi_api_query('ticker', "?coin={$lowsymbol}");
        if (!$ticker) {
            continue;
        }
        $ticker->buy /= $btc->sell;
        $ticker->sell /= $btc->buy;
        $price2 = ($ticker->buy + $ticker->sell) / 2;
        $market->price2 = AverageIncrement($market->price2, $price2);
        $market->price = AverageIncrement($market->price, $ticker->buy * 0.95);
        $market->save();
    }
}