Merge pull request #3 from tpruvot/next

Update for Lbrypool from Yiimp
This commit is contained in:
oakey22 2018-01-05 19:59:16 +00:00 committed by GitHub
commit 3712ac2e84
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 171 additions and 6 deletions

View file

@ -0,0 +1,17 @@
-- Recent additions to add after db init (.gz)
-- mysql yaamp -p < file.sql
-- filled by the stratum instance, to allow to handle/watch multiple instances
ALTER TABLE `stratums` ADD `started` int(11) UNSIGNED NULL AFTER `time`;
ALTER TABLE `stratums` ADD `workers` int(10) UNSIGNED NOT NULL DEFAULT '0' AFTER `algo`;
ALTER TABLE `stratums` ADD `port` int(6) UNSIGNED NULL AFTER `workers`;
ALTER TABLE `stratums` ADD `symbol` varchar(16) NULL AFTER `port`;
ALTER TABLE `stratums` ADD `url` varchar(128) NULL AFTER `symbol`;
ALTER TABLE `stratums` ADD `fds` int(10) UNSIGNED NOT NULL DEFAULT '0' AFTER `url`;

View file

@ -87,12 +87,17 @@ void db_register_stratum(YAAMP_DB *db)
int t = time(NULL);
if(!db) return;
db_query(db, "insert into stratums (pid, time, algo) values (%d, %d, '%s') on duplicate key update time=%d",
pid, t, g_current_algo->name, t);
db_query(db, "INSERT INTO stratums (pid, time, started, algo, port) VALUES (%d, %d, %d, '%s', %d) "
" ON DUPLICATE KEY UPDATE time=%d, algo='%s', port=%d",
pid, t, t, g_stratum_algo, g_tcp_port,
t, g_stratum_algo, g_tcp_port
);
}
void db_update_algos(YAAMP_DB *db)
{
int pid = getpid();
//int fds = 0; // todo, sample: ls -l /proc/$PID/fd | grep socket | grep -c .
if(!db) return;
if(g_current_algo->overflow)
@ -100,9 +105,20 @@ void db_update_algos(YAAMP_DB *db)
debuglog("setting overflow\n");
g_current_algo->overflow = false;
db_query(db, "update algos set overflow=true where name='%s'", g_current_algo->name);
db_query(db, "UPDATE algos SET overflow=true WHERE name='%s'", g_stratum_algo);
}
char symbol[16] = "NULL\0";
if(g_list_coind.count == 1) {
if (g_list_coind.first) {
CLI li = g_list_coind.first;
YAAMP_COIND *coind = (YAAMP_COIND *)li->data;
sprintf(symbol,"'%s'", coind->symbol);
}
}
db_query(db, "UPDATE stratums SET workers=%d, symbol=%s WHERE pid=%d", g_list_client.count, symbol, pid);
///////////////////////////////////////////////////////////////////////////////////////////
db_query(db, "select name, profit, rent, factor from algos");

View file

@ -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', '');
@ -18,5 +19,6 @@ define('EXCH_KRAKEN_SECRET','');
define('EXCH_LIVECOIN_SECRET', '');
define('EXCH_NOVA_SECRET','');
define('EXCH_POLONIEX_SECRET', '');
define('EXCH_STOCKSEXCHANGE_SECRET', '');
define('EXCH_YOBIT_SECRET', '');

View file

@ -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','&currency=BTC');
if (!is_object($balance)) echo "bittrex error\n";

View file

@ -1271,6 +1271,17 @@ function updateCoinExchangeMarkets()
continue;
}
if($currency->Active && $coin->enable) {
// check wallet status (deposit/withdrawals)
$status = coinexchange_api_query('getcurrency', 'ticker_code='.$symbol);
if(is_object($status) && is_object($status->result)) {
$res = $status->result;
if($market->disabled < 9) $market->disabled = (objSafeVal($res,'WalletStatus') == "offline");
$market->message = $market->disabled ? $res->WalletStatus : '';
//debuglog("$exchange: $symbol wallet is {$res->WalletStatus}");
}
}
$market->save();
if($market->disabled || $market->deleted) continue;

View file

@ -0,0 +1,107 @@
<?php
// cex.io api queries - tpruvot 2018
// see https://cex.io/rest-api for the methods
function cexio_api_query($method, $params='')
{
$url = "https://cex.io/api/$method/";
if (!empty($params)) $url .= "$params";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_USERAGENT, 'PHP API');
//curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$execResult = curl_exec($ch);
$res = json_decode($execResult, true);
return $res;
}
function cexio_api_user($method, $params=array())
{
require_once('/etc/yiimp/keys.php');
if (!defined('EXCH_CEXIO_KEY')) return false;
if (!defined('EXCH_CEXIO_SECRET')) return false;
if (!defined('EXCH_CEXIO_ID')) return false;
$username = EXCH_CEXIO_ID;
$apikey = EXCH_CEXIO_KEY; // your API-key
$apisecret = EXCH_CEXIO_SECRET; // your Secret-key
if (empty($username) || empty($apikey) || empty($apisecret)) return false;
$mt = explode(' ', microtime());
$nonce = $mt[1].substr($mt[0], 2, 6);
$nonce = $mt[1];
$msg = "{$nonce}{$username}{$apikey}";
$sha = hash_hmac('sha256', $msg, $apisecret);
$sign = strtoupper($sha);
$url = "https://cex.io/api/$method/";
$postdata = array(
'key' => $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();
}
}
}

View file

@ -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')

View file

@ -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', '');

View file

@ -120,10 +120,11 @@ foreach($algos as $item)
$fees = yaamp_fee($algo);
$stratum = getdbosql('db_stratums', "algo=:algo", array(':algo'=>$algo));
// todo: show per port data ?
$stratum = getdbosql('db_stratums', "algo=:algo ORDER BY started DESC", array(':algo'=>$algo));
$isup = Booltoa($stratum);
$time = $isup ? datetoa2($stratum->time) : '';
$ts = $isup ? datetoa2($stratum->time) : '';
$time = $isup ? datetoa2($stratum->started) : '';
$ts = $isup ? datetoa2($stratum->started) : '';
echo '<tr class="ssrow">';
echo '<td style="background-color: '.$algo_color.'"><b>';

View file

@ -132,6 +132,7 @@ class CronjobController extends CommonController
if(!YAAMP_PRODUCTION) break;
getBitstampBalances();
getCexIoBalances();
doBittrexTrading();
doCryptopiaTrading();
doKrakenTrading();