Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions web/yaamp/core/backend/markets.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ function BackendPricesUpdate()
settings_prefetch_all();

updateBittrexMarkets();
updateBitzMarkets();
updatePoloniexMarkets();
updateBleutradeMarkets();
updateCryptoBridgeMarkets();
Expand Down Expand Up @@ -288,6 +289,42 @@ function updateBleutradeMarkets()

}

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

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

$markets = bitz_api_query('tickerall');

foreach($markets as $c => $ticker)
{
$pairs = explode('_', $c);
$symbol = strtoupper(reset($pairs)); $base = end($pairs);
if($symbol == 'BTC' || $base != 'btc') continue;

if (market_get($exchange, $symbol, "disabled")) {
$market->disabled = 1;
$market->message = 'disabled from settings';
}
$coin = getdbosql('db_coins', "symbol='{$symbol}'");
if(!$coin) continue;
if(!$coin->installed && !$coin->watch) continue;
$market = getdbosql('db_markets', "coinid={$coin->id} and name='{$exchange}'");

if(!$market) continue;
$price2 = ($ticker->bidPrice + $ticker->askPrice)/2;
$market->price2 = AverageIncrement($market->price2, $price2);
$market->price = AverageIncrement($market->price, $ticker->bidPrice);
$market->pricetime = time();
$market->priority = -1;
$market->txfee = 0.2; // trade pct
$market->save();
// debuglog("$exchange: update $symbol: {$market->price} {$market->price2}");
}
}

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

function updateCryptoBridgeMarkets($force = false)
Expand Down
15 changes: 14 additions & 1 deletion web/yaamp/core/backend/rawcoins.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@ function updateRawcoins()
}
}

if (!exchange_get('bitz', 'disabled')) {
$list = bitz_api_query('tickerall');

dborun("UPDATE markets SET deleted=true WHERE name='bitz'");
foreach($list as $c => $ticker) {
$e = explode('_', $c);
if (strtoupper($e[1]) !== 'BTC')
continue;
$symbol = strtoupper($e[0]);
updateRawCoin('bitz', $symbol);
}
}

if (!exchange_get('bleutrade', 'disabled')) {
$list = bleutrade_api_query('public/getcurrencies');
if(isset($list->result) && !empty($list->result))
Expand Down Expand Up @@ -417,7 +430,7 @@ function updateRawCoin($marketname, $symbol, $name='unknown')
}
}

if (in_array($marketname, array('nova','askcoin','binance','coinexchange','coinsmarkets','cryptobridge','hitbtc'))) {
if (in_array($marketname, array('nova','askcoin','binance','bitz','coinexchange','coinsmarkets','cryptobridge','hitbtc'))) {
// don't polute too much the db with new coins, its better from exchanges with labels
return;
}
Expand Down
24 changes: 24 additions & 0 deletions web/yaamp/core/exchange/bitz.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
// see https://apidoc.bit-z.com/en/Demo/PHP.html
// https://apiv2.bitz.com/Market/ticker?symbol=ltc_btc
// https://apiv2.bitz.com/Market/tickerall

function bitz_api_query($method, $params='', $returnType='object')
{
$url = "https://apiv2.bitz.com/Market/$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, 'Mozilla/4.0 (compatible; BitZ API PHP client; '.php_uname('s').'; PHP/'.phpversion().')');
curl_setopt($ch, CURLOPT_ENCODING , '');
//curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$execResult = curl_exec($ch);
if ($returnType == 'object')
$ret = json_decode($execResult);
else
$ret = json_decode($execResult,true);
return $ret->data;
}
3 changes: 3 additions & 0 deletions web/yaamp/core/exchange/exchange.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function strip_data($data)

require_once("bitstamp.php");
require_once("bittrex.php");
require_once("bitz.php");
require_once("bleutrade.php");
require_once("ccexapi.php");
require_once("cexio.php");
Expand Down Expand Up @@ -82,6 +83,8 @@ function getMarketUrl($coin, $marketName)
$url = "https://www.binance.com/trade.html?symbol={$symbol}_{$base}";
else if($market == 'bittrex')
$url = "https://bittrex.com/Market/Index?MarketName={$base}-{$symbol}";
else if($market == 'bitz')
$url = "https://www.bit-z.com/exchange/{$symbol}_{$base}";
else if($market == 'poloniex')
$url = "https://poloniex.com/exchange#{$lowbase}_{$lowsymbol}";
else if($market == 'bleutrade')
Expand Down
3 changes: 3 additions & 0 deletions web/yaamp/core/trading/trading.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ function runExchange($exchangeName=false)
doBittrexTrading(true);
updateBittrexMarkets();
break;
case 'bitz':
updateBitzMarkets();
break;

case 'cexio':
getCexIoBalances();
Expand Down
2 changes: 2 additions & 0 deletions web/yaamp/defaultconfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
if (!defined('YAAMP_BTCADDRESS')) define('YAAMP_BTCADDRESS', '');
if (!defined('YAAMP_SITE_URL')) define('YAAMP_SITE_URL', 'localhost');
if (!defined('YAAMP_API_URL')) define('YAAMP_API_URL', YAAMP_SITE_URL);
if (!defined('YAAMP_API_PAYOUTS')) define('YAAMP_API_PAYOUTS', false);
if (!defined('YAAMP_API_PAYOUTS_PERIOD')) define('YAAMP_API_PAYOUTS_PERIOD', 24 * 60 * 60);
if (!defined('YAAMP_STRATUM_URL')) define('YAAMP_STRATUM_URL', YAAMP_SITE_URL);
if (!defined('YAAMP_SITE_NAME')) define('YAAMP_SITE_NAME', 'YiiMP');
if (!defined('YAAMP_DEFAULT_ALGO')) define('YAAMP_DEFAULT_ALGO', 'x11');
Expand Down
23 changes: 23 additions & 0 deletions web/yaamp/modules/api/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,29 @@ public function actionWalletEx()
}

echo "]";

if(YAAMP_API_PAYOUTS)
{
$json_payouts = controller()->memcache->get("api_payouts-$user->id");
if (empty($json_payouts)) {
$json_payouts = ",\"payouts\": ";
$json_payouts .= "[";
$list = getdbolist('db_payouts', "account_id={$user->id} AND completed>0 AND tx IS NOT NULL AND time >= ".(time() - YAAMP_API_PAYOUTS_PERIOD)." ORDER BY time DESC");
foreach($list as $j => payout)
{
if($j) $json_payouts .= ", ";
$json_payouts .= "{";
$json_payouts .= "\"time\": \"$payout->time\",";
$json_payouts .= "\"amount\": \"$payout->amount\",";
$json_payouts .= "\"tx\": \"$payout->tx\"";
$json_payouts .= "}";
}
$json_payouts .= "]";
controller()->memcache->set("api_payouts-$user->id", $json_payouts, 60, MEMCACHE_COMPRESSED);
}
echo str_replace("},","},\n", $json_payouts);
}

echo "}";
}

Expand Down
12 changes: 11 additions & 1 deletion web/yaamp/modules/site/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,19 @@
"accepted": 82463372.083,
"rejected": 0
}]
<?php if (YAAMP_API_PAYOUTS) : ?>
"payouts":[{
"time": "1529860641",
"amount": "0.001",
"tx": "transaction_id_of_the_payout"
}]
<?php endif; ?>
}
</pre>

<?php
if (YAAMP_API_PAYOUTS)
echo "Payouts of the last ".(YAAMP_API_PAYOUTS_PERIOD / 3600)." hours are displayed, please use a block explorer to see all payouts.";
?>
<p><b>Pool Status</b></p>

request:
Expand Down