} $queryInsert = 'INSERT ' . $newTable . ' SELECT * FROM ' . $context['pricesTable2h'] . ';'; if ($countRows['count'] == 0) { //make sure there are no rows in the new table $db->query($queryInsert); } //delete table from 4 days ago $x_days_ago = date('m_d', mktime(0, 0, 0, date("m"), date("d") - 4, date("Y"))); $oldTable = $context['pricesTable2h'] . '_' . $x_days_ago; $queryDrop = 'DROP TABLE IF EXISTS ' . $oldTable . ';'; $db->query($queryDrop); $output .= $newline . $newline . $queryCreate . $newline . $newline . $queryInsert . $newline . $newline . $queryDrop . $newline . $newline; //get daily balances from Bitfinex //connect to Bitfinex $bitfinexCall = new Bitfinex(BITFINEX_API_KEY, BITFINEX_API_SECRET); $acctFunds = $bitfinexCall->get_balances(); //call get_balances function $acctUSD = $acctFunds[8]['amount']; //USD balance $balanceBitfinex = number_format($acctUSD, 2); //account balance $todaysDate = date('Y-m-d', time()); //check for existing entries for today's date $queryCount = 'SELECT COUNT(*) as count FROM ' . $context['balanceTable'] . ' WHERE date="' . $todaysDate . '";'; $resCount = $db->query($queryCount); foreach ($resCount as $countRows) { } //update api_balance table $queryBalance = 'INSERT INTO ' . $context['balanceTable'] . ' (date, balance_bitfinex) VALUES ("' . $todaysDate . '", "' . $balanceBitfinex . '");'; if ($countRows['count'] == 0) { //make sure there are no rows for today's date
$ma_7 = $row['ma_7']; } $queryMA = $db->query('SELECT (AVG(' . $price_field . ')) AS ma_30 FROM ' . $context['pricesTable'] . ' WHERE count <= 30'); foreach ($queryMA as $row) { $ma_30 = $row['ma_30']; } $btcPrice = getBitfinexPrice('btc'); //current market BTC price $ltcPrice = getBitfinexPrice('ltc'); //current market LTC price if ($currency == 'btc') { $latestPrice = $btcPrice; } else { $latestPrice = $ltcPrice; } $acctFunds = $bitfinexAPI->get_balances(); $acctMargin = $bitfinexAPI->margin_infos(); //array_debug($acctFunds); //array_debug($acc); //funds in margin balance $acctBTC = $acctFunds[4]['amount']; $acctLTC = $acctFunds[5]['amount']; $acctUSD = $acctFunds[7]['amount']; $marginUSD = $acctMargin[0]['margin_limits'][0]['tradable_balance']; //how much btc/ltc you can buy - determined from margin balance $tradable['btc'] = number_format($marginUSD / $btcPrice, 4); $tradable['ltc'] = number_format($marginUSD / $ltcPrice, 4); $output .= $newline . $newline; $output .= 'current prices: ' . $newline . 'btc: ' . number_format($btcPrice, 4) . ' | ltc: ' . number_format($ltcPrice, 4) . $newline . $newline; $output .= 'account balance: ' . number_format($acctUSD, 2) . ' ' . $newline; $output .= 'margin: ' . number_format($marginUSD, 4) . ' | ';
$log->lwrite('Checking for offers older than ' . $config['remove_after'] . ' mins'); foreach ($current_offers as $item) { $id = $item['id']; $timestamp = (int) $item['timestamp']; $current_timestamp = time(); $diff_minutes = round(($current_timestamp - $timestamp) / 60); if ($config['remove_after'] <= $diff_minutes) { $log->lwrite("Removing old offer # {$id}"); $bfx->cancel_offer($id); } } // // Get avaliable balances // $log->lwrite('Getting balances'); $balances = $bfx->get_balances(); $available_balance = 0; //var_dump ($balances); if ($balances) { foreach ($balances as $item) { if ($item['type'] == 'deposit' && $item['currency'] == strtolower($config['currency'])) { $available_balance = floatval($item['available']); $total_balance = round(floatval($item['amount']), 2); $log->lwrite($config['currency'] . " Deposit balance is {$total_balance}"); break; } } } // Is there enough balance to lend? if ($available_balance >= $config['minimum_balance']) { $log->lwrite("Lending available balance of {$available_balance}");