exchanges: allow to ignore some with empty keys/secret

- cryptsy is now used in low priority as default market

- remove keys.php from default defines, only loaded when used

- safecex prepare balances and deposit addresses (not ready yet)
This commit is contained in:
Tanguy Pruvot 2016-01-13 10:46:01 +01:00
parent 07699af80d
commit e3bd3de87d
14 changed files with 144 additions and 27 deletions

View file

@ -102,13 +102,13 @@ function getBestMarket($coin)
// else take one of the big exchanges...
$market = getdbosql('db_markets', "coinid=$coin->id AND price!=0 AND
deposit_address IS NOT NULL AND deposit_address != '' AND
name IN ('poloniex','bittrex','cryptsy') ORDER BY price DESC");
name IN ('poloniex','bittrex') ORDER BY price DESC");
}
if(!$market) {
// else the best price
$market = getdbosql('db_markets', "coinid=$coin->id AND price!=0 AND
deposit_address IS NOT NULL AND deposit_address != ''
AND name!='yobit' ORDER BY price DESC");
AND name!='safecex' AND name!='cryptsy' ORDER BY price DESC");
}
if(!$market) {
$market = getdbosql('db_markets', "coinid=$coin->id AND price!=0 AND
@ -703,13 +703,31 @@ function updateSafecexMarkets()
$market->price2 = AverageIncrement($market->price2, $price2);
$market->price = AverageIncrement($market->price, $ticker->bid*0.98);
$market->save();
if (empty($coin->price)) {
$coin->price = $market->price;
$coin->price2 = $market->price2;
$coin->save();
}
// debuglog("safecex: $pair $market->price ".bitcoinvaluetoa($market->price2));
break;
if(empty($market->deposit_address)) {
if (!isset($getbalances_called)) {
// only one query is enough
$balances = safecex_api_user('getbalances');
$getbalances_called = true;
}
if(is_array($balances)) foreach ($balances as $balance) {
if ($balance->symbol == $coin->symbol) {
if (empty($market->deposit_address)) {
$market->deposit_address = $balance->deposit;
debuglog("safecex: {$coin->symbol} deposit address filled");
$market->save();
} else if ($market->deposit_address != $balance->deposit) {
debuglog("safecex: {$coin->symbol} deposit address differs!");
}
}
}
}
}
}
}

View file

@ -3,6 +3,11 @@
function bittrex_api_query($method, $params='')
{
require_once('/etc/yiimp/keys.php');
if (!defined('EXCH_BITTREX_SECRET')) define('EXCH_BITTREX_SECRET', '');
// optional secret key
if (empty(EXCH_BITTREX_SECRET) && strpos($method, 'public') === FALSE) return FALSE;
if (empty(EXCH_BITTREX_KEY) && strpos($method, 'public') === FALSE) return FALSE;
$apikey = EXCH_BITTREX_KEY; // your API-key
$apisecret = EXCH_BITTREX_SECRET; // your Secret-key

View file

@ -5,28 +5,35 @@
function bleutrade_api_query($method, $params='')
{
require_once('/etc/yiimp/keys.php');
if (!defined('EXCH_BLEUTRADE_SECRET')) define('EXCH_BLEUTRADE_SECRET', '');
// optional secret key
if (empty(EXCH_BLEUTRADE_SECRET) && strpos($method, 'public') === FALSE) return false;
if (empty(EXCH_BLEUTRADE_KEY) && strpos($method, 'public') === FALSE) return false;
$apikey = EXCH_BLEUTRADE_KEY; // your API-key
$apisecret = EXCH_BLEUTRADE_SECRET; // your Secret-key
$nonce = time();
$uri = "https://bleutrade.com/api/v2/$method?apikey=$apikey&nonce=$nonce$params";
if (strpos($method,'public/') === FALSE && !strpos($method,'getdepositaddress'))
debuglog("bleutrade $method $params");
// if (strpos($method,'public/') === FALSE && !strpos($method,'getdepositaddress'))
// debuglog("bleutrade $method $params");
$sign = hash_hmac('sha512', $uri, $apisecret);
$ch = curl_init($uri);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("apisign:$sign"));
curl_setopt($ch, CURLOPT_ENCODING , 'gzip');
$execResult = curl_exec($ch);
$obj = json_decode($execResult);
$data = curl_exec($ch);
$obj = json_decode($data);
if(!is_object($obj)) debuglog("bleutrade: $method fail ".strip_tags($data).curl_error($ch));
curl_close($ch);
return $obj;
}

View file

@ -11,7 +11,7 @@ class CcexAPI
protected $api_url = 'https://c-cex.com/t/';
protected $api_key = EXCH_CCEX_KEY;
protected $api_secret = EXCH_CCEX_SECRET; // not used yet
protected $api_secret; // = EXCH_CCEX_SECRET; // not used yet
// public function __construct($api_key = '') {
// $this->api_key = $api_key;

View file

@ -5,6 +5,9 @@ function cryptsy_api_query($method, array $req = array())
// debuglog("calling cryptsy_api_query $method");
require_once('/etc/yiimp/keys.php');
if (!defined('EXCH_CRYPTSY_SECRET')) define('EXCH_CRYPTSY_SECRET', '');
if (empty(EXCH_CRYPTSY_KEY)) return FALSE;
// API settings
$key = EXCH_CRYPTSY_KEY; // your API-key

View file

@ -20,8 +20,12 @@ function empoex_api_query($method)
function empoex_api_user($method, $params = "")
{
require_once('/etc/yiimp/keys.php');
if (!defined('EXCH_EMPOEX_SECKEY')) define('EXCH_EMPOEX_SECKEY', '');
$api_key = EXCH_EMPOEX_SECKEY;
// optional secret key
if (empty(EXCH_EMPOEX_SECKEY) && strpos($method, 'public') === FALSE) return FALSE;
$api_key = EXCH_EMPOEX_SECKEY;
$url = "https://api.empoex.com/$method/$api_key/$params";

View file

@ -95,7 +95,7 @@ class poloniex {
}
public function generate_address($currency) {
debuglog("generate_address($currency)");
debuglog("poloniex: generate address $currency");
return $this->query(
array(
'command' => 'generateNewAddress',

View file

@ -17,3 +17,53 @@ function safecex_api_query($method, $params='')
return $obj;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
// https://safecex.com/api/getbalances (seems unavailable yet)
function safecex_api_user($method, $params='')
{
require_once('/etc/yiimp/keys.php');
if (!defined('EXCH_SAFECEX_SECRET')) define('EXCH_SAFECEX_SECRET', '');
if (empty(EXCH_SAFECEX_KEY) || empty(EXCH_SAFECEX_SECRET)) return false;
$apikey = EXCH_SAFECEX_KEY;
$nonce = time();
// $mt = explode(' ', microtime());
// $nonce = $mt[1].substr($mt[0], 2, 6);
$url = "https://safecex.com/api/$method?apikey=$apikey&nonce=$nonce$params";
$ch = curl_init($url);
$sign = hash_hmac('sha512', $url, EXCH_SAFECEX_SECRET);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("apisign:$sign"));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
//curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
//curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; Safecex PHP client; '.php_uname('s').'; PHP/'.phpversion().')');
curl_setopt($ch, CURLOPT_ENCODING , '');
$res = curl_exec($ch);
if($res === false)
{
$e = curl_error($ch);
debuglog("safecex: $e");
curl_close($ch);
return false;
}
$result = json_decode($res);
if(!is_object($result) && !is_array($result)) {
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
debuglog("safecex: $method failed ($status) $res");
}
curl_close($ch);
return $result;
}

View file

@ -30,8 +30,11 @@ function yobit_api_query($method)
function yobit_api_query2($method, $req = array())
{
require_once('/etc/yiimp/keys.php');
if (!defined('EXCH_YOBIT_SECRET')) define('EXCH_YOBIT_SECRET', '');
$api_key = EXCH_YOBIT_KEY;
if (empty(EXCH_YOBIT_SECRET)) return FALSE;
$api_key = EXCH_YOBIT_SECRET;
$api_secret = EXCH_YOBIT_SECRET;
$req['method'] = $method;

View file

@ -0,0 +1,29 @@
<?php
function doSafecexTrading($quick=false)
{
$flushall = rand(0, 4) == 0;
if($quick) $flushall = false;
$balances = safecex_api_user('getbalances'); //,'&symbol=BTC');
if(empty($balances)) return;
$savebalance = getdbosql('db_balances', "name='safecex'");
if (is_object($savebalance)) {
$savebalance->balance = 0;
if (is_array($balances)) foreach($balances as $balance)
{
if($balance->symbol == 'BTC') {
$savebalance->balance = $balance->balance;
$savebalance->save();
break;
}
}
}
if (!YAAMP_ALLOW_EXCHANGE) return;
// implement trade here...
}

View file

@ -9,3 +9,4 @@ require_once('empoex_trading.php');
require_once('yobit_trading.php');
require_once('alcurex_trading.php');
require_once('cryptopia_trading.php');
require_once('safecex_trading.php');

View file

@ -10,8 +10,8 @@ if (!defined('YAAMP_DBHOST')) define('YAAMP_DBHOST', 'localhost');
if (!defined('YAAMP_DBNAME')) define('YAAMP_DBNAME', 'yaamp');
if (!defined('YAAMP_DBUSER')) define('YAAMP_DBUSER', 'root');
if (!defined('YAAMP_DBPASSWORD')) define('YAAMP_DBPASSWORD', '');
if (!defined('YIIMP_MYSQLDUMP_USER')) define('YIIMP_MYSQLDUMP_USER', 'root');
if (!defined('YIIMP_MYSQLDUMP_PASS')) define('YIIMP_MYSQLDUMP_PASS', '');
//if (!defined('YIIMP_MYSQLDUMP_USER')) define('YIIMP_MYSQLDUMP_USER', 'root');
//if (!defined('YIIMP_MYSQLDUMP_PASS')) define('YIIMP_MYSQLDUMP_PASS', '');
if (!defined('YIIMP_PUBLIC_EXPLORER')) define('YIIMP_PUBLIC_EXPLORER', true);
@ -30,15 +30,6 @@ if (!defined('EXCH_POLONIEX_KEY')) define('EXCH_POLONIEX_KEY', '');
if (!defined('EXCH_SAFECEX_KEY')) define('EXCH_SAFECEX_KEY', '');
if (!defined('EXCH_YOBIT_KEY')) define('EXCH_YOBIT_KEY', '');
if (!defined('EXCH_BITTREX_SECRET')) define('EXCH_BITTREX_SECRET', '');
if (!defined('EXCH_BLEUTRADE_SECRET')) define('EXCH_BLEUTRADE_SECRET', '');
if (!defined('EXCH_CCEX_SECRET')) define('EXCH_CCEX_SECRET', '');
if (!defined('EXCH_CRYPTSY_SECRET')) define('EXCH_CRYPTSY_SECRET', '');
if (!defined('EXCH_EMPOEX_SECKEY')) define('EXCH_EMPOEX_SECKEY', '');
if (!defined('EXCH_POLONIEX_SECRET')) define('EXCH_POLONIEX_SECRET', '');
if (!defined('EXCH_SAFECEX_SECRET')) define('EXCH_SAFECEX_SECRET', '');
if (!defined('EXCH_YOBIT_SECRET')) define('EXCH_YOBIT_SECRET', '');
if (!defined('YAAMP_BTCADDRESS')) define('YAAMP_BTCADDRESS', '');
if (!defined('YAAMP_SITE_URL')) define('YAAMP_SITE_URL', 'localhost');
if (!defined('YAAMP_SITE_NAME')) define('YAAMP_SITE_NAME', 'YiiMP');

View file

@ -749,6 +749,11 @@ class SiteController extends CommonController
updateEmpoexMarkets();
break;
case 'safecex':
doSafecexTrading(true);
updateSafecexMarkets();
break;
case 'yobit':
doYobitTrading(true);
updateYobitMarkets();

View file

@ -139,6 +139,7 @@ class CronjobController extends CommonController
//doAlcurexTrading();
//doCryptopiaTrading();
doEmpoexTrading();
doSafecexTrading();
break;