mirror of
https://github.com/LBRYFoundation/pool.git
synced 2025-09-23 20:00:42 +00:00
markets: handle most other exchanges tickers
This commit is contained in:
parent
93c785b45a
commit
a2aaf2b9e0
7 changed files with 184 additions and 3 deletions
|
@ -1112,7 +1112,11 @@ function updateCoinExchangeMarkets()
|
|||
$coin = getdbosql('db_coins', "symbol=:sym", array(':sym'=>$symbol));
|
||||
if(!$coin) continue;
|
||||
|
||||
$market = getdbosql('db_markets', "coinid={$coin->id} AND name='$exchange'");
|
||||
$market = getdbosql('db_markets', "coinid={$coin->id} AND name='$exchange' AND IFNULL(base_coin,'') IN ('','BTC')");
|
||||
$base = objSafeVal($currency,'BaseCurrencyCode','');
|
||||
if ($base != 'BTC') {
|
||||
$market = getdbosql('db_markets', "coinid={$coin->id} AND name='$exchange' AND base_coin=:base", array(':base'=>$base));
|
||||
}
|
||||
if(!$market) continue;
|
||||
|
||||
$symbol = $coin->getOfficialSymbol();
|
||||
|
|
|
@ -47,3 +47,44 @@ function bleutrade_api_query($method, $params='')
|
|||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// manual update of one market
|
||||
function bleutrade_update_market($market)
|
||||
{
|
||||
$exchange = 'bleutrade';
|
||||
if (is_string($market))
|
||||
{
|
||||
$symbol = $market;
|
||||
$coin = getdbosql('db_coins', "symbol=:sym", array(':sym'=>$symbol));
|
||||
if(!$coin) return false;
|
||||
$pair = $symbol."_BTC";
|
||||
$market = getdbosql('db_markets', "coinid={$coin->id} AND name='$exchange'");
|
||||
if(!$market) return false;
|
||||
|
||||
} else if (is_object($market)) {
|
||||
|
||||
$coin = getdbo('db_coins', $market->coinid);
|
||||
if(!$coin) return false;
|
||||
$symbol = $coin->getOfficialSymbol();
|
||||
$pair = $symbol."_BTC";
|
||||
if (!empty($market->base_coin)) $pair = $symbol.'_'.$market->base_coin;
|
||||
}
|
||||
|
||||
$t1 = microtime(true);
|
||||
$m = bleutrade_api_query('public/getticker', '&market='.$pair);
|
||||
if(!is_object($m) || !$m->success || empty($m->result)) return false;
|
||||
$ticker = $m->result[0];
|
||||
|
||||
$price2 = ($ticker->Bid+$ticker->Ask)/2;
|
||||
$market->price2 = AverageIncrement($market->price2, $price2);
|
||||
$market->price = AverageIncrement($market->price, $ticker->Bid);
|
||||
$market->pricetime = time();
|
||||
$market->save();
|
||||
|
||||
$apims = round((microtime(true) - $t1)*1000,3);
|
||||
user()->setFlash('message', "$exchange $symbol price updated in $apims ms");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ class CcexAPI
|
|||
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array('apisign:'.$sign));
|
||||
//curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; C-Cex PHP client; '.php_uname('s').'; PHP/'.phpversion().')');
|
||||
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; C-Cex PHP client; '.php_uname('s').'; PHP/'.phpversion().')');
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->timeout/2);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
|
||||
|
||||
|
|
|
@ -36,3 +36,46 @@ function coinexchange_api_query($method, $params='')
|
|||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// manual update of one market
|
||||
function coinexchange_update_market($market)
|
||||
{
|
||||
$exchange = 'coinexchange';
|
||||
if (is_string($market))
|
||||
{
|
||||
$symbol = $market;
|
||||
$coin = getdbosql('db_coins', "symbol=:sym", array(':sym'=>$symbol));
|
||||
if(!$coin) return false;
|
||||
$market = getdbosql('db_markets', "coinid={$coin->id} AND name='$exchange'");
|
||||
if(!$market) return false;
|
||||
|
||||
} else if (is_object($market)) {
|
||||
|
||||
$coin = getdbo('db_coins', $market->coinid);
|
||||
if(!$coin) return false;
|
||||
$symbol = $coin->getOfficialSymbol();
|
||||
}
|
||||
|
||||
if (empty($market->marketid)) {
|
||||
user()->setFlash('error', "$exchange $symbol marketid not set!");
|
||||
return false;
|
||||
}
|
||||
|
||||
$t1 = microtime(true);
|
||||
$m = coinexchange_api_query('getmarketsummary', 'market_id='.$market->marketid);
|
||||
if(!is_object($m) || !$m->success || empty($m->result)) return false;
|
||||
$ticker = $m->result;
|
||||
|
||||
$price2 = ((double) $ticker->BidPrice + (double) $ticker->AskPrice)/2;
|
||||
$market->price2 = AverageIncrement($market->price2, $price2);
|
||||
$market->price = AverageIncrement($market->price, (double) $ticker->BidPrice);
|
||||
$market->pricetime = time();
|
||||
$market->save();
|
||||
|
||||
$apims = round((microtime(true) - $t1)*1000,3);
|
||||
user()->setFlash('message', "$exchange $symbol price updated in $apims ms {$market->price}");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -254,3 +254,46 @@ function livecoin_api_query($method, $params='')
|
|||
$obj = json_decode($execResult);
|
||||
return $obj;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// manual update of one market
|
||||
function livecoin_update_market($market)
|
||||
{
|
||||
$exchange = 'livecoin';
|
||||
if (is_string($market))
|
||||
{
|
||||
$symbol = $market;
|
||||
$coin = getdbosql('db_coins', "symbol=:sym", array(':sym'=>$symbol));
|
||||
if(!$coin) return false;
|
||||
$pair = $symbol.'/BTC';
|
||||
$market = getdbosql('db_markets', "coinid={$coin->id} AND name='$exchange'");
|
||||
if(!$market) return false;
|
||||
|
||||
} else if (is_object($market)) {
|
||||
|
||||
$coin = getdbo('db_coins', $market->coinid);
|
||||
if(!$coin) return false;
|
||||
$symbol = $coin->getOfficialSymbol();
|
||||
$pair = $symbol.'/BTC';
|
||||
if (!empty($market->base_coin)) $pair = $symbol.'/'.$market->base_coin;
|
||||
}
|
||||
|
||||
$t1 = microtime(true);
|
||||
$ticker = livecoin_api_query('exchange/ticker','?currencyPair='.urlencode($pair));
|
||||
if(!empty($ticker->errorMessage)) {
|
||||
user()->setFlash('error', "$exchange $symbol {$ticker->errorMessage}");
|
||||
}
|
||||
if(!is_object($ticker) || !isset($ticker->best_bid)) return false;
|
||||
|
||||
$price2 = ($ticker->best_bid+$ticker->best_ask)/2;
|
||||
$market->price2 = AverageIncrement($market->price2, $price2);
|
||||
$market->price = AverageIncrement($market->price, $ticker->best_bid);
|
||||
$market->pricetime = time();
|
||||
$market->save();
|
||||
|
||||
$apims = round((microtime(true) - $t1)*1000,3);
|
||||
user()->setFlash('message', "$exchange $symbol price updated in $apims ms {$market->price}");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -58,3 +58,44 @@ function nova_api_user($method, $params=array())
|
|||
|
||||
return $res;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// manual update of one market
|
||||
function nova_update_market($market)
|
||||
{
|
||||
$exchange = 'nova';
|
||||
if (is_string($market))
|
||||
{
|
||||
$symbol = $market;
|
||||
$coin = getdbosql('db_coins', "symbol=:sym", array(':sym'=>$symbol));
|
||||
if(!$coin) return false;
|
||||
$pair = 'BTC_'.strtoupper($symbol);
|
||||
$market = getdbosql('db_markets', "coinid={$coin->id} AND name='$exchange'");
|
||||
if(!$market) return false;
|
||||
|
||||
} else if (is_object($market)) {
|
||||
|
||||
$coin = getdbo('db_coins', $market->coinid);
|
||||
if(!$coin) return false;
|
||||
$symbol = $coin->getOfficialSymbol();
|
||||
$pair = 'BTC_'.strtoupper($symbol);
|
||||
if (!empty($market->base_coin)) $pair = $market->base_coin.'_'.strtoupper($symbol);
|
||||
}
|
||||
|
||||
$t1 = microtime(true);
|
||||
$m = nova_api_query('market/info/'.$pair);
|
||||
if(!is_object($m) || $m->status != 'success' || empty($m->markets)) return false;
|
||||
$ticker = $m->markets[0];
|
||||
|
||||
$price2 = ($ticker->bid+$ticker->ask)/2;
|
||||
$market->price = AverageIncrement($market->price, $ticker->bid);
|
||||
$market->price2 = AverageIncrement($market->price2, $ticker->last_price);
|
||||
$market->pricetime = time();
|
||||
$market->save();
|
||||
|
||||
$apims = round((microtime(true) - $t1)*1000,3);
|
||||
user()->setFlash('message', "$exchange $symbol price updated in $apims ms");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -40,7 +40,8 @@ function cancelExchangeOrder($order=false)
|
|||
|
||||
function runExchange($exchangeName=false)
|
||||
{
|
||||
if ($exchangeName)
|
||||
if (!empty($exchangeName))
|
||||
{
|
||||
switch($exchangeName)
|
||||
{
|
||||
case 'alcurex':
|
||||
|
@ -72,6 +73,10 @@ function runExchange($exchangeName=false)
|
|||
updateCCexMarkets();
|
||||
break;
|
||||
|
||||
case 'coinexchange':
|
||||
updateCoinExchangeMarkets();
|
||||
break;
|
||||
|
||||
case 'empoex':
|
||||
//doEmpoexTrading(true);
|
||||
//updateEmpoexMarkets();
|
||||
|
@ -106,5 +111,9 @@ function runExchange($exchangeName=false)
|
|||
doPoloniexTrading(true);
|
||||
updatePoloniexMarkets();
|
||||
break;
|
||||
|
||||
default:
|
||||
debuglog(__FUNCTION__.' '.$exchangeName.' not implemented');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue