Beispiel #1
0
 }
 if (count($warning) == 0) {
     // Check it doesn't already exits...
     $userCheck = $db->query("SELECT name, bfxapikey FROM `" . $config['db']['prefix'] . "Users` WHERE (name = '" . $db->escapeStr($_REQUEST['installAdminUser']) . "' OR bfxapikey = '" . $db->escapeStr($_REQUEST['installAdminBFXKey']) . "' ) LIMIT 1");
     if (count($userCheck) == 1) {
         if ($userCheck[0]['name'] == $_REQUEST['installAdminUser']) {
             $warning[] = 'This user name already exists in our database';
         }
         if ($userCheck[0]['bfxapikey'] == $_REQUEST['installAdminBFXKey']) {
             $warning[] = 'This bitfinex key already exists in our database';
         }
     }
 }
 if (count($warning) == 0) {
     // test their bfx key and sec to see if we can pull data //
     $bfxTest = new Bitfinex(0, $_REQUEST['installAdminBFXKey'], $_REQUEST['installAdminBFXSec']);
     $bt = $bfxTest->bitfinex_get('account_infos');
     if ($bt[0]['fees'][0]['pairs'] != '') {
         // looks good //
         // Create The Account //
         // hash the password
         $passEnc = $hasher->HashPassword($_REQUEST['installAdminPassword']);
         // write account to db
         $sql = "INSERT into `" . $config['db']['prefix'] . "Users` (`name`,`email`,`password`,`bfxapikey`,`bfxapisec`,`status` )\n\t\t\t\t VALUES\n\t\t\t\t ( '" . $db->escapeStr($_REQUEST['installAdminUser']) . "', '" . $db->escapeStr($_REQUEST['installAdminEmail']) . "', '" . $db->escapeStr($passEnc) . "',\n\t\t\t\t '" . $db->escapeStr($_REQUEST['installAdminBFXKey']) . "', '" . $db->escapeStr($_REQUEST['installAdminBFXSec']) . "', '9' )";
         $newUser = $db->iquery($sql);
         if ($newUser['id'] != 0) {
             //  Set default settings for the account //
             $sql = "INSERT into `" . $config['db']['prefix'] . "Vars` (`id`,`minlendrate`,`spreadlend`,`USDgapBottom`,`USDgapTop`,`thirtyDayMin`,`highholdlimit`,`highholdamt` )\n\t\t\t\t\t VALUES\n\t\t\t\t\t ( '" . $newUser['id'] . "', '0.0650', '3', '25000', '100000', '0.1500', '0.3500', '0' )";
             $newActSettings = $db->iquery($sql);
             // Success, tell them they need to login now //
             $alert[] = '<strong>User ' . $_REQUEST['new_name'] . '</strong> Account Created';
Beispiel #2
0
 function doAddAccount()
 {
     global $config, $hasher, $pages, $alert, $warning, $gen;
     // Check Everything Submitted to see if its valid //
     if (strlen($_REQUEST['new_name']) < 3) {
         $warning[] = 'Account Name must be at least 3 characters long';
     }
     if (strlen($_REQUEST['new_bfxKey']) != 43) {
         $warning[] = 'Bitfinex API Keys are 43 Characters Long';
     }
     if (strlen($_REQUEST['new_bfxSec']) != 43) {
         $warning[] = 'Bitfinex API Secrets are 43 Characters Long';
     }
     // Passwords should never be longer than 72 characters to prevent DoS attacks
     if (strlen($_REQUEST['new_password']) > 72) {
         $warning[] = 'Passwords must be less than 72 Characters';
     }
     if (count($warning) == 0) {
         // Check it doesn't already exits...
         $userCheck = $this->db->query("SELECT name, bfxapikey FROM `" . $config['db']['prefix'] . "Users` WHERE (name = '" . $this->db->escapeStr($_REQUEST['new_name']) . "' OR bfxapikey = '" . $this->db->escapeStr($_REQUEST['new_bfxKey']) . "' ) LIMIT 1");
         if (count($userCheck) == 1) {
             if ($userCheck[0]['name'] == $_REQUEST['new_name']) {
                 $warning[] = 'This user name already exists in our database';
             }
             if ($userCheck[0]['bfxapikey'] == $_REQUEST['new_bfxKey']) {
                 $warning[] = 'This bitfinex key already exists in our database';
             }
         }
     }
     if (count($warning) == 0) {
         // test their bfx key and sec to see if we can pull data //
         $bfxTest = new Bitfinex(0, $_REQUEST['new_bfxKey'], $_REQUEST['new_bfxSec']);
         $bt = $bfxTest->bitfinex_get('account_infos');
         if ($bt[0]['fees'][0]['pairs'] != '') {
             // looks good //
             // Create The Account //
             // hash the password
             $passEnc = $hasher->HashPassword($_REQUEST['new_password']);
             // write account to db
             $sql = "INSERT into `" . $config['db']['prefix'] . "Users` (`name`,`email`,`password`,`bfxapikey`,`bfxapisec`,`status` )\n\t\t\t\t\t VALUES\n\t\t\t\t\t ( '" . $this->db->escapeStr($_REQUEST['new_name']) . "', '" . $this->db->escapeStr($_REQUEST['new_email']) . "', '" . $this->db->escapeStr($passEnc) . "',\n\t\t\t\t\t '" . $this->db->escapeStr($_REQUEST['new_bfxKey']) . "', '" . $this->db->escapeStr($_REQUEST['new_bfxSec']) . "', '" . $this->db->escapeStr($_REQUEST['new_actType']) . "' )";
             $newUser = $this->db->iquery($sql);
             if ($newUser['id'] != 0) {
                 //  Set default settings for the account //
                 $sql = "INSERT into `" . $config['db']['prefix'] . "Vars` (`id`,`minlendrate`,`spreadlend`,`USDgapBottom`,`USDgapTop`,`thirtyDayMin`,`highholdlimit`,`highholdamt` )\n\t\t\t\t\t\t VALUES\n\t\t\t\t\t\t ( '" . $newUser['id'] . "', '0.0650', '3', '25000', '100000', '0.1500', '0.3500', '0' )";
                 $newActSettings = $this->db->iquery($sql);
                 $ret['page'] = 2;
                 $ret['newaccount'] = $newUser['id'];
                 $alert[] = '<strong>User ' . $_REQUEST['new_name'] . '</strong> Account Created';
             }
         }
     } else {
         $ret['page'] = 0;
     }
     return $ret;
 }
<?php

$currency = @$_GET['currency'] ? htmlspecialchars($_GET['currency']) : 'usd';
include_once "./config-{$currency}.php";
include_once './functions.php';
include_once './bitfinex.php';
include_once './logging.php';
// Logging class initialization
$log = new Logging();
// set path and name of log file (optional)
//	$log->lfile('./output.log');
// write message to the log file
$bfx = new Bitfinex($config['api_key'], $config['api_secret']);
$log->lwrite('Getting credits');
$credits = $bfx->get_credits();
// Something is wrong most likely API key
if (array_key_exists('message', $credits)) {
    die($credits['message']);
}
$amount_total = 0;
$rate_total = 0;
$count = count($credits);
foreach ($credits as $credit) {
    $rate = $credit['rate'];
    $amount = $credit['amount'];
    $amount_total = $amount_total + $amount;
    $rate_total = $rate_total + $rate;
}
$rate_total = $rate_total / $count;
//not weighted
$log->lwrite("Total {$count} loans for {$amount_total}");
*/
function update_last_action($last_action_data)
{
    global $db, $context;
    $queryD = 'UPDATE ' . $context['tradeDataTable'] . ' SET 
        last_action="' . $last_action_data['last_action'] . '",
        last_price="' . $last_action_data['last_price'] . '",            
        trade_signal="' . $last_action_data['trade_signal'] . '",
        last_updated="' . date('Y-m-d H:i:s', time()) . '"
        WHERE currency="' . $last_action_data['currency'] . '" 
            AND exchange="bitfinex"';
    $resultD = $db->query($queryD);
}
include_once 'include/api_bitfinex.php';
include_once 'include/config.php';
$bitfinexAPI = new Bitfinex(BITFINEX_API_KEY, BITFINEX_API_SECRET);
$debug = $_GET['debug'];
global $totalBalance, $bitfinexAPI;
//total balance in your account
if ($debug == 1) {
    //debug mode - no trading, output only
    echo '<< debug mode >>';
    $newline = '<br>';
} else {
    //live mode - output is sent to email - \n is newline in emails
    $newline = "\n";
}
//get trading options from api_options
$queryO = $db->query('SELECT * FROM ' . $context['optionsTable'] . ' ORDER BY opt');
echo $newline . $newline . 'api_options' . $newline;
foreach ($queryO as $opt) {
foreach ($resCount as $countRows) {
}
$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) {
include_once 'include/api_bitfinex.php';
include_once 'include/api_database.php';
include_once 'include/config.php';
global $totalBalance;
//total balance in your account
global $bitfinexAPI;
//bitfinex object
global $rangePercent;
//stop loss range %
global $pumpPercent;
global $dumpPercent;
global $bitfinexBalance;
$pumpPercent = 3.8;
$dumpPercent = -3.8;
$debug = $_GET['debug'];
$bitfinexAPI = new Bitfinex(BITFINEX_API_KEY, BITFINEX_API_SECRET);
$candleData = new Database($db);
if ($debug == 1) {
    //debug mode - no trading, output only
    echo '<< debug mode >>';
    $newline = '<br>';
} else {
    //live mode - output is sent to email - \n is newline in emails
    $newline = "\n";
}
$bitfinexOptions = $candleData->get_options();
$bitfinexTrading = $bitfinexOptions['bitfinex_trading'];
$bitfinexAPI->isBitfinexTrading($bitfinexTrading);
$optionsArray = array('bitfinex_currency', 'bitfinex_balance', 'bitfinex_pd_percent', 'bitfinex_sl_range', 'bitfinex_trading');
$output .= $newline . $newline . 'api_options' . $newline;
foreach ($optionsArray as $thisOpt) {
Beispiel #7
0
<?php

$currency = @$_GET['currency'] ? htmlspecialchars($_GET['currency']) : 'usd';
include_once "./config-{$currency}.php";
include_once './functions.php';
include_once './bitfinex.php';
include_once './logging.php';
// Logging class initialization
$log = new Logging();
// set path and name of log file (optional)
//	$log->lfile('./output.log');
// write message to the log file
$log->lwrite('Startup--------------------------');
$bfx = new Bitfinex($config['api_key'], $config['api_secret']);
//var_dump( $bfx);
//
// Get list of offers
//
$log->lwrite('Getting offers');
$current_offers = $bfx->get_offers();
var_dump($current_offers);
// Something is wrong most likely API key
if (array_key_exists('message', $current_offers)) {
    die($current_offers['message']);
}
// Remove offers that weren't executed for too long
$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();