mirror of
https://github.com/LBRYFoundation/pool.git
synced 2025-08-23 17:37:25 +00:00
markets: handle cryptohub api, but only manually
their api is not complete enough to auto create the markets...
This commit is contained in:
parent
2ad138591e
commit
20de9ab774
3 changed files with 114 additions and 0 deletions
|
@ -23,6 +23,7 @@ function BackendPricesUpdate()
|
|||
updateAlcurexMarkets();
|
||||
updateBinanceMarkets();
|
||||
updateBterMarkets();
|
||||
updateCryptohubMarkets();
|
||||
//updateEmpoexMarkets();
|
||||
updateJubiMarkets();
|
||||
updateLiveCoinMarkets();
|
||||
|
@ -1165,6 +1166,48 @@ function updateBterMarkets()
|
|||
}
|
||||
}
|
||||
|
||||
function updateCryptohubMarkets()
|
||||
{
|
||||
$exchange = 'cryptohub';
|
||||
if (exchange_get($exchange, 'disabled')) return;
|
||||
|
||||
$markets = cryptohub_api_query('market/ticker');
|
||||
if(!is_array($markets)) return;
|
||||
|
||||
$list = getdbolist('db_markets', "name='$exchange'");
|
||||
foreach($list as $market)
|
||||
{
|
||||
$coin = getdbo('db_coins', $market->coinid);
|
||||
if(!$coin) continue;
|
||||
|
||||
$symbol = $coin->getOfficialSymbol();
|
||||
if (market_get($exchange, $symbol, "disabled")) {
|
||||
$market->disabled = 1;
|
||||
$market->message = 'disabled from settings';
|
||||
$market->save();
|
||||
continue;
|
||||
}
|
||||
|
||||
$dbpair = 'BTC'.'_'.$symbol;
|
||||
foreach ($markets as $pair => $ticker) {
|
||||
if ($pair != $dbpair) continue;
|
||||
$price2 = ($ticker['highestBid']+$ticker['lowestAsk'])/2;
|
||||
$market->price = AverageIncrement($market->price, $ticker['highestBid']);
|
||||
$market->price2 = AverageIncrement($market->price2, $price2);
|
||||
$market->pricetime = time();
|
||||
//if ($market->disabled < 9) $market->disabled = (floatval($ticker['baseVolume']) < 0.01);
|
||||
$market->save();
|
||||
|
||||
if (empty($coin->price2)) {
|
||||
$coin->price = $market->price;
|
||||
$coin->price2 = $market->price2;
|
||||
$coin->market = $exchange;
|
||||
$coin->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function updateEmpoexMarkets()
|
||||
{
|
||||
$exchange = 'empoex';
|
||||
|
|
68
web/yaamp/core/exchange/cryptohub.php
Normal file
68
web/yaamp/core/exchange/cryptohub.php
Normal file
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
|
||||
// https://cryptohub.online/api/market/ticker/
|
||||
|
||||
function cryptohub_api_query($method, $params='')
|
||||
{
|
||||
$uri = "https://cryptohub.online/api/{$method}/";
|
||||
if (!empty($params)) $uri .= "{$params}/";
|
||||
|
||||
$ch = curl_init($uri);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
|
||||
|
||||
$execResult = strip_tags(curl_exec($ch));
|
||||
|
||||
// array required for ticker "foreach"
|
||||
$array = json_decode($execResult, true);
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// manual update of one market
|
||||
function cryptohub_update_market($market)
|
||||
{
|
||||
$exchange = 'cryptohub';
|
||||
if (is_string($market))
|
||||
{
|
||||
$symbol = $market;
|
||||
$coin = getdbosql('db_coins', "symbol=:sym", array(':sym'=>$symbol));
|
||||
if(!$coin) return false;
|
||||
$pair = $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 = $symbol;
|
||||
if (!empty($market->base_coin)) $pair = $market->base_coin.'_'.$symbol;
|
||||
}
|
||||
|
||||
$t1 = microtime(true);
|
||||
$ticker = cryptohub_api_query("market/ticker",$pair);
|
||||
if(!$ticker || empty($ticker)) return false;
|
||||
$ticker = array_pop($ticker);
|
||||
if(arraySafeVal($ticker,'highestBid') === NULL) {
|
||||
debuglog("$exchange: invalid data received for $pair ticker");
|
||||
return false;
|
||||
}
|
||||
|
||||
$price2 = ((double) $ticker['highestBid'] + $ticker['lowestAsk']) / 2;
|
||||
$market->price2 = AverageIncrement($market->price2, $price2);
|
||||
$market->price = AverageIncrement($market->price, (double) $ticker['highestBid']);
|
||||
if ($ticker['lowestAsk'] < $market->price) $market->price = $ticker['lowestAsk'];
|
||||
$market->pricetime = time();
|
||||
$market->save();
|
||||
|
||||
$apims = round((microtime(true) - $t1)*1000,3);
|
||||
user()->setFlash('message', "$exchange $symbol price updated in $apims ms");
|
||||
|
||||
return true;
|
||||
}
|
|
@ -19,6 +19,7 @@ require_once("bleutrade.php");
|
|||
require_once("ccexapi.php");
|
||||
require_once("cexio.php");
|
||||
require_once("cryptobridge.php");
|
||||
require_once("cryptohub.php");
|
||||
require_once("kraken.php");
|
||||
require_once("poloniex.php");
|
||||
require_once("yobit.php");
|
||||
|
@ -93,6 +94,8 @@ function getMarketUrl($coin, $marketName)
|
|||
$url = "https://coinsmarkets.com/trade-{$base}-{$symbol}.htm";
|
||||
else if($market == 'cryptobridge')
|
||||
$url = "https://wallet.crypto-bridge.org/market/BRIDGE.{$symbol}_BRIDGE.{$base}";
|
||||
else if($market == 'cryptohub')
|
||||
$url = "https://cryptohub.online/market/{$symbol}/{$base}";
|
||||
else if($market == 'cryptopia')
|
||||
$url = "https://www.cryptopia.co.nz/Exchange?market={$symbol}_{$base}";
|
||||
else if($market == 'cryptowatch')
|
||||
|
|
Loading…
Add table
Reference in a new issue