Example #1
0
    curl_setopt($ch, CURLOPT_URL, $url);
    $result = curl_exec($ch);
    curl_close($ch);
    $json = json_decode($result, true);
    return $json;
}
//get price for BTC-E currency pair
function getPriceData($pair)
{
    global $public_api;
    $json = retrieveJSON($public_api . 'ticker/' . $pair);
    return $json[$pair];
}
$candleData = new Database($db);
$candleData->get_options();
$candleData->get_candles('bitfinex_btc');
$diff = $candleData->get_percent();
$percentDiff_12 = $candleData->get_percent();
//trend of 12 candles (6 hours)
$percentDiff_12 = number_format($percentDiff_12, 2);
//echo $percentDiff_12;
//get ema10 and ema21
$k21 = 2 / (21 + 1);
//smoothing constant - 21 day
$k10 = 2 / (10 + 1);
//smoothing constant - 10 day
$q = 'SELECT date_format(time, "%m/%d/%Y %h:%i %p") as time, bitfinex_btc from api_prices order by count desc';
$res = $db->query($q);
$array = array();
$arrayPrice = array();
foreach ($res as $row) {
$tradable['btc'] = number_format($marginUSD / $btcPrice, 4);
$tradable['ltc'] = number_format($marginUSD / $ltcPrice, 4);
$output .= $newline . $newline;
$output .= 'account balance: ' . number_format($acctUSD, 2) . ' ' . $newline;
$output .= 'margin: ' . number_format($marginUSD, 4) . ' | ';
$output .= 'tradeable btc: ' . $tradable['btc'] . ' | tradeable ltc: ' . $tradable['ltc'] . $newline . $newline;
$output .= 'current prices: | btc: ' . number_format($btcPrice, 4) . ' | ltc: ' . number_format($ltcPrice, 4) . $newline . $newline;
//get api_trade_data
$queryT = 'SELECT * FROM ' . $context['tradeDataTable'] . ' WHERE currency = "' . $currency . '"
    AND exchange = "bitfinex"';
$resT = $db->query($queryT);
foreach ($resT as $t) {
    $last_updated = $t['last_updated'];
    $trade_signal = $t['trade_signal'];
}
$candleData->get_candles($price_field);
//get all candle data from db
//get ema data
$ema10 = $candleData->get_ema(10);
$ema21 = $candleData->get_ema(21);
if ($ema10 > $ema21) {
    $crossOver = 1;
    $crossUnder = 0;
    $emaTrend = 'Cross Over';
} else {
    $crossOver = 0;
    $crossUnder = 1;
    $emaTrend = 'Cross Under';
}
//get ATH & ATL for stop loss calculations
$recordedATH = $candleData->get_recorded_ATH();