yiimp: add exchange command, for private api tests

This commit is contained in:
Tanguy Pruvot 2016-01-15 15:54:21 +01:00
parent b54a5c8102
commit ea8abb3032
3 changed files with 105 additions and 5 deletions

View file

@ -6,7 +6,7 @@
* *
* To use this command, enter the following on the command line: * To use this command, enter the following on the command line:
* <pre> * <pre>
* php protected/yiic.php checkup * php web/yaamp/yiic.php checkup
* </pre> * </pre>
* *
* @property string $help The command description. * @property string $help The command description.
@ -31,8 +31,8 @@ class CheckupCommand extends CConsoleCommand
if (isset($args[0])) { if (isset($args[0])) {
echo "Yii checkup command\n"; echo "Yiimp checkup command\n";
echo "Usage: yiic checkup\n"; echo "Usage: yiimp checkup\n";
return 1; return 1;
} else { } else {
@ -44,7 +44,7 @@ class CheckupCommand extends CConsoleCommand
self::autolinkCoinsImages(); self::autolinkCoinsImages();
if (YAAMP_ALLOW_EXCHANGE == false) if (!YAAMP_ALLOW_EXCHANGE)
self::cleanUserBalancesBTC(); self::cleanUserBalancesBTC();
echo "ok\n"; echo "ok\n";

View file

@ -0,0 +1,100 @@
<?php
/**
* ExchangeCommand is a console command, to check private apis keys
*
* To use this command, enter the following on the command line:
* <pre>
* php web/yaamp/yiic.php exchange test
* </pre>
*
* @property string $help The command description.
*
*/
class ExchangeCommand extends CConsoleCommand
{
protected $basePath;
/**
* Execute the action.
* @param array $args command line parameters specific for this command
* @return integer non zero application exit code after printing help
*/
public function run($args)
{
$runner=$this->getCommandRunner();
$commands=$runner->commands;
$root = realpath(Yii::app()->getBasePath().DIRECTORY_SEPARATOR.'..');
$this->basePath = str_replace(DIRECTORY_SEPARATOR, '/', $root);
if (!isset($args[0])) {
echo "Yiimp exchange command\n";
echo "Usage: yiimp exchange test\n";
return 1;
} else if ($args[0] == 'test') {
$this->testApiKeys();
echo "ok\n";
return 0;
}
}
/**
* Provides the command description.
* @return string the command description.
*/
public function getHelp()
{
return parent::getHelp().'exchange';
}
public function testApiKeys()
{
require_once($this->basePath.'/yaamp/core/core.php');
if (!empty(EXCH_BITTREX_KEY)) {
$balance = bittrex_api_query('account/getbalance','&currency=BTC');
echo("bittrex btc: ".json_encode($balance->result)."\n");
}
if (!empty(EXCH_BLEUTRADE_KEY)) {
$balance = bleutrade_api_query('account/getbalances','&currencies=BTC');
echo("bleutrade btc: ".json_encode($balance->result)."\n");
}
if (!empty(EXCH_CCEX_KEY)) {
$ccex = new CcexAPI;
$balances = $ccex->getBalance();
if(!$balances || !isset($balances['return'])) echo "error\n";
else echo("c-cex btc: ".json_encode($balances['return'][1])."\n");
}
if (!empty(EXCH_CRYPTOPIA_KEY)) {
$balance = cryptopia_api_user('GetBalance',array("Currency"=>"BTC"));
echo("cryptopia btc: ".json_encode($balance->Data)."\n");
}
if (!empty(EXCH_CRYPTSY_KEY)) {
$info = cryptsy_api_query('getinfo');
if (!arraySafeVal($info,'success',0) || !is_array($info['return'])) echo "error\n";
else echo("cryptsy btc: ".json_encode($info['return']['balances_available']['BTC'])."\n");
}
if(!empty(EXCH_POLONIEX_KEY)) {
$poloniex = new poloniex;
$balance = $poloniex->get_available_balances();
echo("poloniex available : ".json_encode($balance)."\n");
}
if (!empty(EXCH_SAFECEX_KEY)) {
$balance = safecex_api_user('getbalance', "&symbol=BTC");
echo("safecex btc: ".json_encode($balance)."\n");
}
if (!empty(EXCH_YOBIT_KEY)) {
$info = yobit_api_query2('getInfo');
if (!arraySafeVal($info,'success',0) || !is_array($info['return'])) echo "error\n";
else echo("yobit btc: ".json_encode($info['return']['funds']['btc'])."\n");
}
// only one secret key
$balance = empoex_api_user('account/balance','BTC');
if ($balance) echo("empoex btc: ".json_encode($balance['available'])."\n");
}
}

View file

@ -8,7 +8,7 @@ function doEmpoexTrading($quick=false)
$balances = empoex_api_user('account/balance','BTC'); $balances = empoex_api_user('account/balance','BTC');
// {"available":[{"Coin":"BTC","Amount":"0.00102293"}],"pending":[],"held":[]} // {"available":[{"Coin":"BTC","Amount":"0.00102293"}],"pending":[],"held":[]}
if(!$balances || !isset($balances->available) || empty($balances->available)) return; if(!$balances || !isset($balances->available) || empty($balances->available)) return;
$savebalance = getdbosql('db_balances', "name='empoex'"); $savebalance = getdbosql('db_balances', "name='empoex'");
$savebalance->balance = 0; $savebalance->balance = 0;