diff --git a/sql/2018-01-stratums_ports.sql b/sql/2018-01-stratums_ports.sql new file mode 100644 index 0000000..d46ef7b --- /dev/null +++ b/sql/2018-01-stratums_ports.sql @@ -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`; + diff --git a/stratum/db.cpp b/stratum/db.cpp index 1b74e21..765a7dc 100644 --- a/stratum/db.cpp +++ b/stratum/db.cpp @@ -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"); diff --git a/web/keys.sample.php b/web/keys.sample.php index f4d4bd3..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', ''); @@ -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', ''); 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/backend/markets.php b/web/yaamp/core/backend/markets.php index cba8c8c..83c5b27 100644 --- a/web/yaamp/core/backend/markets.php +++ b/web/yaamp/core/backend/markets.php @@ -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; 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/site/common_results.php b/web/yaamp/modules/site/common_results.php index 3e3bc2a..3c25577 100644 --- a/web/yaamp/modules/site/common_results.php +++ b/web/yaamp/modules/site/common_results.php @@ -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 ''; echo ''; 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();