Skip to content

Commit

Permalink
markets: handle graviex ticker (tpruvot#252)
Browse files Browse the repository at this point in the history
manual only, so market row need to be created manually if really required.
  • Loading branch information
ServePeak authored and tpruvot committed Apr 1, 2018
1 parent 5bb898f commit 31441a6
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
47 changes: 47 additions & 0 deletions web/yaamp/core/backend/markets.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ function BackendPricesUpdate()
updatePoloniexMarkets();
updateBleutradeMarkets();
updateCryptoBridgeMarkets();
updateGraviexMarkets();
updateKrakenMarkets();
updateKuCoinMarkets();
updateCCexMarkets();
Expand Down Expand Up @@ -332,6 +333,52 @@ function updateCryptoBridgeMarkets($force = false)

/////////////////////////////////////////////////////////////////////////////////////////////

function updateGraviexMarkets($force = false)
{
$exchange = 'graviex';
if (exchange_get($exchange, 'disabled')) return;

$list = getdbolist('db_markets', "name LIKE '$exchange%'");
if (empty($list)) return;

$markets = graviex_api_query('tickers');
if(!is_array($markets)) return;

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;
}

$symbol = strtolower($symbol);
$dbpair = $symbol.'btc';
foreach ($markets as $pair => $ticker) {
if ($pair != $dbpair) continue;
$price2 = ($ticker['ticker']['high']+$ticker['ticker']['low'])/2;
$market->price = AverageIncrement($market->price, $ticker['ticker']['high']);
$market->price2 = AverageIncrement($market->price2, $price2);
$market->pricetime = time();
$market->save();

if (empty($coin->price2)) {
$coin->price = $market->price;
$coin->price2 = $market->price2;
$coin->market = $exchange;
$coin->save();
}
}
}
}

/////////////////////////////////////////////////////////////////////////////////////////////

function updateKrakenMarkets($force = false)
{
$exchange = 'kraken';
Expand Down
3 changes: 3 additions & 0 deletions web/yaamp/core/exchange/exchange.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ function strip_data($data)
require_once("ccexapi.php");
require_once("cexio.php");
require_once("cryptobridge.php");
require_once("graviex.php");
require_once("cryptohub.php");
require_once("kraken.php");
require_once("poloniex.php");
Expand Down Expand Up @@ -104,6 +105,8 @@ function getMarketUrl($coin, $marketName)
$url = "https://c-cex.com/?p={$lowsymbol}-{$lowbase}";
else if($market == 'empoex')
$url = "http://www.empoex.com/trade/{$symbol}-{$base}";
else if($market == 'graviex')
$url = "https://graviex.net/api/v2/tickers/{$symbol}{$base}";
else if($market == 'jubi')
$url = "http://jubi.com/coin/{$lowsymbol}";
else if($market == 'hitbtc')
Expand Down
23 changes: 23 additions & 0 deletions web/yaamp/core/exchange/graviex.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

// https://graviex.net/api/v2/tickers.json

function graviex_api_query($method, $params='')
{
$uri = "https://graviex.net/api/v2/{$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);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

$execResult = strip_tags(curl_exec($ch));

// array required for ticker "foreach"
$obj = json_decode($execResult, true);

return $obj;
}

0 comments on commit 31441a6

Please sign in to comment.