diff --git a/web/keys.sample.php b/web/keys.sample.php index b65f839..da2034f 100644 --- a/web/keys.sample.php +++ b/web/keys.sample.php @@ -10,6 +10,7 @@ define('EXCH_BITSTAMP_SECRET',''); define('EXCH_BLEUTRADE_SECRET', ''); define('EXCH_BTER_SECRET', ''); define('EXCH_CCEX_SECRET', ''); +define('EXCH_CEXIO_SECRET', ''); define('EXCH_COINMARKETS_PASS', ''); define('EXCH_CRYPTOPIA_SECRET', ''); define('EXCH_EMPOEX_SECKEY', ''); diff --git a/web/yaamp/commands/ExchangeCommand.php b/web/yaamp/commands/ExchangeCommand.php index 6ac6905..15f143f 100644 --- a/web/yaamp/commands/ExchangeCommand.php +++ b/web/yaamp/commands/ExchangeCommand.php @@ -127,6 +127,11 @@ class ExchangeCommand extends CConsoleCommand if (!is_array($balance)) echo "bitstamp error ".json_encode($balance)."\n"; else echo("bitstamp: ".json_encode($balance)."\n"); } + if (!empty(EXCH_CEXIO_KEY)) { + $balance = cexio_api_user('balance'); + if (!is_array($balance)) echo "cexio error ".json_encode($balance)."\n"; + else echo("cexio: ".json_encode(arraySafeVal($balance,"BTC",$balance))."\n"); + } if (!empty(EXCH_BITTREX_KEY)) { $balance = bittrex_api_query('account/getbalance','¤cy=BTC'); if (!is_object($balance)) echo "bittrex error\n"; diff --git a/web/yaamp/core/exchange/cexio.php b/web/yaamp/core/exchange/cexio.php new file mode 100644 index 0000000..243a4b6 --- /dev/null +++ b/web/yaamp/core/exchange/cexio.php @@ -0,0 +1,107 @@ + $apikey, + 'signature' => $sign, + 'nonce' => $nonce + ); + + if (!empty($params)) { + foreach($params as $k=>$v) $postdata[$k] = $v; + } + + $post_data = http_build_query($postdata, '', '&'); + + $ch = curl_init($url); + + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); + //curl_setopt($ch, CURLOPT_SSLVERSION, 1 /*CURL_SSLVERSION_TLSv1*/); + curl_setopt($ch, CURLOPT_SSL_SESSIONID_CACHE, 0); + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); + curl_setopt($ch, CURLOPT_TIMEOUT, 30); + curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; cex.io API PHP client; '.php_uname('s').'; PHP/'.phpversion().')'); + curl_setopt($ch, CURLOPT_ENCODING , ''); + + $execResult = curl_exec($ch); + $res = json_decode($execResult, true); + + return $res; +} + +// https://cex.io/rest-api#ticker + +function cexio_btceur() +{ + $ticker = cexio_api_query('ticker', 'BTC/EUR'); + return is_array($ticker) ? floatval($ticker["last"]) : false; +} + +function cexio_btcusd() +{ + $ticker = cexio_api_query('ticker', 'BTC/USD'); + return is_array($ticker) ? floatval($ticker["last"]) : false; +} + +// https://cex.io/rest-api#account-balance + +function getCexIoBalances() +{ + $exchange = 'cexio'; + if (exchange_get($exchange, 'disabled')) return; + + $savebalance = getdbosql('db_balances', "name='$exchange'"); + if (is_object($savebalance)) { + $balances = cexio_api_user('balance'); + if (is_array($balances)) { + $b = arraySafeVal($balances, 'BTC'); + $savebalance->balance = arraySafeVal($b, 'available'); + $savebalance->save(); + } + } +} diff --git a/web/yaamp/core/exchange/exchange.php b/web/yaamp/core/exchange/exchange.php index 431999d..b690f83 100644 --- a/web/yaamp/core/exchange/exchange.php +++ b/web/yaamp/core/exchange/exchange.php @@ -18,6 +18,7 @@ require_once("bitstamp.php"); require_once("bittrex.php"); require_once("ccexapi.php"); require_once("bleutrade.php"); +require_once("cexio.php"); require_once("kraken.php"); require_once("yobit.php"); require_once("shapeshift.php"); @@ -82,6 +83,8 @@ function getMarketUrl($coin, $marketName) $url = "https://bleutrade.com/exchange/{$symbol}/{$base}"; else if($market == 'bter') $url = "https://bter.com/trade/{$lowsymbol}_{$lowbase}"; + else if($market == 'cexio') + $url = "https://cex.io/trade/{$symbol}-{$base}"; else if($market == 'coinexchange') $url = "https://www.coinexchange.io/market/{$symbol}/{$base}"; else if($market == 'coinsmarkets') diff --git a/web/yaamp/defaultconfig.php b/web/yaamp/defaultconfig.php index 3bb0e71..c260f44 100644 --- a/web/yaamp/defaultconfig.php +++ b/web/yaamp/defaultconfig.php @@ -32,6 +32,8 @@ if (!defined('EXCH_BITSTAMP_KEY')) define('EXCH_BITSTAMP_KEY',''); if (!defined('EXCH_BLEUTRADE_KEY')) define('EXCH_BLEUTRADE_KEY', ''); if (!defined('EXCH_BTER_KEY')) define('EXCH_BTER_KEY', ''); if (!defined('EXCH_CCEX_KEY')) define('EXCH_CCEX_KEY', ''); +if (!defined('EXCH_CEXIO_ID')) define('EXCH_CEXIO_ID', ''); +if (!defined('EXCH_CEXIO_KEY')) define('EXCH_CEXIO_KEY', ''); if (!defined('EXCH_CRYPTOPIA_KEY')) define('EXCH_CRYPTOPIA_KEY', ''); if (!defined('EXCH_HITBTC_KEY')) define('EXCH_HITBTC_KEY', ''); if (!defined('EXCH_POLONIEX_KEY')) define('EXCH_POLONIEX_KEY', ''); diff --git a/web/yaamp/modules/thread/CronjobController.php b/web/yaamp/modules/thread/CronjobController.php index 17f2172..b6bd7db 100644 --- a/web/yaamp/modules/thread/CronjobController.php +++ b/web/yaamp/modules/thread/CronjobController.php @@ -132,6 +132,7 @@ class CronjobController extends CommonController if(!YAAMP_PRODUCTION) break; getBitstampBalances(); + getCexIoBalances(); doBittrexTrading(); doCryptopiaTrading(); doKrakenTrading();