mirror of
https://github.com/LBRYFoundation/pool.git
synced 2025-09-20 18:09:54 +00:00
add banx private api (v3) support
get deposit addresses...
This commit is contained in:
parent
ea8abb3032
commit
a81493224d
10 changed files with 136 additions and 4 deletions
|
@ -8,6 +8,7 @@ define('YIIMP_MYSQLDUMP_PASS', '<my_mysql_password>');
|
|||
define('EXCH_BITTREX_SECRET', '<my_bittrex_api_secret_key>');
|
||||
define('EXCH_CRYPTOPIA_SECRET', '');
|
||||
define('EXCH_CRYPTSY_SECRET', '');
|
||||
define('EXCH_BANX_SECKEY', '');
|
||||
define('EXCH_BLEUTRADE_SECRET', '');
|
||||
define('EXCH_CCEX_SECRET', '');
|
||||
define('EXCH_EMPOEX_SECKEY', '');
|
||||
|
|
|
@ -41,6 +41,7 @@ define('EXCH_BLEUTRADE_KEY', '');
|
|||
define('EXCH_YOBIT_KEY', '');
|
||||
define('EXCH_CCEX_KEY', '');
|
||||
define('EXCH_SAFECEX_KEY', '');
|
||||
define('EXCH_BANX_USERNAME', '');
|
||||
|
||||
// Automatic withdraw to Yaamp btc wallet if btc balance > 0.3
|
||||
define('EXCH_AUTO_WITHDRAW', 0.3);
|
||||
|
|
|
@ -92,6 +92,11 @@ class ExchangeCommand extends CConsoleCommand
|
|||
if (!arraySafeVal($info,'success',0) || !is_array($info['return'])) echo "error\n";
|
||||
else echo("yobit btc: ".json_encode($info['return']['funds']['btc'])."\n");
|
||||
}
|
||||
if (!empty(EXCH_BANX_USERNAME)) {
|
||||
//$balance = banx_api_user('account/getbalance','?currency=BTC');
|
||||
$balance = banx_api_user('account/getbalances');
|
||||
echo("banx all: ".json_encode($balance->result)."\n");
|
||||
}
|
||||
|
||||
// only one secret key
|
||||
$balance = empoex_api_user('account/balance','BTC');
|
||||
|
|
|
@ -745,8 +745,10 @@ function updateBanxioMarkets()
|
|||
$data = banx_public_api_query('getmarketsummaries');
|
||||
if(!$data || !is_array($data->result)) return;
|
||||
|
||||
$list = getdbolist('db_markets', "name='banx'");
|
||||
foreach($list as $market)
|
||||
$symbols = array();
|
||||
|
||||
$currencies = getdbolist('db_markets', "name='banx'");
|
||||
foreach($currencies as $market)
|
||||
{
|
||||
$coin = getdbo('db_coins', $market->coinid);
|
||||
if(!$coin || !$coin->installed) continue;
|
||||
|
@ -767,12 +769,54 @@ function updateBanxioMarkets()
|
|||
if ($coin->name == 'unknown' && !empty($ticker->currencylong)) {
|
||||
$coin->name = $ticker->currencylong;
|
||||
$coin->save();
|
||||
debuglog("banx: update $symbol name {$coin->name}");
|
||||
debuglog("$exchange: update $symbol label {$coin->name}");
|
||||
}
|
||||
// store for deposit addresses
|
||||
$symbols[$ticker->currencylong] = $coin->symbol;
|
||||
$symbols[$ticker->partnerlong] = $coin->symbol;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!empty(EXCH_BANX_USERNAME))
|
||||
{
|
||||
// deposit addresses
|
||||
$last_checked = cache()->get($exchange.'-deposit_address-check');
|
||||
if (!$last_checked) {
|
||||
// no coin symbols in the results wtf ! only labels :/
|
||||
$query = banx_api_user('account/getdepositaddresses');
|
||||
}
|
||||
if (!isset($query)) return;
|
||||
if (!is_object($query)) return;
|
||||
if (!$query->success || !is_array($query->result)) return;
|
||||
|
||||
foreach($query->result as $account)
|
||||
{
|
||||
if (!isset($account->currency) || !isset($account->address)) continue;
|
||||
if (empty($account->currency) || empty($account->address)) continue;
|
||||
|
||||
$label = $account->currency;
|
||||
if (!isset($symbols[$label])) continue;
|
||||
|
||||
$symbol = $symbols[$label];
|
||||
|
||||
if($symbol == 'BTC') continue;
|
||||
|
||||
$coin = getdbosql('db_coins', "symbol=:symbol", array(':symbol'=>$symbol));
|
||||
if(!$coin) continue;
|
||||
|
||||
$market = getdbosql('db_markets', "coinid={$coin->id} and name='$exchange'");
|
||||
if(!$market) continue;
|
||||
|
||||
if ($market->deposit_address != $account->address) {
|
||||
$market->deposit_address = $account->address;
|
||||
$market->save();
|
||||
debuglog("$exchange: deposit address for $symbol updated");
|
||||
}
|
||||
}
|
||||
cache()->set($exchange.'-deposit_address-check', time(), 12*3600);
|
||||
}
|
||||
}
|
||||
|
||||
function updateSafecexMarkets()
|
||||
|
|
|
@ -33,3 +33,49 @@ function banx_public_api_query($method, $params='')
|
|||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
// methods ok getbalances
|
||||
// method failed getbalance "?currency=BTC"
|
||||
|
||||
function banx_api_user($method, $params='')
|
||||
{
|
||||
require_once('/etc/yiimp/keys.php');
|
||||
if (!defined('EXCH_BANX_SECKEY')) define('EXCH_BANX_SECKEY', '');
|
||||
|
||||
if (empty(EXCH_BANX_USERNAME) || empty(EXCH_BANX_SECKEY)) return false;
|
||||
|
||||
$uri = "https://www.banx.io/api/v3/$method$params";
|
||||
|
||||
//$nonce = time();
|
||||
$mt = explode(' ', microtime());
|
||||
$nonce = $mt[1].substr($mt[0], 2, 6);
|
||||
|
||||
$headers = array(
|
||||
'Content-Type: application/json; charset=utf-8',
|
||||
'uts: '.$nonce,
|
||||
'uid: '.EXCH_BANX_USERNAME,
|
||||
'aut: '.EXCH_BANX_SECKEY,
|
||||
);
|
||||
|
||||
$ch = curl_init($uri);
|
||||
curl_setopt($ch, CURLOPT_POST, 0);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
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_USERAGENT, 'Mozilla/4.0 (compatible; Banx API PHP client; '.php_uname('s').'; PHP/'.phpversion().')');
|
||||
curl_setopt($ch, CURLOPT_ENCODING , '');
|
||||
|
||||
$data = curl_exec($ch);
|
||||
$res = json_decode($data);
|
||||
|
||||
if(!is_object($res) || !$res->success) {
|
||||
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
debuglog("banx: $method failed ($status) ".strip_tags($data).' '.curl_error($ch));
|
||||
}
|
||||
|
||||
curl_close($ch);
|
||||
|
||||
return $res;
|
||||
}
|
26
web/yaamp/core/trading/banx_trading.php
Normal file
26
web/yaamp/core/trading/banx_trading.php
Normal file
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
function doBanxTrading($quick=false)
|
||||
{
|
||||
$flushall = rand(0, 4) == 0;
|
||||
if($quick) $flushall = false;
|
||||
|
||||
$balances = banx_api_user('account/getbalances');
|
||||
if(!$balances || !isset($balances->result) || !$balances->success) return;
|
||||
|
||||
$savebalance = getdbosql('db_balances', "name='banx'");
|
||||
if (!is_object($savebalance)) return;
|
||||
|
||||
$savebalance->balance = 0;
|
||||
|
||||
foreach($balances->result as $balance)
|
||||
{
|
||||
if($balance->currency == 'BTC') {
|
||||
$savebalance->balance = $balance->available;
|
||||
$savebalance->save();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!YAAMP_ALLOW_EXCHANGE) return;
|
||||
}
|
|
@ -8,5 +8,7 @@ require_once('c-cex_trading.php');
|
|||
require_once('empoex_trading.php');
|
||||
require_once('yobit_trading.php');
|
||||
require_once('alcurex_trading.php');
|
||||
require_once('banx_trading.php');
|
||||
require_once('cryptopia_trading.php');
|
||||
require_once('safecex_trading.php');
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ if (!defined('EXCH_CRYPTOPIA_KEY')) define('EXCH_CRYPTOPIA_KEY', '');
|
|||
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_BANX_USERNAME')) define('EXCH_BANX_USERNAME', '');
|
||||
|
||||
if (!defined('YAAMP_BTCADDRESS')) define('YAAMP_BTCADDRESS', '');
|
||||
if (!defined('YAAMP_SITE_URL')) define('YAAMP_SITE_URL', 'localhost');
|
||||
|
|
|
@ -724,8 +724,13 @@ class SiteController extends CommonController
|
|||
updateAlcurexMarkets();
|
||||
break;
|
||||
|
||||
case 'banx':
|
||||
doBanxTrading(true);
|
||||
updateBanxMarkets();
|
||||
break;
|
||||
|
||||
case 'cryptopia':
|
||||
//doCryptopiaTrading(true);
|
||||
doCryptopiaTrading(true);
|
||||
updateCryptopiaMarkets();
|
||||
break;
|
||||
|
||||
|
|
|
@ -137,6 +137,7 @@ class CronjobController extends CommonController
|
|||
doYobitTrading();
|
||||
doCCexTrading();
|
||||
//doAlcurexTrading();
|
||||
doBanxTrading();
|
||||
doCryptopiaTrading();
|
||||
doEmpoexTrading();
|
||||
doSafecexTrading();
|
||||
|
|
Loading…
Add table
Reference in a new issue