Example #1
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}");
        }
    }
}
Example #2
0
function showUser($userid, $what)
{
    $user = getdbo('db_accounts', $userid);
    if (!$user) {
        return;
    }
    $d = datetoa2($user->last_login);
    $balance = bitcoinvaluetoa($user->balance);
    $paid = dboscalar("select sum(amount) from payouts where account_id={$user->id}");
    $paid = bitcoinvaluetoa($paid);
    $t = time() - 24 * 60 * 60;
    $miner_count = getdbocount('db_workers', "userid={$user->id}");
    $share_count = getdbocount('db_shares', "userid={$user->id}");
    $block_count = getdbocount('db_blocks', "userid={$user->id} and time>{$t}");
    $coin = getdbo('db_coins', $user->coinid);
    echo "<tr class='ssrow'>";
    if ($coin) {
        echo "<td><img src='{$coin->image}' width=16> {$coin->symbol}</td>";
    } else {
        echo "<td></td>";
    }
    echo "<td>{$user->id}</td>";
    echo "<td><a href='/site?address={$user->username}'>{$user->username}</a></td>";
    echo "<td>{$what}</td>";
    echo "<td>{$d}</td>";
    echo "<td>{$block_count}</td>";
    echo "<td>{$balance}</td>";
    if (intval($paid) > 0.01) {
        echo "<td><b>{$paid}</b></td>";
    } else {
        echo "<td>{$paid}</td>";
    }
    echo "<td>{$miner_count}</td>";
    echo "<td>{$share_count}</td>";
    if ($user->is_locked) {
        echo "<td>locked</td>";
        echo "<td><a href='/site/unblockuser?wallet={$user->username}'>unblock</a></td>";
    } else {
        echo "<td></td>";
        echo "<td><a href='/site/blockuser?wallet={$user->username}'>block</a></td>";
    }
    echo "</tr>";
}
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);
    $d = datetoa2($earning->create_time);
    if (!$coin) {
        $reward = bitcoinvaluetoa($earning->amount);
        $value = altcoinvaluetoa($earning->amount * 1000);
        $percent = $block ? mbitcoinvaluetoa($earning->amount * 100 / $block->amount) : '';
        $algo = $block ? $block->algo : '';
        echo "<tr class='ssrow'>";
        echo "<td width=18><img width=16 src='/images/btc.png'></td>";
        echo "<td><b>Rental</b><span style='font-size: .8em'> ({$algo})</span></td>";
        echo "<td align=right style='font-size: .8em'><b>{$reward} BTC</b></td>";
        echo "<td align=right style='font-size: .8em'>{$percent}%</td>";
        echo "<td align=right style='font-size: .8em'>{$value}</td>";
        echo "<td align=right style='font-size: .8em'>{$d} ago</td>";
        echo "<td align=right style='font-size: .8em'>Cleared</td>";
        echo "</tr>";
        continue;
    }
    $reward = altcoinvaluetoa($earning->amount);
function doBleutradeTrading($quick = false)
{
    $flushall = rand(0, 4) == 0;
    if ($quick) {
        $flushall = false;
    }
    //	debuglog("-------------- dobleutradeTrading() flushall $flushall");
    $orders = bleutrade_api_query('market/getopenorders');
    if (!$orders) {
        return;
    }
    foreach ($orders->result as $order) {
        $e = explode('_', $order->Exchange);
        $symbol = $e[0];
        /// "Exchange" : "LTC_BTC",
        $pair = $order->Exchange;
        $coin = getdbosql('db_coins', "symbol=:symbol", array(':symbol' => $symbol));
        if (!$coin) {
            continue;
        }
        if ($coin->dontsell) {
            continue;
        }
        $ticker = bleutrade_api_query('public/getticker', "&market={$pair}");
        if (!$ticker || !$ticker->success || !isset($ticker->result[0])) {
            continue;
        }
        $ask = bitcoinvaluetoa($ticker->result[0]->Ask);
        $sellprice = bitcoinvaluetoa($order->Price);
        // flush orders not on the ask
        if ($ask + 5.0E-8 < $sellprice || $flushall) {
            //			debuglog("bleutrade cancel order $order->Exchange $sellprice -> $ask");
            bleutrade_api_query('market/cancel', "&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("bleutrade adding order {$coin->symbol}");
            //	$ticker = bleutrade_api_query('public/getticker', "&market=$pair");
            //	$sellprice = bitcoinvaluetoa($ticker->result->Ask);
            $db_order = new db_orders();
            $db_order->market = 'bleutrade';
            $db_order->coinid = $coin->id;
            $db_order->amount = $order->Quantity;
            $db_order->price = $sellprice;
            $db_order->ask = $ticker->result[0]->Ask;
            $db_order->bid = $ticker->result[0]->Bid;
            $db_order->uuid = $order->OrderId;
            $db_order->created = time();
            $db_order->save();
        }
    }
    // flush obsolete orders
    $list = getdbolist('db_orders', "market='bleutrade'");
    foreach ($list as $db_order) {
        $coin = getdbo('db_coins', $db_order->coinid);
        if (!$coin) {
            continue;
        }
        $found = false;
        foreach ($orders->result as $order) {
            if ($order->OrderId == $db_order->uuid) {
                $found = true;
                break;
            }
        }
        if (!$found) {
            debuglog("bleutrade deleting order {$coin->name} {$db_order->amount}");
            $db_order->delete();
        }
    }
    // 	if($flushall)
    // 	{
    //		debuglog("bleutrade flushall got here");
    // 		return;
    // 	}
    sleep(2);
    // add orders
    $balances = bleutrade_api_query('account/getbalances');
    //	debuglog($balances);
    if (!$balances || !isset($balances->result) || !$balances->success) {
        return;
    }
    $savebalance = getdbosql('db_balances', "name='bleutrade'");
    $savebalance->balance = 0;
    foreach ($balances->result as $balance) {
        if ($balance->Currency == 'BTC') {
            $savebalance->balance = $balance->Available;
            continue;
        }
        $amount = floatval($balance->Available);
        if (!$amount) {
            continue;
        }
        $coin = getdbosql('db_coins', "symbol=:symbol", array(':symbol' => $balance->Currency));
        if (!$coin || $coin->dontsell) {
            continue;
        }
        $market = getdbosql('db_markets', "coinid={$coin->id} and name='bleutrade'");
        if ($market) {
            $market->lasttraded = time();
            $market->save();
        }
        if ($amount * $coin->price < 1.0E-5) {
            continue;
        }
        $pair = "{$balance->Currency}_BTC";
        $data = bleutrade_api_query('public/getorderbook', "&market={$pair}&type=BUY&depth=10");
        if (!$data) {
            continue;
        }
        //	if(!isset($data->result[0])) continue;
        for ($i = 0; $i < 5; $i++) {
            if (!isset($data->result->buy[$i])) {
                break;
            }
            $nextbuy = $data->result->buy[$i];
            if ($amount < $nextbuy->Quantity || $nextbuy->Quantity * $nextbuy->Rate < 1.0E-5) {
                break;
            }
            $sellprice = bitcoinvaluetoa($nextbuy->Rate);
            //			debuglog("bleutrade selling market $pair, $nextbuy->Quantity, $sellprice");
            $res = bleutrade_api_query('market/selllimit', "&market={$pair}&quantity={$nextbuy->Quantity}&rate={$sellprice}");
            if (!$res->success) {
                debuglog($res);
                break;
            }
            $amount -= $nextbuy->Quantity;
        }
        $ticker = bleutrade_api_query('public/getticker', "&market={$pair}");
        if (!$ticker || !$ticker->success || !isset($ticker->result[0])) {
            continue;
        }
        if ($coin->sellonbid) {
            $sellprice = bitcoinvaluetoa($ticker->result[0]->Bid);
        } else {
            $sellprice = bitcoinvaluetoa($ticker->result[0]->Ask);
        }
        if ($amount * $sellprice < 0.0005) {
            continue;
        }
        debuglog("bleutrade selling {$pair}, {$amount}, {$sellprice}");
        $res = bleutrade_api_query('market/selllimit', "&market={$pair}&quantity={$amount}&rate={$sellprice}");
        if (!$res || !$res->success || !isset($res->result)) {
            debuglog($res);
            continue;
        }
        $db_order = new db_orders();
        $db_order->market = 'bleutrade';
        $db_order->coinid = $coin->id;
        $db_order->amount = $amount;
        $db_order->price = $sellprice;
        $db_order->ask = $ticker->result[0]->Ask;
        $db_order->bid = $ticker->result[0]->Bid;
        $db_order->uuid = $res->result->orderid;
        $db_order->created = time();
        $db_order->save();
        sleep(1);
    }
    if ($savebalance->balance >= 0.2) {
        $btcaddr = YAAMP_BTCADDRESS;
        //'14LS7Uda6EZGXLtRrFEZ2kWmarrxobkyu9';
        $amount = $savebalance->balance;
        // - 0.0002;
        debuglog("bleutrade withdraw {$amount} to {$btcaddr}");
        sleep(1);
        $res = bleutrade_api_query('account/withdraw', "&currency=BTC&quantity={$amount}&address={$btcaddr}");
        debuglog($res);
        if ($res && $res->success) {
            $withdraw = new db_withdraws();
            $withdraw->market = 'bleutrade';
            $withdraw->address = $btcaddr;
            $withdraw->amount = $amount;
            $withdraw->time = time();
            $withdraw->uuid = $res->result->orderid;
            $withdraw->save();
            //	$savebalance->balance = 0;
        }
    }
    $savebalance->save();
    //	debuglog('-------------- dobleutradeTrading() done');
}
Example #5
0
echo "<th></th>";
echo "<th>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);
    echo "<tr class='ssrow'>";
    echo "<td width=18></td>";
    echo "<td><b>{$d} ago</b></td>";
    echo "<td align=right><b>{$amount}</b></td>";
    if ($user->coinid == $bitcoin->id) {
        echo "<td style='font-family: monospace;'><a href='https://blockchain.info/tx/{$payout->tx}' target=_blank>{$payout->tx}</a></td>";
    } else {
        echo "<td style='font-family: monospace;'><a href='/explorer?id={$user->coinid}&txid={$payout->tx}' target=_blank>{$payout->tx}</a></td>";
    }
    echo "</tr>";
    $total += $payout->amount;
}
$total = bitcoinvaluetoa($total);
echo "<tr class='ssrow' style='border-top: 2px solid #eee;'>";
echo "<td width=18></td>";
echo "<td><b>Total</b></td>";
echo "<td align=right><b>{$total}</b></td>";
echo "<td></td>";
echo "</tr>";
echo "</table><br>";
echo "</div></div><br>";
Example #6
0
$row3 = dborow("select avg(hashrate) as a, sum(earnings) as b from hashstats where time>{$t3} and algo=:algo", array(':algo' => $algo));
if ($row1['a'] > 0 && $row2['a'] > 0 && $row3['a'] > 0) {
    $btcmhday1 = bitcoinvaluetoa($row1['b'] / $row1['a'] * 1000000 / 2);
    $btcmhday2 = bitcoinvaluetoa($row2['b'] / $row2['a'] * 1000000 / 7);
    $btcmhday3 = bitcoinvaluetoa($row3['b'] / $row3['a'] * 1000000 / 30);
} else {
    $btcmhday1 = 0;
    $btcmhday2 = 0;
    $btcmhday3 = 0;
}
$hashrate1 = Itoa2($row1['a']);
$hashrate2 = Itoa2($row2['a']);
$hashrate3 = Itoa2($row3['a']);
$total1 = bitcoinvaluetoa($row1['b']);
$total2 = bitcoinvaluetoa($row2['b']);
$total3 = bitcoinvaluetoa($row3['b']);
$height = '240px';
$algos = yaamp_get_algos();
$string = '';
foreach ($algos as $a) {
    if ($a == $algo) {
        $string .= "<option value='{$a}' selected>{$a}</option>";
    } else {
        $string .= "<option value='{$a}'>{$a}</option>";
    }
}
echo <<<end

<div id='resume_update_button' style='color: #444; background-color: #ffd; border: 1px solid #eea;
\tpadding: 10px; margin-left: 20px; margin-right: 20px; margin-top: 15px; cursor: pointer; display: none;'
\tonclick='auto_page_resume();' align=center>
Example #7
0
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>";
    echo "<td align=right><b>{$amount}</b></td>";
    if ($user->coinid == 6) {
        $txurl = "https://blockchain.info/tx/{$payout->tx}";
    } else {
        $txurl = "/explorer?id={$user->coinid}&txid={$payout->tx}";
    }
    echo "<td style='font-family: monospace;'><a href='{$txurl}' target=_blank>{$payout_tx}</a></td>";
    echo "</tr>";
    $total += $payout->amount;
}
$amount = bitcoinvaluetoa($total);
echo "<tr class='ssrow'>";
echo "<td align=right>Total:</td>";
echo "<td align=right><b>{$amount}</b></td>";
echo "<td></td>";
echo "</tr>";
echo "</table><br>";
echo "</div>";
echo "</div><br>";
Example #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);
}
Example #9
0
 public function actionTitle_results()
 {
     $user = getuserparam(getparam('address'));
     if ($user) {
         $balance = bitcoinvaluetoa($user->balance);
         $coin = getdbo('db_coins', $user->coinid);
         if ($coin) {
             echo "{$balance} {$coin->symbol} - yaamp.com";
         } else {
             echo "{$balance} - yaamp.com";
         }
     } else {
         echo "yaamp.com";
     }
 }
Example #10
0
function doCCexTrading($quick = false)
{
    $flushall = rand(0, 4) == 0;
    if ($quick) {
        $flushall = false;
    }
    //	debuglog("-------------- doCCexTrading() $flushall");
    $ccex = new CcexAPI();
    // upgrade orders
    $coins = getdbolist('db_coins', "enable and id in (select distinct coinid from markets where name='c-cex')");
    foreach ($coins as $coin) {
        if ($coin->dontsell) {
            continue;
        }
        $market2 = getdbosql('db_markets', "coinid={$coin->id} and (name='bittrex' or name='cryptsy')");
        if ($market2) {
            continue;
        }
        $pair = strtolower($coin->symbol) . '-btc';
        //		debuglog("c-cex list order for $pair");
        sleep(5);
        $orders = $ccex->getOrders($pair, 1);
        if (!$orders || isset($orders['error'])) {
            continue;
        }
        foreach ($orders['return'] as $uuid => $order) {
            $ticker = $ccex->getTickerInfo($pair);
            if (!$ticker) {
                continue;
            }
            if ($order['price'] > $ticker['sell'] + 5.0E-8 || $flushall) {
                //				debuglog("c-cex cancel order for $pair $uuid");
                sleep(5);
                $ccex->cancelOrder($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("c-cex adding order {$coin->symbol}");
                $db_order = new db_orders();
                $db_order->market = 'c-cex';
                $db_order->coinid = $coin->id;
                $db_order->amount = $order['amount'];
                $db_order->price = $order['price'];
                $db_order->ask = $ticker['sell'];
                $db_order->bid = $ticker['buy'];
                $db_order->uuid = $uuid;
                $db_order->created = time();
                $db_order->save();
            }
        }
        $list = getdbolist('db_orders', "coinid={$coin->id} and market='c-cex'");
        foreach ($list as $db_order) {
            $found = false;
            foreach ($orders['return'] as $uuid => $order) {
                if ($uuid == $db_order->uuid) {
                    $found = true;
                    break;
                }
            }
            if (!$found) {
                debuglog("c-cex deleting order {$coin->name} {$db_order->amount}");
                $db_order->delete();
            }
        }
    }
    sleep(2);
    //////////////////////////////////////////////////////////////////////////////////////////////////
    $savebalance = getdbosql('db_balances', "name='c-cex'");
    $savebalance->balance = 0;
    //	debuglog("c-cex getbalance");
    sleep(5);
    $balances = $ccex->getBalance();
    if (!$balances || !isset($balances['return'])) {
        return;
    }
    foreach ($balances['return'] as $balance) {
        foreach ($balance as $symbol => $amount) {
            if (!$amount) {
                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='c-cex'");
            if ($market) {
                $market->lasttraded = time();
                $market->save();
            }
            if ($amount * $coin->price < 1.0E-5) {
                continue;
            }
            $pair = "{$symbol}-btc";
            ////////////////////////
            $maxprice = 0;
            $maxamount = 0;
            //		debuglog("c-cex list order for $pair all");
            sleep(5);
            $orders = $ccex->getOrders($pair, 0);
            foreach ($orders['return'] as $order) {
                if ($order['type'] == 'sell') {
                    continue;
                }
                if ($order['price'] > $maxprice) {
                    $maxprice = $order['price'];
                    $maxamount = $order['amount'];
                }
            }
            //	debuglog("maxbuy for $pair $maxamount $maxprice");
            if ($amount >= $maxamount && $maxamount * $maxprice > 1.0E-5) {
                $sellprice = bitcoinvaluetoa($maxprice);
                debuglog("c-cex selling market {$pair}, {$maxamount}, {$sellprice}");
                sleep(5);
                $res = $ccex->makeOrder('sell', $pair, $maxamount, $sellprice);
                if (!$res || !isset($res['return'])) {
                    debuglog($res);
                } else {
                    $amount -= $maxamount;
                }
                sleep(1);
            }
            ///
            $ticker = $ccex->getTickerInfo($pair);
            if (!$ticker) {
                continue;
            }
            $sellprice = bitcoinvaluetoa($ticker['sell']);
            //		debuglog("c-cex selling $pair, $amount, $sellprice");
            sleep(5);
            $res = $ccex->makeOrder('sell', $pair, $amount, $sellprice);
            if (!$res || !isset($res['return'])) {
                continue;
            }
            $db_order = new db_orders();
            $db_order->market = 'c-cex';
            $db_order->coinid = $coin->id;
            $db_order->amount = $amount;
            $db_order->price = $sellprice;
            $db_order->ask = $ticker['sell'];
            $db_order->bid = $ticker['buy'];
            $db_order->uuid = $res['return'];
            $db_order->created = time();
            $db_order->save();
        }
    }
    $savebalance->save();
    //	debuglog('-------------- doCCexTrading() done');
}
Example #11
0
    if (!$user) {
        continue;
    }
    $coin = getdbo('db_coins', $user->coinid);
    if ($user->username == $username) {
        echo "<tr style='background-color: #e0d3e8;'><td width=24>";
    } else {
        echo "<tr class='ssrow'><td width=24>";
    }
    if ($coin) {
        echo "<img width=16 src='{$coin->image}'>";
    } else {
        echo "<img width=16 src='/images/base/delete.png'>";
    }
    echo "</td><td><a href='/?address={$address}' style='font-family: monospace; font-size: 1.1em;'>{$address}</a></td>";
    $balance = bitcoinvaluetoa($user->balance);
    if ($coin) {
        $balance = $balance > 0 ? "{$balance} {$coin->symbol}" : '';
    } else {
        $balance = $balance > 0 ? "{$balance} BTC" : '';
    }
    echo "<td align=right>{$balance}</td>";
    echo "<tr>";
}
echo "</table></form></div></div><br>";
echo "</td><td valign=top>";
echo <<<END
<div id='pool_current_results'>
<br><br><br><br><br><br><br><br><br><br>
</div>
END;
Example #12
0
echo "<thead class=''>";
echo "<tr>";
echo "<th>Name</th>";
echo "<th>Price</th>";
echo "<th>Price2</th>";
echo "<th>Sent</th>";
echo "<th>Traded</th>";
echo "<th>Late</th>";
echo "<th>Deposit</th>";
echo "<th>Message</th>";
echo "</tr>";
echo "</thead><tbody>";
$bestmarket = getBestMarket($coin);
foreach ($list as $market) {
    $price = bitcoinvaluetoa($market->price);
    $price2 = bitcoinvaluetoa($market->price2);
    $lowsymbol = strtolower($coin->symbol);
    if ($market->name == 'cryptsy') {
        $marketurl = "https://www.cryptsy.com/markets/view/{$market->marketid}";
    } else {
        if ($market->name == 'bittrex') {
            $marketurl = "https://bittrex.com/Market/Index?MarketName=BTC-{$coin->symbol}";
        } else {
            if ($market->name == 'mintpal') {
                $marketurl = "https://www.mintpal.com/market/{$coin->symbol}/BTC";
            } else {
                if ($market->name == 'poloniex') {
                    $marketurl = "https://poloniex.com/exchange/btc_{$coin->symbol}";
                } else {
                    if ($market->name == 'bleutrade') {
                        $marketurl = "https://bleutrade.com/exchange/{$coin->symbol}/BTC";
Example #13
0
                     }
                 }
             }
         }
     }
 }
 if ($exchange->status == 'waiting') {
     echo "<tr style='background-color: #e0d3e8;'>";
 } else {
     echo "<tr class='ssrow'>";
 }
 $sent = datetoa2($exchange->send_time) . ' ago';
 $received = $exchange->receive_time ? sectoa($exchange->receive_time - $exchange->send_time) : '';
 $price = $exchange->price ? bitcoinvaluetoa($exchange->price) : bitcoinvaluetoa($coin->price);
 $estimate = bitcoinvaluetoa($exchange->price_estimate);
 $total = $exchange->price ? bitcoinvaluetoa($exchange->quantity * $exchange->price) : bitcoinvaluetoa($exchange->quantity * $coin->price);
 echo "<td><img width=16 src='{$coin->image}'></td>";
 echo "<td><b><a href='/site/coin?id={$coin->id}'>{$coin->name} ({$coin->symbol})</a></b></td>";
 echo "<td><b><a href='{$marketurl}' target=_blank>{$exchange->market}</a></b></td>";
 echo "<td>{$sent}</td>";
 echo "<td>{$exchange->quantity}</td>";
 echo "<td>{$estimate}</td>";
 echo "<td>{$price}</td>";
 echo $total > 0.01 ? "<td><b>{$total}</b></td>" : "<td>{$total}</td>";
 echo "<td>";
 if ($exchange->status == 'waiting') {
     //	echo "<a href='/site/clearexchange?id=$exchange->id'>[clear]</a>";
     echo "<a href='/site/deleteexchange?id={$exchange->id}'>[del]</a>";
 }
 echo "</td>";
 echo "</tr>";
}
$step = 15 * 60;
$t = time() - 24 * 60 * 60;
$stats = getdbolist('db_balanceuser', "time>{$t} and userid={$user->id} order by time");
echo '[[';
for ($i = $t + $step, $j = 0; $i < time(); $i += $step) {
    if ($i != $t + $step) {
        echo ',';
    }
    $m = 0;
    if (isset($stats[$j]) && $i > $stats[$j]->time) {
        $m = bitcoinvaluetoa($stats[$j]->balance);
        $j++;
    }
    $d = date('Y-m-d H:i:s', $i);
    echo "[\"{$d}\",{$m}]";
}
echo '],[';
for ($i = $t + $step, $j = 0; $i < time(); $i += $step) {
    if ($i != $t + $step) {
        echo ',';
    }
    $m = 0;
    if (isset($stats[$j]) && $i > $stats[$j]->time) {
        $m = bitcoinvaluetoa($stats[$j]->pending);
        $j++;
    }
    $d = date('Y-m-d H:i:s', $i);
    echo "[\"{$d}\",{$m}]";
}
echo ']]';
Example #15
0
echo "<br><table class='dataGrid'>";
echo "<thead>";
echo "<tr>";
echo "<th></th>";
echo "<th>Name</th>";
echo "<th align=right>Amount</th>";
echo "<th align=right>Diff</th>";
echo "<th align=right>Block</th>";
echo "<th align=right>Time</th>";
echo "<th align=right>Status</th>";
echo "</tr>";
echo "</thead>";
foreach ($db_blocks as $db_block) {
    $d = datetoa2($db_block->time);
    if (!$db_block->coin_id) {
        $reward = bitcoinvaluetoa($db_block->amount);
        $algo_color = getAlgoColors($db_block->algo);
        echo "<tr style='background-color:{$algo_color};'>";
        echo "<td width=18><img width=16 src='/images/btc.png'></td>";
        echo "<td><b>Rental</b> ({$db_block->algo})</td>";
        echo "<td align=right style='font-size: .8em'><b>{$reward} BTC</b></td>";
        echo "<td align=right style='font-size: .8em'></td>";
        echo "<td align=right style='font-size: .8em'></td>";
        echo "<td align=right style='font-size: .8em'>{$d} ago</td>";
        echo "<td align=right style='font-size: .8em'>";
        echo "<span style='padding: 2px; color: white; background-color: #5cb85c'>Confirmed</span>";
        echo "</td>";
        echo "</tr>";
        continue;
    }
    $coin = getdbo('db_coins', $db_block->coin_id);
Example #16
0
<?php

$algo = user()->getState('yaamp-algo');
$t = time() - 48 * 60 * 60;
$stats = getdbolist('db_hashstats', "time>{$t} and algo=:algo", array(':algo' => $algo));
echo '[';
foreach ($stats as $i => $n) {
    $m = $n->hashrate ? bitcoinvaluetoa($n->earnings * 24 * 1000000 / $n->hashrate) : 0;
    if ($i) {
        echo ',';
    }
    $d = date('Y-m-d H:i:s', $n->time);
    echo "[\"{$d}\",{$m}]";
}
echo ']';
Example #17
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}");
        }
    }
}
Example #18
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');
}
Example #19
0
    return;
}
echo "<table class='dataGrid'>";
echo "<thead>";
echo "<tr>";
echo "<th>ID</th>";
echo "<th>Address</th>";
echo "<th align=right>Time</th>";
echo "<th align=right>Type</th>";
echo "<th align=right>Amount</th>";
echo "<th>Tx</th>";
echo "</tr>";
echo "</thead>";
foreach ($list as $tx) {
    $d = datetoa2($tx->time);
    $amount = bitcoinvaluetoa($tx->amount);
    $renter = getdbo('db_renters', $tx->renterid);
    if (!$renter) {
        continue;
    }
    echo "<tr class='ssrow'>";
    echo "<td>{$renter->id}</td>";
    echo "<td><a href='/renting?address={$renter->address}'>{$renter->address}</a></td>";
    echo "<td align=right><b>{$d} ago</b></td>";
    echo "<td align=right title='{$tx->address}'>{$tx->type}</td>";
    echo "<td align=right><b>{$amount}</b></td>";
    if (strlen($tx->tx) > 32) {
        $tx_show = substr($tx->tx, 0, 36) . '...';
        $txurl = "https://blockchain.info/tx/{$tx->tx}";
        echo "<td style='font-family: monospace;'><a href='{$txurl}' target=_blank>{$tx_show}</a></td>";
    } else {
Example #20
0
<?php

$algo = user()->getState('yaamp-algo');
$t = time() - 48 * 60 * 60;
$stats = getdbolist('db_hashstats', "time>{$t} and algo=:algo", array(':algo' => $algo));
echo '[';
foreach ($stats as $i => $n) {
    $e = bitcoinvaluetoa($n->earnings * 24);
    if ($i) {
        echo ',';
    }
    $d = date('Y-m-d H:i:s', $n->time);
    echo "[\"{$d}\",{$e}]";
}
echo ']';
Example #21
0
echo "<thead>";
echo "<tr>";
echo "<th></th>";
echo "<th>Name</th>";
echo "<th align=right>max</th>";
echo "<th align=right>mbtc</th>";
echo "<th align=right>profit</th>";
echo "<th align=right>TTF</th>";
echo "<th align=right>Hash *</th>";
echo "<th align=right>**</th>";
echo "</tr>";
echo "</thead>";
foreach ($list as $coin) {
    $name = substr($coin->name, 0, 12);
    $difficulty = Itoa2($coin->difficulty, 3);
    $price = bitcoinvaluetoa($coin->price);
    $height = number_format($coin->block_height, 0, '.', ' ');
    $pool_ttf = $coin->pool_ttf ? sectoa2($coin->pool_ttf) : '';
    $reward = round($coin->reward, 3);
    $btcmhd = mbitcoinvaluetoa(yaamp_profitability($coin));
    $pool_hash = yaamp_coin_rate($coin->id);
    $pool_hash = $pool_hash ? Itoa2($pool_hash) . 'h/s' : '';
    show_orders($allorders, $services, $btcmhd);
    show_services($services, $btcmhd);
    if (!$coin->auto_ready) {
        echo "<tr style='opacity: 0.4;'>";
    } else {
        echo "<tr class='ssrow'>";
    }
    echo "<td width=18><img width=16 src='{$coin->image}'></td>";
    echo "<td><b><a href='/site/coin?id={$coin->id}'>{$name}</a></b></td>";
Example #22
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();
}
Example #23
0
    }
    echo "<span style='color: red;'> {$percent_pool2}</span></td>";
    $owed = dboscalar("select sum(balance) from accounts where coinid={$coin->id}");
    $owed_btc = bitcoinvaluetoa($owed * $coin->price);
    $owed = bitcoinvaluetoa($owed);
    if ($coin->balance + $coin->mint < $owed) {
        echo "<td align=right style='font-size: .9em'><span style='color: red;'>{$owed}<br>{$owed_btc}</span></td>";
    } else {
        echo "<td align=right style='font-size: .9em'>{$owed}<br>{$owed_btc}</td>";
    }
    $btc = bitcoinvaluetoa($coin->balance * $coin->price);
    echo "<td align=right style='font-size: .9em'>{$coin->balance}<br>{$btc}</td>";
    $btc = bitcoinvaluetoa($coin->mint * $coin->price);
    echo "<td align=right style='font-size: .9em'>{$coin->mint}<br>{$btc}</td>";
    $price = bitcoinvaluetoa($coin->price);
    $price2 = bitcoinvaluetoa($coin->price2);
    //	$marketcount = getdbocount('db_markets', "coinid=$coin->id");
    $marketname = '';
    $bestmarket = getBestMarket($coin);
    if ($bestmarket) {
        $marketname = $bestmarket->name;
    }
    if ($coin->dontsell) {
        echo "<td align=right style='font-size: .9em; background-color: #ffaaaa'>{$price}<br>{$price2}</td>";
    } else {
        echo "<td align=right style='font-size: .9em'>{$price}<br>{$price2}</td>";
    }
    echo "<td align=right style='font-size: .9em'>{$coin->reward}<br>{$marketname}</td>";
    echo "</tr>";
}
echo "</tbody>";
Example #24
0
    $total_paid += $paid;
}
echo "</tbody>";
$total_balance = bitcoinvaluetoa($total_balance);
$total_paid = bitcoinvaluetoa($total_paid);
$user_count = count($users);
echo "<tr class='ssrow' style='border-top: 2px solid #eee;'>";
echo "<td><b>Users Total ({$user_count})</b></a></td>";
echo "<td colspan=7></td>";
echo "<td align=right><b>{$total_balance}</b></td>";
echo "<td align=right><b>{$total_paid}</b></td>";
echo "<td></td>";
echo "</tr>";
if ($coin) {
    $balance = bitcoinvaluetoa($coin->balance);
    $profit = bitcoinvaluetoa($balance - $total_balance);
    echo "<tr class='ssrow' style='border-top: 2px solid #eee;'>";
    echo "<td><b>Wallet Balance</b></a></td>";
    echo "<td colspan=7></td>";
    echo "<td align=right><b>{$balance}</b></td>";
    echo "<td colspan=2></td>";
    echo "</tr>";
    echo "<tr class='ssrow' style='border-top: 2px solid #eee;'>";
    echo "<td><b>Wallet Profit</b></a></td>";
    echo "<td colspan=7></td>";
    echo "<td align=right><b>{$profit}</b></td>";
    echo "<td colspan=2></td>";
    echo "</tr>";
}
echo "</table>";
//echo "<p><a href='/site/bonususers'>1% bonus</a></p>";
Example #25
0
<?php

$algo = user()->getState('yaamp-algo');
$s = 4 * 60 * 60;
$t = time() - 7 * 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] = array();
        $res[$i]['earnings'] = 0;
        $res[$i]['hashrate'] = 0;
    }
    $res[$i]['earnings'] += $n->earnings;
    $res[$i]['hashrate'] += $n->hashrate / 24;
}
echo '[';
foreach ($res as $i => $n) {
    $m = $n['hashrate'] ? bitcoinvaluetoa($n['earnings'] * 1000000 / $n['hashrate']) : 0;
    if ($i != $first) {
        echo ',';
    }
    $d = date('Y-m-d H:i:s', $i);
    echo "[\"{$d}\",{$m}]";
}
echo ']';
Example #26
0
echo "<thead>";
echo "<tr>";
echo "<th>Wallet</th>";
echo "<th>Last</th>";
echo "<th width=20></th>";
echo "<th>Coin</th>";
echo "<th align=right>Pool</th>";
echo "<th align=right>User</th>";
echo "</tr>";
echo "</thead><tbody>";
foreach ($list as $user) {
    $coin = getdbo('db_coins', $user->coinid);
    $balance = bitcoinvaluetoa($user->balance);
    $d = datetoa2($user->last_login);
    echo "<tr class='ssrow'>";
    echo "<td><a href='/?address={$user->username}'><b>{$user->username}</b></a></td>";
    echo "<td>{$d}</td>";
    if ($coin) {
        $coinbalance = bitcoinvaluetoa($coin->balance);
        echo "<td><img width=16 src='{$coin->image}'></td>";
        echo "<td><b><a href='/site/coin?id={$coin->id}'>{$coin->name}</a></b></td>";
        echo "<td align=right>{$coinbalance}</td>";
    } else {
        echo "<td></td>";
        echo "<td></td>";
        echo "<td align=right></td>";
    }
    echo "<td align=right>{$balance}</td>";
    echo "</tr>";
}
echo "</tbody></table>";
Example #27
0
$hashrate1 = max($hashrate1, 1);
$hashrate2 = max($hashrate2, 1);
$hashrate3 = max($hashrate3, 1);
$hashrate4 = max($hashrate4, 1);
$btcmhday1 = mbitcoinvaluetoa($total1 / $hashrate1 * 1000000 * 24 * 1000);
$btcmhday2 = mbitcoinvaluetoa($total2 / $hashrate2 * 1000000 * 1 * 1000);
$btcmhday3 = mbitcoinvaluetoa($total3 / $hashrate3 * 1000000 / 7 * 1000);
$btcmhday4 = mbitcoinvaluetoa($total4 / $hashrate4 * 1000000 / 30 * 1000);
$hashrate1 = Itoa2($hashrate1);
$hashrate2 = Itoa2($hashrate2);
$hashrate3 = Itoa2($hashrate3);
$hashrate4 = Itoa2($hashrate4);
$total1 = bitcoinvaluetoa($total1);
$total2 = bitcoinvaluetoa($total2);
$total3 = bitcoinvaluetoa($total3);
$total4 = bitcoinvaluetoa($total4);
echo "<tr class='ssrow' style='border-top: 2px solid #eee;'>";
echo "<td width=18><img width=16 src='/images/btc.png'></td>";
echo "<td><b>BTC Value</b></td>";
echo "<td align=right style='font-size: .9em;'>{$total1}</td>";
echo "<td align=right style='font-size: .9em;'>{$total2}</td>";
echo "<td align=right style='font-size: .9em;'>{$total3}</td>";
echo "<td align=right style='font-size: .9em;'>{$total4}</td>";
echo "</tr>";
///////////////////////////////////////////////////////////////////////
echo "<tr class='ssrow' style='border-top: 2px solid #eee;'>";
echo "<td width=18></td>";
echo "<td><b>Avg Hashrate</b></td>";
echo "<td align=right style='font-size: .9em;'>{$hashrate1}h/s</td>";
echo "<td align=right style='font-size: .9em;'>{$hashrate2}h/s</td>";
echo "<td align=right style='font-size: .9em;'>{$hashrate3}h/s</td>";
Example #28
0
<?php

$algo = user()->getState('yaamp-algo');
JavascriptFile("/extensions/jqplot/jquery.jqplot.js");
JavascriptFile("/extensions/jqplot/plugins/jqplot.dateAxisRenderer.js");
JavascriptFile("/extensions/jqplot/plugins/jqplot.barRenderer.js");
JavascriptFile("/extensions/jqplot/plugins/jqplot.highlighter.js");
JavascriptFile("/extensions/jqplot/plugins/jqplot.cursor.js");
JavascriptFile('/yaamp/ui/js/auto_refresh.js');
$this->widget('UniForm');
$balance = bitcoinvaluetoa($renter->balance);
echo <<<END

<table cellspacing=20 width=100%>
<tr><td valign=top width=50%>

<!--  -->

<div id='balance_results'></div>
<div id='orders_results'></div>

</td><td valign=top>

<div id='pool_current_results'>
<br><br><br><br><br><br><br><br><br><br>
</div>

<div id='all_orders_results'></div>

<div class="main-left-box">
<div class="main-left-title">Last 24 Hours Renting ({$algo})</div>
Example #29
0
 public function actionWithdraw()
 {
     $fees = 0.0001;
     $deposit = user()->getState('yaamp-deposit');
     if (!$deposit) {
         $this->render('login');
         return;
     }
     $renter = getrenterparam($deposit);
     if (!$renter) {
         $this->render('login');
         return;
     }
     $amount = getparam('withdraw_amount');
     $address = getparam('withdraw_address');
     $amount = floatval(bitcoinvaluetoa(min($amount, $renter->balance - $fees)));
     if ($amount < 0.001) {
         user()->setFlash('error', 'Minimum withdraw is 0.001');
         $this->redirect("/renting");
         return;
     }
     $coin = getdbosql('db_coins', "symbol='BTC'");
     if (!$coin) {
         return;
     }
     $remote = new Bitcoin($coin->rpcuser, $coin->rpcpasswd, $coin->rpchost, $coin->rpcport);
     $res = $remote->validateaddress($address);
     if (!$res || !isset($res['isvalid']) || !$res['isvalid']) {
         user()->setFlash('error', 'Invalid address');
         $this->redirect("/renting");
         return;
     }
     $rentertx = new db_rentertxs();
     $rentertx->renterid = $renter->id;
     $rentertx->time = time();
     $rentertx->amount = $amount;
     $rentertx->type = 'withdraw';
     $rentertx->address = $address;
     $rentertx->tx = 'scheduled';
     $rentertx->save();
     debuglog("withdraw scheduled {$renter->id} {$renter->address}, {$amount} to {$address}");
     user()->setFlash('message', "withdraw scheduled");
     $this->redirect("/renting");
 }
Example #30
0
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');
}