Exemplo n.º 1
0
    $output = '<< debug mode >>';
    $newline = '<br>';
} else {
    //live mode
    $newline = "\n";
    //output is sent via email \n is newline in email
}
//get options from api_options table
$queryO = $db->query('SELECT * FROM ' . $context['optionsTable'] . ' ORDER BY opt');
$output .= $newline . $newline . 'api_options' . $newline;
foreach ($queryO as $opt) {
    $output .= '[ ' . $opt['opt'] . ': ' . $opt['setting'] . ' ]';
    $btc_e_option[$opt['opt']] = $opt['setting'];
}
echo $output;
$acctInfo = $api->apiQuery('getInfo');
$acctFunds = $acctInfo['return']['funds'];
$currency = $btc_e_option['btc_e_currency'];
$pair = $currency . '_usd';
//database field
$price_field = 'btce_' . $currency;
$queryMA = $db->query('SELECT (AVG(' . $price_field . ')) AS ma_7 FROM ' . $context['pricesTable'] . ' WHERE count <= 7');
foreach ($queryMA as $row) {
    $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'];
}
$latestPrice = $allPrices[$pair]['lastPrice'];
$btcPrice = $allPrices['btc_usd']['lastPrice'];
Exemplo n.º 2
0
        echo "MySQL error: " . $mysqli->error . PHP_EOL;
        exit;
    }
    // Clean database
    $result = $mysqli->query("DELETE FROM `bitbot`.`ticker` WHERE `ticker`.`timestamp` < " . (time() - 60 * 60 * 24 * 2));
    if (!$result) {
        echo "MySQL error: " . $mysqli->error . PHP_EOL;
        exit;
    }
    //DELETE FROM `bitbot`.`ticker` WHERE `ticker`.`id` = 1
} catch (BTCeAPIException $e) {
    echo $e->getMessage();
}
// Get account balance
try {
    $accountInfo = $BTCeAPI->apiQuery('getInfo');
    $ltc = $accountInfo['return']['funds']['ltc'];
    $btc = $accountInfo['return']['funds']['btc'];
    $nmc = $accountInfo['return']['funds']['nmc'];
    $nvc = $accountInfo['return']['funds']['nvc'];
    $ppc = $accountInfo['return']['funds']['ppc'];
    $usd = $accountInfo['return']['funds']['usd'];
    // Save to database
    $result = $mysqli->query("UPDATE `bitbot`.`balance` SET `ltc` = '" . $ltc . "', `btc` = '" . $btc . "', `nmc` = '" . $nmc . "', `nvc` = '" . $nvc . "', `ppc` = '" . $ppc . "', `usd` = '" . $usd . "', `timestamp` = '" . time() . "' WHERE `balance`.`id` = 1;");
    if (!$result) {
        echo "MySQL error: " . $mysqli->error . PHP_EOL;
        exit;
    }
} catch (BTCeAPIException $e) {
    echo $e->getMessage();
}
Exemplo n.º 3
0
<?php

/**
 * Example Usage of the BTCe API PHP Class
 *
 * @author marinu666
 * @license MIT License - https://github.com/marinu666/PHP-btce-api
 */
require_once 'btce-api.php';
$BTCeAPI = new BTCeAPI('', '');
// Example getInfo
try {
    // Perform the API Call
    $getInfo = $BTCeAPI->apiQuery('getInfo');
    // Print so we can see the output
    print_r($getInfo);
} catch (BTCeAPIException $e) {
    echo $e->getMessage();
}
// Example Custom query
try {
    // Input Parameters as an array (see: https://btc-e.com/api/documentation for list of parameters per call)
    $params = array('pair' => 'btc_usd');
    // Show info for the btc_usd pair
    // Perform the API Query
    print_r($BTCeAPI->apiQuery('ActiveOrders', $params));
} catch (BTCeAPIException $e) {
    echo $e->getMessage();
}
// Making an order
try {
Exemplo n.º 4
0
 /**
  * @param BTCeAPI $api
  * @return mixed
  * @throws BTCeAPIException
  */
 public function load(BTCeAPI &$api)
 {
     $qRes = $api->apiQuery('getInfo');
     if (isset($qRes['return']) && isset($qRes['return']['funds'])) {
         log_msg("Connection success, server time: " . date('Y.m.d H:i:s', $qRes['return']['server_time']));
         $qRes['return']['updated'] = time();
         $this->import($qRes['return']['funds']);
     } else {
         throw new BTCeAPIException(StorageException::$messages[StorageException::NO_DATA_IN_RESULT]);
     }
     return true;
 }