mirror of
https://github.com/LBRYFoundation/pool.git
synced 2025-09-18 00:19:43 +00:00
crex24: private api query, update balances
This commit is contained in:
parent
1c2a51394b
commit
c5b1a57be2
7 changed files with 129 additions and 0 deletions
|
@ -54,6 +54,7 @@ define('EXCH_CEXIO_ID', '');
|
||||||
define('EXCH_CEXIO_KEY', '');
|
define('EXCH_CEXIO_KEY', '');
|
||||||
define('EXCH_COINMARKETS_USER', '');
|
define('EXCH_COINMARKETS_USER', '');
|
||||||
define('EXCH_COINMARKETS_PIN', '');
|
define('EXCH_COINMARKETS_PIN', '');
|
||||||
|
define('EXCH_CREX24_KEY', '');
|
||||||
define('EXCH_BINANCE_KEY', '');
|
define('EXCH_BINANCE_KEY', '');
|
||||||
define('EXCH_BITSTAMP_ID','');
|
define('EXCH_BITSTAMP_ID','');
|
||||||
define('EXCH_BITSTAMP_KEY','');
|
define('EXCH_BITSTAMP_KEY','');
|
||||||
|
|
|
@ -174,6 +174,11 @@ class ExchangeCommand extends CConsoleCommand
|
||||||
if (!is_array($balances)) echo "coinsmarkets error ".json_encode($balances)."\n";
|
if (!is_array($balances)) echo "coinsmarkets error ".json_encode($balances)."\n";
|
||||||
else echo("coinsmarkets: ".json_encode($balances['return'])."\n");
|
else echo("coinsmarkets: ".json_encode($balances['return'])."\n");
|
||||||
}
|
}
|
||||||
|
if (!empty(EXCH_CREX24_KEY)) {
|
||||||
|
$balance = crex24_api_user('account/balance',array('currency'=>'BTC'));
|
||||||
|
if (!is_array($balance)) echo "crex24 error ".json_encode($balance)."\n";
|
||||||
|
else echo("crex24: ".json_encode($balance)."\n");
|
||||||
|
}
|
||||||
if (!empty(EXCH_CRYPTOPIA_KEY)) {
|
if (!empty(EXCH_CRYPTOPIA_KEY)) {
|
||||||
$balance = cryptopia_api_user('GetBalance',array("Currency"=>"BTC"));
|
$balance = cryptopia_api_user('GetBalance',array("Currency"=>"BTC"));
|
||||||
if (!is_object($balance)) echo("cryptopia error ".json_encode($balance)."\n");
|
if (!is_object($balance)) echo("cryptopia error ".json_encode($balance)."\n");
|
||||||
|
|
|
@ -24,3 +24,62 @@ function crex24_api_query($method, $params='', $returnType='object')
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function crex24_api_user($method, $url_params=array(), $json_body='')
|
||||||
|
{
|
||||||
|
require_once('/etc/yiimp/keys.php');
|
||||||
|
if (!defined('EXCH_CREX24_SECRET')) define('EXCH_CREX24_SECRET', '');
|
||||||
|
|
||||||
|
if (empty(EXCH_CREX24_KEY) || empty(EXCH_CREX24_SECRET)) return false;
|
||||||
|
|
||||||
|
$base = 'https://api.crex24.com';
|
||||||
|
$path = '/v2/'.$method;
|
||||||
|
|
||||||
|
if (!empty($url_params)) {
|
||||||
|
if (is_array($url_params)) {
|
||||||
|
$path .= '?'.http_build_query($url_params, '', '&');
|
||||||
|
} elseif (is_string($url_params)) {
|
||||||
|
$path .= '?'.$url_params;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$mt = explode(' ', microtime());
|
||||||
|
$nonce = $mt[1].substr($mt[0], 2, 6);
|
||||||
|
$sign = base64_encode(hash_hmac('sha512', $path.$nonce.$json_body, base64_decode(EXCH_CREX24_SECRET), true));
|
||||||
|
|
||||||
|
$headers = array(
|
||||||
|
'X-CREX24-API-KEY: '.EXCH_CREX24_KEY,
|
||||||
|
'X-CREX24-API-NONCE: '.$nonce,
|
||||||
|
'X-CREX24-API-SIGN: '.$sign,
|
||||||
|
);
|
||||||
|
|
||||||
|
$uri = $base.$path;
|
||||||
|
|
||||||
|
$ch = curl_init($uri);
|
||||||
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||||
|
if (!empty($json_body)) {
|
||||||
|
curl_setopt($ch, CURLOPT_POST, 1);
|
||||||
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_body);
|
||||||
|
}
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
//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; crex24 API client; '.php_uname('s').'; PHP/'.PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION.')');
|
||||||
|
curl_setopt($ch, CURLOPT_ENCODING , '');
|
||||||
|
|
||||||
|
$data = curl_exec($ch);
|
||||||
|
$res = json_decode($data);
|
||||||
|
unset($headers);
|
||||||
|
|
||||||
|
if(empty($res)) {
|
||||||
|
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||||
|
debuglog("crex24: $method failed ($status) ".strip_data($data).' '.curl_error($ch));
|
||||||
|
}
|
||||||
|
|
||||||
|
curl_close($ch);
|
||||||
|
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
53
web/yaamp/core/trading/crex24_trading.php
Normal file
53
web/yaamp/core/trading/crex24_trading.php
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
function doCrex24CancelOrder($OrderID=false)
|
||||||
|
{
|
||||||
|
if(!$OrderID) return;
|
||||||
|
|
||||||
|
// todo
|
||||||
|
}
|
||||||
|
|
||||||
|
function doCrex24Trading($quick=false)
|
||||||
|
{
|
||||||
|
$exchange = 'crex24';
|
||||||
|
$updatebalances = true;
|
||||||
|
|
||||||
|
if (exchange_get($exchange, 'disabled')) return;
|
||||||
|
|
||||||
|
$data = crex24_api_user('account/balance','nonZeroOnly=false');
|
||||||
|
if (!is_array($data) || empty($data)) return;
|
||||||
|
|
||||||
|
$savebalance = getdbosql('db_balances', "name='$exchange'");
|
||||||
|
|
||||||
|
foreach($data as $balance)
|
||||||
|
{
|
||||||
|
if ($balance->currency == 'BTC') {
|
||||||
|
if (is_object($savebalance)) {
|
||||||
|
$savebalance->balance = $balance->available;
|
||||||
|
$savebalance->onsell = $balance->reserved;
|
||||||
|
$savebalance->save();
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($updatebalances) {
|
||||||
|
// store available balance in market table
|
||||||
|
$coins = getdbolist('db_coins', "symbol=:symbol OR symbol2=:symbol",
|
||||||
|
array(':symbol'=>$balance->currency)
|
||||||
|
);
|
||||||
|
if (empty($coins)) continue;
|
||||||
|
foreach ($coins as $coin) {
|
||||||
|
$market = getdbosql('db_markets', "coinid=:coinid AND name='$exchange'", array(':coinid'=>$coin->id));
|
||||||
|
if (!$market) continue;
|
||||||
|
$market->balance = $balance->available;
|
||||||
|
$market->ontrade = $balance->reserved;
|
||||||
|
$market->balancetime = time();
|
||||||
|
$market->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!YAAMP_ALLOW_EXCHANGE) return;
|
||||||
|
|
||||||
|
// real trading, todo..
|
||||||
|
}
|
|
@ -9,6 +9,7 @@ require_once('kraken_trading.php');
|
||||||
require_once('yobit_trading.php');
|
require_once('yobit_trading.php');
|
||||||
require_once('alcurex_trading.php');
|
require_once('alcurex_trading.php');
|
||||||
require_once('coinsmarkets_trading.php');
|
require_once('coinsmarkets_trading.php');
|
||||||
|
require_once('crex24_trading.php');
|
||||||
require_once('cryptopia_trading.php');
|
require_once('cryptopia_trading.php');
|
||||||
require_once('hitbtc_trading.php');
|
require_once('hitbtc_trading.php');
|
||||||
require_once('kucoin_trading.php');
|
require_once('kucoin_trading.php');
|
||||||
|
@ -36,6 +37,9 @@ function cancelExchangeOrder($order=false)
|
||||||
case 'bleutrade':
|
case 'bleutrade':
|
||||||
doBleutradeCancelOrder($order->uuid);
|
doBleutradeCancelOrder($order->uuid);
|
||||||
break;
|
break;
|
||||||
|
case 'crex24':
|
||||||
|
doCrex24CancelOrder($order->uuid);
|
||||||
|
break;
|
||||||
case 'cryptopia':
|
case 'cryptopia':
|
||||||
doCryptopiaCancelOrder($order->uuid);
|
doCryptopiaCancelOrder($order->uuid);
|
||||||
break;
|
break;
|
||||||
|
@ -73,6 +77,11 @@ function runExchange($exchangeName=false)
|
||||||
updateBterMarkets();
|
updateBterMarkets();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'crex24':
|
||||||
|
doCrex24Trading(true);
|
||||||
|
updateCrex24Markets();
|
||||||
|
break;
|
||||||
|
|
||||||
case 'cryptopia':
|
case 'cryptopia':
|
||||||
doCryptopiaTrading(true);
|
doCryptopiaTrading(true);
|
||||||
updateCryptopiaMarkets();
|
updateCryptopiaMarkets();
|
||||||
|
|
|
@ -35,6 +35,7 @@ if (!defined('EXCH_BTER_KEY')) define('EXCH_BTER_KEY', '');
|
||||||
if (!defined('EXCH_CCEX_KEY')) define('EXCH_CCEX_KEY', '');
|
if (!defined('EXCH_CCEX_KEY')) define('EXCH_CCEX_KEY', '');
|
||||||
if (!defined('EXCH_CEXIO_ID')) define('EXCH_CEXIO_ID', '');
|
if (!defined('EXCH_CEXIO_ID')) define('EXCH_CEXIO_ID', '');
|
||||||
if (!defined('EXCH_CEXIO_KEY')) define('EXCH_CEXIO_KEY', '');
|
if (!defined('EXCH_CEXIO_KEY')) define('EXCH_CEXIO_KEY', '');
|
||||||
|
if (!defined('EXCH_CREX24_KEY')) define('EXCH_CREX24_KEY', '');
|
||||||
if (!defined('EXCH_CRYPTOPIA_KEY')) define('EXCH_CRYPTOPIA_KEY', '');
|
if (!defined('EXCH_CRYPTOPIA_KEY')) define('EXCH_CRYPTOPIA_KEY', '');
|
||||||
if (!defined('EXCH_HITBTC_KEY')) define('EXCH_HITBTC_KEY', '');
|
if (!defined('EXCH_HITBTC_KEY')) define('EXCH_HITBTC_KEY', '');
|
||||||
if (!defined('EXCH_POLONIEX_KEY')) define('EXCH_POLONIEX_KEY', '');
|
if (!defined('EXCH_POLONIEX_KEY')) define('EXCH_POLONIEX_KEY', '');
|
||||||
|
|
|
@ -129,6 +129,7 @@ class CronjobController extends CommonController
|
||||||
getBitstampBalances();
|
getBitstampBalances();
|
||||||
getCexIoBalances();
|
getCexIoBalances();
|
||||||
doBittrexTrading();
|
doBittrexTrading();
|
||||||
|
doCrex24Trading();
|
||||||
doCryptopiaTrading();
|
doCryptopiaTrading();
|
||||||
doKrakenTrading();
|
doKrakenTrading();
|
||||||
doLiveCoinTrading();
|
doLiveCoinTrading();
|
||||||
|
|
Loading…
Add table
Reference in a new issue