function BackendPricesUpdate() { // debuglog(__FUNCTION__); updateBittrexMarkets(); updateCryptsyMarkets(); updateCCexMarkets(); updateBleutradeMarkets(); updatePoloniexMarkets(); updateYobitMarkets(); updateJubiMarkets(); $list2 = getdbolist('db_coins', "installed and symbol2 is not null"); foreach ($list2 as $coin2) { $coin = getdbosql('db_coins', "symbol='{$coin2->symbol2}'"); if (!$coin) { continue; } $list = getdbolist('db_markets', "coinid={$coin->id}"); foreach ($list as $market) { $market2 = getdbosql('db_markets', "coinid={$coin2->id} and name='{$market->name}'"); if (!$market2) { continue; } $market2->price = $market->price; $market2->price2 = $market->price2; $market2->deposit_address = $market->deposit_address; $market2->save(); } } $coins = getdbolist('db_coins', "installed and id in (select distinct coinid from markets)"); foreach ($coins as $coin) { if ($coin->symbol == 'BTC') { $coin->price = 1; $coin->price2 = 1; $coin->save(); continue; } $market = getBestMarket($coin); if ($market) { $coin->price = $market->price * (1 - YAAMP_FEES_EXCHANGE / 100); $coin->price2 = $market->price2; $base_coin = !empty($market->base_coin) ? getdbosql('db_coins', "symbol='{$market->base_coin}'") : null; if ($base_coin) { $coin->price *= $base_coin->price; $coin->price2 *= $base_coin->price; } // if($market->name == 'c-cex') // $coin->price *= 0.95; } else { $coin->price = 0; $coin->price2 = 0; } $coin->save(); dborun("update earnings set price={$coin->price} where status!=2 and 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>"; echo "</table>"; ////////////////////////////////////////// echo "<br>";
function sellCoinToExchange($coin) { if ($coin->dontsell) { return; } $remote = new Bitcoin($coin->rpcuser, $coin->rpcpasswd, $coin->rpchost, $coin->rpcport); $info = $remote->getinfo(); if (!$info || !$info['balance']) { return false; } if (!empty($coin->symbol2)) { $coin2 = getdbosql('db_coins', "symbol='{$coin->symbol2}'"); if (!$coin2) { return; } $amount = $info['balance'] - $info['paytxfee']; $amount *= 0.9; // debuglog("sending $amount $coin->symbol to main wallet"); $tx = $remote->sendtoaddress($coin2->master_wallet, $amount); // if(!$tx) debuglog($remote->error); return; } $market = getBestMarket($coin); if (!$market) { return; } if (!$coin->sellonbid && $market->lastsent != null && $market->lastsent > $market->lasttraded) { // debuglog("*** not sending $coin->name to $market->name. last tx is late ***"); return; } $deposit_address = $market->deposit_address; $marketname = $market->name; if (empty($deposit_address)) { return false; } $reserved1 = dboscalar("select sum(balance) from accounts where coinid={$coin->id}"); $reserved2 = dboscalar("select sum(amount*price) from earnings\n\t\twhere status!=2 and userid in (select id from accounts where coinid={$coin->id})"); $reserved = ($reserved1 + $reserved2) * 10; $amount = $info['balance'] - $info['paytxfee'] - $reserved; // if($reserved>0) // { // debuglog("$reserved1 $reserved2 out of {$info['balance']}"); // debuglog("reserving $reserved $coin->symbol out of $coin->balance, available $amount"); // } if ($amount < $coin->reward / 4) { // debuglog("not enough $coin->symbol to sell $amount < $coin->reward /4"); return false; } $deposit_info = $remote->validateaddress($deposit_address); if (!$deposit_info || !isset($deposit_info['isvalid']) || !$deposit_info['isvalid']) { debuglog("sell invalid address {$deposit_address}"); return; } $amount = round($amount, 8); // debuglog("sending $amount $coin->symbol to $marketname, $deposit_address"); $market->lastsent = time(); $market->save(); // sleep(1); $tx = $remote->sendtoaddress($deposit_address, $amount); if (!$tx) { // debuglog($remote->error); if ($coin->symbol == 'MUE') { $amount = min($amount, 5000); } else { if ($coin->symbol == 'DIME') { $amount = min($amount, 10000000); } else { if ($coin->symbol == 'CNOTE') { $amount = min($amount, 10000); } else { if ($coin->symbol == 'SRC') { $amount = min($amount, 500); } else { $amount = round($amount * 0.99, 8); } } } } // debuglog("sending $amount $coin->symbol to $deposit_address"); sleep(1); $tx = $remote->sendtoaddress($deposit_address, $amount); if (!$tx) { debuglog("sending {$amount} {$coin->symbol} to {$deposit_address}"); debuglog($remote->error); return; } } $exchange = new db_exchange(); $exchange->market = $marketname; $exchange->coinid = $coin->id; $exchange->send_time = time(); $exchange->quantity = $amount; $exchange->price_estimate = $coin->price; $exchange->status = 'waiting'; $exchange->tx = $tx; $exchange->save(); return; }