Skip to content

Commit

Permalink
monitor the right webserver and new exchanges
Browse files Browse the repository at this point in the history
Added cryptopia ticker, and prepare alcurex functions...
  • Loading branch information
tpruvot committed Jul 14, 2015
1 parent 9aa8562 commit ccd8bed
Show file tree
Hide file tree
Showing 22 changed files with 236 additions and 105 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ stratum/blocknotify
stratum/config/
*.log
web/yaamp/runtime/*
cookies/
Empty file added cookies/.gitkeep
Empty file.
2 changes: 2 additions & 0 deletions web/serverconfig.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
define('YAAMP_SITE_URL', 'yiimp.ccminer.org');
define('YAAMP_ADMIN_EMAIL', 'yiimp@spam.la');

define('YAAMP_USE_NGINX', false);

$cold_wallet_table = array(
'1C23KmLeCaQSLLyKVykHEUse1R7jRDv9j9' => 0.10,
);
Expand Down
59 changes: 58 additions & 1 deletion web/yaamp/core/backend/markets.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ function BackendPricesUpdate()
updatePoloniexMarkets();
updateYobitMarkets();
updateJubiMarkets();
updateAlcurexMarkets();
updateCryptopiaMarkets();

$list2 = getdbolist('db_coins', "installed and symbol2 is not null");
foreach($list2 as $coin2)
Expand Down Expand Up @@ -481,7 +483,7 @@ function updateYobitMarkets()
function updateJubiMarkets()
{
$btc = jubi_api_query('ticker', "?coin=btc");
if(!is_object($btc)) continue;
if(!is_object($btc)) return;

$list = getdbolist('db_markets', "name='jubi'");
foreach($list as $market)
Expand All @@ -507,7 +509,62 @@ function updateJubiMarkets()
}
}

function updateAlcurexMarkets()
{
$data = alcurex_api_query('market', "?info=on");
if(!is_object($data)) return;

$list = getdbolist('db_markets', "name='alcurex'");
foreach($list as $market)
{
$coin = getdbo('db_coins', $market->coinid);
if(!$coin || !$coin->installed) continue;
$pair = strtoupper($coin->symbol).'_BTC';
foreach ($data->MARKETS as $ticker) {
if ($ticker->Pair === $pair) {
$lpair = strtolower($pair);
$last = alcurex_api_query('market', "?pair=$lpair&last=last");
if (is_object($last) && !empty($last->$lpair)) {
$last = reset($last->$lpair);
$market->price = AverageIncrement($market->price, $last->price);
$market->save();
}
$last = alcurex_api_query('market', "?pair=$lpair&last=sell");
if (is_object($last) && !empty($last->$lpair)) {
$last = reset($last->$lpair);
$market->price2 = AverageIncrement($market->price2, $last->price);
$market->save();
}
debuglog("alcurex... should Update $pair: $market->price $market->price2");
}
}
}
}

function updateCryptopiaMarkets()
{
$data = cryptopia_api_query('GetMarkets', 24);
if(!is_object($data)) return;

$list = getdbolist('db_markets', "name='cryptopia'");
foreach($list as $market)
{
$coin = getdbo('db_coins', $market->coinid);
if(!$coin || !$coin->installed) continue;

$pair = strtoupper($coin->symbol).'/BTC';

foreach ($data->Data as $ticker) {
if ($ticker->Label === $pair) {

$price2 = ($ticker->BidPrice+$ticker->AskPrice)/2;
$market->price2 = AverageIncrement($market->price2, $price2);
$market->price = AverageIncrement($market->price, $ticker->BidPrice*0.98);
// debuglog("Updated $pair: $market->price");
$market->save();
break;
}
}
}
}

54 changes: 37 additions & 17 deletions web/yaamp/core/backend/rawcoins.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ function updateRawcoins()
{
if($ticker['disabled']) continue;
if($ticker['delisted']) continue;

updateRawCoin('poloniex', $symbol);
}

Expand All @@ -62,11 +61,35 @@ function updateRawcoins()
{
$e = explode('_', $i);
$symbol = strtoupper($e[0]);

updateRawCoin('yobit', $symbol);
}
}

$list = cryptopia_api_query('GetMarkets');
if(isset($list->Data))
{
dborun("update markets set deleted=true where name='cryptopia'");
foreach($list->Data as $item) {
$e = explode('/', $item->Label);
if (strtoupper($e[1]) !== 'BTC')
continue;
$symbol = strtoupper($e[0]);
updateRawCoin('cryptopia', $symbol);
}
}


$list = alcurex_api_query('market','?info=on');
if(isset($list->MARKETS))
{
dborun("update markets set deleted=true where name='alcurex'");
foreach($list->MARKETS as $item) {
$e = explode('_', $item->Pair);
$symbol = strtoupper($e[0]);
updateRawCoin('alcurex', $symbol);
}
}

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

dborun("delete from markets where deleted");
Expand Down Expand Up @@ -123,22 +146,19 @@ function updateRawCoin($marketname, $symbol, $name='unknown')

/////////

// if($coin->enable || !empty($coin->algo) || !empty($coin->errors) || $coin->name == 'unknown') return;
// debuglog("http://www.cryptocoinrank.com/$coin->name");
// if($coin->enable || !empty($coin->algo) || !empty($coin->errors) || $coin->name == 'unknown') return;
// debuglog("http://www.cryptocoinrank.com/$coin->name");

// $data = file_get_contents("http://www.cryptocoinrank.com/$coin->name");
// if($data)
// {
// $b = preg_match('/Algo: <span class=\"d-gray\">(.*)<\/span>/', $data, $m);
// if($b)
// {
// $coin->errors = trim($m[1]);
// $coin->save();
// }
// }
// $data = file_get_contents("http://www.cryptocoinrank.com/$coin->name");
// if($data)
// {
// $b = preg_match('/Algo: <span class=\"d-gray\">(.*)<\/span>/', $data, $m);
// if($b)
// {
// $coin->errors = trim($m[1]);
// $coin->save();
// }
// }

}




4 changes: 0 additions & 4 deletions web/yaamp/core/core.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,3 @@
require_once('trading/trading.php');
require_once('exchange/exchange.php');
require_once('backend/backend.php');




17 changes: 17 additions & 0 deletions web/yaamp/core/exchange/alcurex.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

// https://alcurex.org/index.php/crypto/api_documentation

function alcurex_api_query($method, $params='')
{
$uri = "https://alcurex.org/api/$method.php$params";
// debuglog("$uri");

$ch = curl_init($uri);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$execResult = curl_exec($ch);
$obj = json_decode($execResult);

return $obj;
}
19 changes: 19 additions & 0 deletions web/yaamp/core/exchange/cryptopia.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

// https://www.cryptopia.co.nz/api/GetMarkets/24

function cryptopia_api_query($method, $params='')
{
$uri = "https://www.cryptopia.co.nz/api/$method";
if (!empty($params))
$uri .= "/$params";
// debuglog("$uri");

$ch = curl_init($uri);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$execResult = curl_exec($ch);
$obj = json_decode($execResult);

return $obj;
}
11 changes: 5 additions & 6 deletions web/yaamp/core/exchange/cryptsy.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

function cryptsy_api_query($method, array $req = array())
{
// debuglog("calling cryptsy_api_query $method");
debuglog("calling cryptsy_api_query $method");
// debuglog($req);

require_once('/etc/yiimp/keys.php');
Expand All @@ -11,6 +11,8 @@ function cryptsy_api_query($method, array $req = array())
$key = '44752827db114b157b19b22ee30b88eba3f40651'; // your API-key
$secret = YIIMP_CRYPT_PVK; // your Secret-key

$cookie_jar = tempnam('/var/yaamp/cookies','cryptsy_cook');

$req['method'] = $method;
$mt = explode(' ', microtime());
$req['nonce'] = $mt[1];
Expand All @@ -34,6 +36,7 @@ function cryptsy_api_query($method, array $req = array())
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; Cryptsy API PHP client; '.php_uname('s').'; PHP/'.phpversion().')');
}
curl_setopt($ch, CURLOPT_URL, 'https://api.cryptsy.com/api');
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_jar);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
Expand All @@ -55,10 +58,6 @@ function cryptsy_api_query($method, array $req = array())
return null;
}

// sleep(1);
sleep(1);
return $dec;
}




5 changes: 2 additions & 3 deletions web/yaamp/core/exchange/exchange.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@
require_once("bleutrade.php");
require_once("yobit.php");
require_once("jubi.php");



require_once("alcurex.php");
require_once("cryptopia.php");
6 changes: 6 additions & 0 deletions web/yaamp/core/trading/alcurex_trading.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

function doAlcurexTrading()
{

}
6 changes: 6 additions & 0 deletions web/yaamp/core/trading/cryptopia_trading.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

function doCryptopiaTrading()
{
}

16 changes: 8 additions & 8 deletions web/yaamp/core/trading/cryptsy_trading.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ function doCryptsyTrading($quick=false)

$orders = cryptsy_api_query('allmyorders');
if(empty($orders)) return;
if(!is_array($orders)) {
debuglog("-------------- doCryptsyTrading() $flushall $orders");
if(!is_array($orders) || !isset($orders['return'])) {
debuglog("-------------- doCryptsyTrading() $flushall ".json_encode($orders));
return;
}

Expand Down Expand Up @@ -99,11 +99,11 @@ function doCryptsyTrading($quick=false)
}
}

// if($flushall)
// {
// debuglog("cryptsy flushall");
// return;
// }
// if($flushall)
// {
// debuglog("cryptsy flushall");
// return;
// }

sleep(2);

Expand Down Expand Up @@ -227,7 +227,7 @@ function doCryptsyTrading($quick=false)

$savebalance->save();

// debuglog('-------------- doCryptsyTrading() done');
// debuglog('-------------- doCryptsyTrading() done');
}


Expand Down
5 changes: 2 additions & 3 deletions web/yaamp/core/trading/trading.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@
require_once('cryptsy_trading.php');
require_once('c-cex_trading.php');
require_once('yobit_trading.php');



require_once('alcurex_trading.php');
require_once('cryptopia_trading.php');
11 changes: 6 additions & 5 deletions web/yaamp/modules/coin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,6 @@
else if($market->name == 'bittrex')
$url = "https://bittrex.com/Market/Index?MarketName=BTC-$coin->symbol";

else if($market->name == 'mintpal')
$url = "https://www.mintpal.com/market/$coin->symbol/BTC";

else if($market->name == 'poloniex')
$url = "https://poloniex.com/exchange/btc_$coin->symbol";

Expand All @@ -107,6 +104,12 @@
else if($market->name == 'yobit')
$url = "https://yobit.net/en/trade/$coin->symbol/BTC";

else if($market->name == 'cryptopia')
$url = "https://www.cryptopia.co.nz/Exchange?market=${coin->symbol}_BTC";

else if($market->name == 'alcurex')
$url = "https://alcurex.org/index.php/crypto/market?pair=${lowsymbol}_btc";

echo "<a href='$url' target=_blank>$market->name</a> ";
}

Expand All @@ -130,5 +133,3 @@
echo "<br><br><br><br><br>";




7 changes: 0 additions & 7 deletions web/yaamp/modules/market/MarketController.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,3 @@ public function actionSellto()
}

}







0 comments on commit ccd8bed

Please sign in to comment.