cleanup: drop dead exchanges code

cryptsy cryptomic(banx) and safecex
This commit is contained in:
Tanguy Pruvot 2016-10-22 00:34:50 +02:00
parent d4150a9ffe
commit 114001ab1b
14 changed files with 10 additions and 1234 deletions

View file

@ -54,7 +54,6 @@ class CoindbCommand extends CConsoleCommand
$nbUpdated += $this->grabCcexIcons();
$nbUpdated += $this->grabCryptopiaIcons();
$nbUpdated += $this->grabAlcurexIcons();
$nbUpdated += $this->grabCryptomicIcons();
$nbUpdated += $this->grabNovaIcons();
echo "total updated: $nbUpdated\n";
@ -402,42 +401,6 @@ class CoindbCommand extends CConsoleCommand
return $nbUpdated;
}
/**
* Icon grabber - Cryptomic
*/
public function grabCryptomicIcons()
{
$url = 'https://cdn.cryptomic.com/images/currencyicons/';
$nbUpdated = 0;
$sql = "SELECT DISTINCT coins.id FROM coins INNER JOIN markets M ON M.coinid = coins.id ".
"WHERE M.name='cryptomic' AND IFNULL(coins.image,'') = ''";
$coins = dbolist($sql);
if (empty($coins))
return 0;
echo "cryptomic: try to download new icons...\n";
foreach ($coins as $coin) {
$coin = getdbo('db_coins', $coin["id"]);
$symbol = $coin->symbol;
if (!empty($coin->symbol2)) $symbol = $coin->symbol2;
$local = $this->basePath."/images/coin-{$symbol}.png";
try {
$data = @ file_get_contents($url.strtoupper($symbol).'-64.png');
} catch (Exception $e) {
continue;
}
if (strlen($data) < 2048) continue;
echo $symbol." icon found\n";
file_put_contents($local, $data);
if (filesize($local) > 0) {
$coin->image = "/images/coin-{$symbol}.png";
$nbUpdated += $coin->save();
}
}
if ($nbUpdated)
echo "$nbUpdated icons downloaded from cryptomic\n";
return $nbUpdated;
}
/**
* Icon grabber - NovaExchange
*/

View file

@ -122,8 +122,6 @@ class ExchangeCommand extends CConsoleCommand
public function testApiKeys()
{
require_once($this->basePath.'/yaamp/core/core.php');
if (!empty(EXCH_BITSTAMP_KEY)) {
$balance = bitstamp_api_user('balance');
if (!is_array($balance)) echo "bitstamp error ".json_encode($balance)."\n";
@ -169,31 +167,16 @@ class ExchangeCommand extends CConsoleCommand
if (objSafeVal($info,'status','') != 'success' || !is_array($info->balances)) echo "nova error\n";
else echo("nova btc: ".json_encode($info->balances[0])."\n");
}
if (!empty(EXCH_CRYPTSY_KEY)) {
$info = cryptsy_api_query('getinfo');
if (!arraySafeVal($info,'success',0) || !is_array($info['return'])) echo "error\n";
else echo("cryptsy btc: ".json_encode($info['return']['balances_available']['BTC'])."\n");
}
if(!empty(EXCH_POLONIEX_KEY)) {
$poloniex = new poloniex;
$balance = $poloniex->get_available_balances();
echo("poloniex available : ".json_encode($balance)."\n");
}
if (!empty(EXCH_SAFECEX_KEY)) {
$balance = safecex_api_user('getbalance', "&symbol=BTC");
echo("safecex btc: ".json_encode($balance)."\n");
}
if (!empty(EXCH_YOBIT_KEY)) {
$info = yobit_api_query2('getInfo');
if (!arraySafeVal($info,'success',0) || !is_array($info['return'])) echo "error\n";
else echo("yobit btc: ".json_encode($info['return']['funds']['btc'])."\n");
}
if (!empty(EXCH_BANX_USERNAME)) {
//$balance = cryptomic_api_user('account/getbalance','?currency=BTC');
$balance = cryptomic_api_user('account/getbalances');
if (!is_object($balance)) echo "cryptomic error ".json_encode($balance)."\n";
else echo("cryptomic all: ".json_encode($balance->result)."\n");
}
// only one secret key
$balance = empoex_api_user('account/balance','BTC');
if ($balance) echo("empoex btc: ".json_encode($balance['available'])."\n");

View file

@ -17,13 +17,10 @@ function BackendPricesUpdate()
updateCCexMarkets();
updateCryptopiaMarkets();
updateYobitMarkets();
updateSafecexMarkets();
updateAlcurexMarkets();
updateBterMarkets();
//updateEmpoexMarkets();
updateCryptsyMarkets();
updateJubiMarkets();
updateCryptomicMarkets();
updateNovaMarkets();
updateShapeShiftMarkets();
@ -410,158 +407,6 @@ function updateBittrexMarkets($force = false)
}
}
/////////////////////////////////////////////////////////////////////////////////////////////
function updateCryptsyMarkets()
{
$exchange = 'cryptsy';
if (exchange_get($exchange, 'disabled')) return;
// dborun("update markets set price=0 where name='$exchange'");
// return;
$markets = cryptsy_api_query('getmarkets');
if(!$markets || !isset($markets['return'])) {
return;
}
$list = cryptsy_api_query('getcoindata');
if(!$list || !isset($list['return'])) {
return;
}
foreach($list['return'] as $currency)
{
if($currency['code'] == 'BTC') continue;
$symbol = $currency['code'];
$coin = getdbosql('db_coins', "symbol=:symbol", array(':symbol'=>$symbol));
if(!$coin) continue;
$market = getdbosql('db_markets', "coinid=$coin->id and name='$exchange'");
if(!$market)
{
$market = new db_markets;
$market->coinid = $coin->id;
$market->name = $exchange;
foreach($markets['return'] as $item)
{
if($item['secondary_currency_code'] != 'BTC') continue;
if($item['primary_currency_code'] != $symbol) continue;
$market->marketid = $item['marketid'];
}
}
if(empty($market->marketid))
{
foreach($markets['return'] as $item)
{
if($item['secondary_currency_code'] != 'BTC') continue;
if($item['primary_currency_code'] != $symbol) continue;
$market->marketid = $item['marketid'];
}
}
if (market_get($exchange, $symbol, "disabled")) {
$market->disabled = 1;
$market->deleted = 1;
$market->message = 'disabled from settings';
$market->save();
continue;
}
$market->txfee = $currency['withdrawalfee']*100;
switch($currency['maintenancemode'])
{
case 0:
$market->message = '';
break;
case 1:
$market->message = 'Maintenance';
break;
case 2:
$market->message = 'Updating Wallet';
break;
case 3:
$market->message = 'Network Issues';
break;
case 666:
$market->message = 'Funds holded';
break;
default:
$market->message = 'Unknown Error';
break;
}
$market->disabled = (int) (arraySafeVal($currency,'maintenancemode',0) > 0);
$market->save();
if ($market->disabled) continue;
$ticker = getCryptsyTicker($market->marketid);
if(!$ticker) continue;
if(!isset($ticker->return->$symbol->buyorders[0]))
{
debuglog("$exchange: error $coin->name id {$market->marketid}");
if (isset($ticker->error))
debuglog($ticker->error);
else
debuglog($ticker, 5);
continue;
}
$price2 = $ticker->return->$symbol->buyorders[0]->price;
if (isset($ticker->return->$symbol->sellorders))
$price2 = ($price2 + $ticker->return->$symbol->sellorders[0]->price) / 2.0;
$market->price2 = AverageIncrement($market->price2, $price2);
$market->price = AverageIncrement($market->price, $ticker->return->$symbol->buyorders[0]->price);
$market->pricetime = time();
$market->save();
// debuglog("cryptsy update $coin->symbol: $market->price $market->price2");
}
if(!empty(EXCH_CRYPTSY_KEY))
{
// deposit addresses
$list = array();
$last_checked = cache()->get($exchange.'-deposit_address-check');
if (!$last_checked) {
$list = cryptsy_api_query('getmydepositaddresses');
}
if (empty($list)) return;
if (!is_array($list)) return;
$success = arraySafeVal($list,'success',0);
if (!$success || !is_array($list['return'])) return;
foreach($list['return'] as $symbol => $address)
{
if($symbol == 'BTC') continue;
$coin = getdbosql('db_coins', "symbol=:symbol", array(':symbol'=>$symbol));
if(!$coin) continue;
$market = getdbosql('db_markets', "coinid={$coin->id} and name='$exchange'");
if(!$market) continue;
if (!is_string($address))
debuglog("$exchange: $symbol deposit address format error ".json_encode($address));
else if (!empty($address) && $market->deposit_address != $address) {
$market->deposit_address = $address;
$market->save();
debuglog("$exchange: deposit address for $symbol updated");
}
}
cache()->set($exchange.'-deposit_address-check', time(), 12*3600);
}
}
////////////////////////////////////////////////////////////////////////////////////
function updateCCexMarkets()
@ -986,103 +831,6 @@ function updateCryptopiaMarkets()
cache()->set($exchange.'-deposit_address-check', time(), 12*3600);
}
function updateCryptomicMarkets()
{
$exchange = 'cryptomic';
if (exchange_get($exchange, 'disabled')) return;
$data = cryptomic_api_query('getmarketsummaries');
if(!$data || !is_array($data->result)) return;
$symbols = array();
$currencies = getdbolist('db_markets', "name IN ('$exchange','banx')");
foreach($currencies as $market)
{
$coin = getdbo('db_coins', $market->coinid);
if(!$coin) continue;
if (market_get($exchange, $coin->symbol, "disabled")) {
$market->disabled = 1;
$market->deleted = 1;
$market->message = 'disabled from settings';
$market->save();
continue;
}
$pair = strtoupper($coin->symbol).'-BTC';
foreach ($data->result as $ticker) {
if ($ticker->marketname === $pair) {
if ($market->disabled < 9) {
$nbm = (int) dboscalar("SELECT COUNT(id) FROM markets WHERE coinid={$coin->id}");
$market->disabled = intval($ticker->dayvolume) <= 1 && $nbm > 1;
}
if (!$market->disabled) {
$market->price = AverageIncrement($market->price, $ticker->bid);
$market->price2 = AverageIncrement($market->price2, $ticker->ask);
$market->pricetime = time();
$market->save();
}
if (empty($coin->price2) && !$market->disabled) {
$coin->price = $market->price;
$coin->price2 = $market->price2;
$coin->save();
}
if ($coin->name == 'unknown' && !empty($ticker->currencylong)) {
$coin->name = $ticker->currencylong;
$coin->save();
debuglog("$exchange: update {$coin->symbol} label {$coin->name}");
}
// store for deposit addresses
$symbols[$ticker->currencylong] = $coin->symbol;
$symbols[$ticker->partnerlong] = $coin->symbol;
break;
}
}
}
if(!empty(EXCH_BANX_USERNAME))
{
// deposit addresses
$last_checked = cache()->get($exchange.'-deposit_address-check');
if (!$last_checked) {
// no coin symbols in the results wtf ! only labels :/
sleep(1);
$query = cryptomic_api_user('account/getdepositaddresses');
}
if (!isset($query)) return;
if (!is_object($query)) return;
if (!$query->success || !is_array($query->result)) return;
foreach($query->result as $account)
{
if (!isset($account->currency) || !isset($account->address)) continue;
if (empty($account->currency) || empty($account->address)) continue;
$label = $account->currency;
if (!isset($symbols[$label])) continue;
$symbol = $symbols[$label];
if($symbol == 'BTC') continue;
$coin = getdbosql('db_coins', "symbol=:symbol", array(':symbol'=>$symbol));
if(!$coin) continue;
$market = getdbosql('db_markets', "coinid={$coin->id} and name IN ('{$exchange}','banx')");
if(!$market) continue;
if ($market->deposit_address != $account->address) {
$market->deposit_address = $account->address;
$market->save();
debuglog("$exchange: deposit address for $symbol updated");
}
}
cache()->set($exchange.'-deposit_address-check', time(), 12*3600);
}
}
function updateNovaMarkets()
{
$exchange = 'nova';
@ -1147,106 +895,6 @@ function updateNovaMarkets()
}
}
function updateSafecexMarkets()
{
$exchange = 'safecex';
if (exchange_get($exchange, 'disabled')) return;
$data = safecex_api_query('getmarkets');
if(empty($data)) return;
$list = getdbolist('db_markets', "name='$exchange'");
foreach($list as $market)
{
$coin = getdbo('db_coins', $market->coinid);
if(!$coin) continue;
if (market_get($exchange, $coin->symbol, "disabled")) {
$market->disabled = 1;
$market->deleted = 1;
$market->message = 'disabled from settings';
$market->save();
continue;
}
$pair = strtoupper($coin->symbol).'/BTC';
foreach ($data as $ticker) {
if ($ticker->market === $pair) {
$price2 = ($ticker->bid + $ticker->ask)/2;
$market->price2 = AverageIncrement($market->price2, $price2);
$market->price = AverageIncrement($market->price, $ticker->bid*0.98);
$market->pricetime = time();
$market->save();
if (empty($coin->price)) {
$coin->price = $market->price;
$coin->price2 = $market->price2;
$coin->save();
}
if (empty(EXCH_SAFECEX_KEY)) continue;
// deposit addresses (in getbalances api)
$last_checked = cache()->get($exchange.'-deposit_address-check');
if (empty($market->deposit_address) || isset($getbalances_called) || !$last_checked) {
// note: will try to get all missing installed coins deposit address
// but these addresses are not automatically created on safecex.
if (!isset($getbalances_called)) {
// only one query is enough
$balances = safecex_api_user('getbalances');
$getbalances_called = true;
// allow to check once all new/changed deposit addresses (in 2 job loops)
if (dborun("UPDATE markets SET deposit_address=NULL WHERE name='$exchange' AND deposit_address=' '"))
$need_new_loop = true;
cache()->set($exchange.'-deposit_address-check', time(), 12*3600); // recheck all in 12h
}
if(is_array($balances)) foreach ($balances as $balance) {
if ($balance->symbol == $coin->symbol) {
if (!isset($balance->deposit)) break;
if (empty(trim($market->deposit_address))) {
$market->deposit_address = $balance->deposit;
$market->save();
debuglog("$exchange: {$coin->symbol} deposit address imported");
} else if (trim($market->deposit_address) != $balance->deposit) {
$market->deposit_address = $balance->deposit;
$market->save();
debuglog("$exchange: {$coin->symbol} deposit address was wrong, updated.");
}
}
}
}
}
}
}
if (isset($getbalances_called))
{
// update btc balance too btw
if (is_array($balances)) foreach ($balances as $balance) {
if ($balance->symbol == 'BTC') {
$balance = floatval($balance->balance);
dborun("UPDATE balances SET balance=$balance WHERE name='$exchange'");
}
}
// prevent api calls each 15mn for deposit addresses
// will be rechecked on new coins or if a market address is empty (or forced in 12 hours)
$list = dbolist("SELECT C.symbol AS symbol FROM markets M INNER JOIN coins C on M.coinid = C.id " .
"WHERE M.name='$exchange' AND C.installed AND IFNULL(M.deposit_address,'')='' ORDER BY symbol");
$missing = array();
foreach($list as $row) {
$missing[] = $row['symbol'];
}
if(!empty($missing) && !isset($need_new_loop)) {
debuglog("$exchange: no deposit address found for ".implode(',',$missing));
// stop asking safecex for inexistant deposit addresses (except on new coin or empty address, or 12h)
dborun("UPDATE markets SET deposit_address=' ' WHERE name='$exchange' AND IFNULL(deposit_address,'')=''");
}
}
}
function updateBterMarkets()
{
$exchange = 'bter';

View file

@ -4,10 +4,7 @@ function updateRawcoins()
{
// debuglog(__FUNCTION__);
exchange_set_default('cryptsy', 'disabled', true);
exchange_set_default('empoex', 'disabled', true);
exchange_set_default('safecex', 'disabled', true);
exchange_set_default('cryptomic', 'disabled', true);
settings_prefetch_all();
@ -85,16 +82,6 @@ function updateRawcoins()
}
}
if (!exchange_get('cryptsy', 'disabled')) {
$list = cryptsy_api_query('getmarkets');
if(isset($list['return']))
{
dborun("UPDATE markets SET deleted=true WHERE name='cryptsy'");
foreach($list['return'] as $item)
updateRawCoin('cryptsy', $item['primary_currency_code'], $item['primary_currency_name']);
}
}
if (!exchange_get('yobit', 'disabled')) {
$res = yobit_api_query('info');
if($res)
@ -109,21 +96,6 @@ function updateRawcoins()
}
}
if (!exchange_get('safecex', 'disabled')) {
$list = safecex_api_query('getmarkets');
if(!empty($list))
{
dborun("UPDATE markets SET deleted=true WHERE name='safecex'");
foreach($list as $pair => $item) {
$e = explode('/', $item->market);
if (strtoupper($e[1]) !== 'BTC')
continue;
$symbol = strtoupper($e[0]);
updateRawCoin('safecex', $symbol, $item->name);
}
}
}
if (!exchange_get('cryptopia', 'disabled')) {
$list = cryptopia_api_query('GetMarkets');
if(isset($list->Data))
@ -169,26 +141,6 @@ function updateRawcoins()
}
}
if (!exchange_get('cryptomic', 'disabled')) {
$list = cryptomic_api_simple('marketsv2');
if(is_array($list))
{
dborun("UPDATE markets SET name='cryptomic', deleted=true WHERE name IN ('cryptomic','banx')");
foreach($list as $item) {
$e = explode('/', $item['market']);
$base = strtoupper($e[1]);
if ($base != 'BTC')
continue;
$symbol = strtoupper($e[0]);
if ($symbol == 'ATP')
continue;
$name = explode('/', $item['marketname']);
updateRawCoin('cryptomic', $symbol, $name[0]);
//debuglog("cryptomic: $symbol {$name[0]}");
}
}
}
if (!exchange_get('nova', 'disabled')) {
$list = nova_api_query('markets');
if(is_object($list) && !empty($list->markets))

View file

@ -1,65 +0,0 @@
<?php
function cryptsy_api_query($method, array $req = array())
{
// debuglog("calling cryptsy_api_query $method");
require_once('/etc/yiimp/keys.php');
if (!defined('EXCH_CRYPTSY_SECRET')) define('EXCH_CRYPTSY_SECRET', '');
if (empty(EXCH_CRYPTSY_KEY)) return FALSE;
// API settings
$key = EXCH_CRYPTSY_KEY; // your API-key
$secret = EXCH_CRYPTSY_SECRET; // your Secret-key
// $cookie_jar = tempnam(YAAMP_HTDOCS.'/yaamp/runtime/cookies','cryptsy_cook');
$cookie_jar = YAAMP_HTDOCS.'/yaamp/runtime/cookies/cryptsy_cookies.dat';
//touch($cookie_jar);
$req['method'] = $method;
$mt = explode(' ', microtime());
$req['nonce'] = $mt[1];
// generate the POST data string
$post_data = http_build_query($req, '', '&');
$sign = hash_hmac("sha512", $post_data, $secret);
// generate the extra headers
$headers = array(
'Sign: '.$sign,
'Key: '.$key,
);
// our curl handle (initialize if required)
static $ch = null;
if (is_null($ch)) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
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);
// run the query
$res = curl_exec($ch);
if ($res === false) {
debuglog("ERROR cryptsy_api_query $method");
return null;
}
// debuglog("cryptsy: $method");
$dec = json_decode($res, true);
if (!is_array($dec)) {
debuglog("ERROR cryptsy_api_query $method");
debuglog(strip_tags($res));
return null;
}
//usleep(200*1000);
return $dec;
}

View file

@ -17,15 +17,12 @@ require_once("ccexapi.php");
require_once("bleutrade.php");
require_once("kraken.php");
require_once("yobit.php");
require_once("cryptsy.php");
require_once("safecex.php");
require_once("shapeshift.php");
require_once("bter.php");
require_once("empoex.php");
require_once("jubi.php");
require_once("alcurex.php");
require_once("cryptopia.php");
require_once("cryptomic.php");
require_once("nova.php");
/* Format an exchange coin Url */
@ -61,12 +58,8 @@ function getMarketUrl($coin, $marketName)
$url = "https://bleutrade.com/exchange/{$symbol}/{$base}";
else if($market == 'bter')
$url = "https://bter.com/trade/{$lowsymbol}_{$lowbase}";
else if($market == 'banx' || $market == 'cryptomic')
$url = "https://www.cryptomic.com/trade?c={$symbol}&p={$base}";
else if($market == 'cryptopia')
$url = "https://www.cryptopia.co.nz/Exchange?market={$symbol}_{$base}";
else if($market == 'cryptsy')
$url = "https://www.cryptsy.com/markets/view/{$symbol}_{$base}";
else if($market == 'c-cex')
$url = "https://c-cex.com/?p={$lowsymbol}-{$lowbase}";
else if($market == 'empoex')
@ -75,8 +68,6 @@ function getMarketUrl($coin, $marketName)
$url = "http://jubi.com/coin/{$lowsymbol}";
else if($market == 'nova')
$url = "https://novaexchange.com/market/{$base}_{$symbol}/";
else if($market == 'safecex')
$url = "https://safecex.com/market?q={$symbol}/{$base}";
else if($market == 'yobit')
$url = "https://yobit.net/en/trade/{$symbol}/{$base}";
else

View file

@ -1,69 +0,0 @@
<?php
// https://safecex.com/help/api
// https://safecex.com/api/getmarkets
// https://safecex.com/api/getmarket?market=VTC/BTC
function safecex_api_query($method, $params='')
{
$uri = "https://safecex.com/api/{$method}{$params}";
$ch = curl_init($uri);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$execResult = strip_tags(curl_exec($ch));
$obj = json_decode($execResult);
return $obj;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
// https://safecex.com/api/getbalances (seems unavailable yet)
function safecex_api_user($method, $params='')
{
require_once('/etc/yiimp/keys.php');
if (!defined('EXCH_SAFECEX_SECRET')) define('EXCH_SAFECEX_SECRET', '');
if (empty(EXCH_SAFECEX_KEY) || empty(EXCH_SAFECEX_SECRET)) return false;
$apikey = EXCH_SAFECEX_KEY;
$nonce = time();
// $mt = explode(' ', microtime());
// $nonce = $mt[1].substr($mt[0], 2, 6);
$url = "https://safecex.com/api/$method?apikey=$apikey&nonce=$nonce$params";
$ch = curl_init($url);
$sign = hash_hmac('sha512', $url, EXCH_SAFECEX_SECRET);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("apisign:$sign"));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
//curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
//curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; Safecex PHP client; '.php_uname('s').'; PHP/'.phpversion().')');
curl_setopt($ch, CURLOPT_ENCODING , '');
$res = curl_exec($ch);
if($res === false)
{
$e = curl_error($ch);
debuglog("safecex: $e");
curl_close($ch);
return false;
}
$result = json_decode($res);
if(!is_object($result) && !is_array($result)) {
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
debuglog("safecex: $method failed ($status) $res");
}
curl_close($ch);
return $result;
}

View file

@ -39,7 +39,7 @@ class CExchange
// add to our db if not there already
}
$list = getdbolist('db_orders', "market='$this->marketname'");
$list = getdbolist('db_orders', "market='{$this->marketname}'");
foreach($list as $db_order)
{
$found = false;
@ -59,7 +59,7 @@ class CExchange
}
}
$savebalance = getdbosql('db_balances', "name='cryptsy'");
$savebalance = getdbosql('db_balances', "name='{$this->marketname}'");
$savebalance->balance = 0;
$this->balances = $this->loadBalances();
@ -99,6 +99,8 @@ class CExchange
////////////////////////////////////////////////////////////////////////////////////////////////
/*
class CExchangeCryptsy extends CExchange
{
protected function loadOrders()
@ -194,6 +196,5 @@ class CExchangeCryptsy extends CExchange
};
*/

View file

@ -30,6 +30,7 @@ class CExchangeCoin
public static function create($coin, $marketname)
{
/*
switch($marketname)
{
case 'cryptsy':
@ -39,10 +40,13 @@ class CExchangeCoin
$cexcoin->load();
return $cexcoin;
*/
}
};
/*
class CExchangeCoinCryptsy extends CExchangeCoin
{
private $marketid;
@ -79,6 +83,5 @@ class CExchangeCoinCryptsy extends CExchangeCoin
};
*/

View file

@ -1,57 +0,0 @@
<?php
function doCryptomicTrading($quick=false)
{
$exchange = 'cryptomic';
$updatebalances = true;
if (exchange_get($exchange, 'disabled')) return;
// [{"currency":"BTC","balance":0.02265703,"available":0.02265703,"pending":0,"isbts":0,"cryptoaddress":"1DCVPWgs..."}]}
$balances = cryptomic_api_user('account/getbalances');
if(!$balances || !isset($balances->result) || !$balances->success) return;
$savebalance = getdbosql('db_balances', "name IN ('{$exchange}','banx')");
if (is_object($savebalance)) {
$savebalance->balance = 0;
$savebalance->save();
dborun("UPDATE markets SET balance=0 WHERE name='{$exchange}'");
}
foreach($balances->result as $balance)
{
if ($balance->currency == 'BTC') {
if (!is_object($savebalance)) continue;
$savebalance->balance = $balance->available;
$savebalance->save();
continue;
}
if ($updatebalances) {
// store available balance in market table
$coins = getdbolist('db_coins', "symbol=:symbol OR symbol2=:symbol",
array(':symbol'=>$balance->currency)
);
if (empty($coins)) continue;
foreach ($coins as $coin) {
$market = getdbosql('db_markets', "coinid=:coinid AND name='{$exchange}'", array(':coinid'=>$coin->id));
if (!$market) continue;
$market->balance = $balance->available;
$market->ontrade = $balance->balance - $balance->available;
$deposit_address = objSafeVal($balance,'cryptoaddress');
if (!empty($deposit_address) && $market->deposit_address != $balance->cryptoaddress) {
debuglog("{$exchange}: {$coin->symbol} deposit address updated");
$market->deposit_address = $balance->cryptoaddress;
}
$market->balancetime = time();
$market->save();
}
}
}
if (!YAAMP_ALLOW_EXCHANGE) return;
$flushall = rand(0, 8) == 0;
if($quick) $flushall = false;
}

View file

@ -1,274 +0,0 @@
<?php
function getCryptsyTicker($marketid)
{
try {
$res = @ fetch_url("http://pubapi2.cryptsy.com/api.php?method=singleorderdata&marketid=$marketid");
if(!$res)
$res = @ fetch_url("http://pubapi1.cryptsy.com/api.php?method=singleorderdata&marketid=$marketid");
if(!$res) return null;
$ticker = json_decode($res);
} catch (Exception $e) {
debuglog("cryptsy ticker http failure");
$ticker = null;
}
return $ticker;
}
function doCryptsyTrading($quick=false)
{
$exchange = 'cryptsy';
$updatebalances = true;
if (exchange_get($exchange, 'disabled')) return;
$savebalance = getdbosql('db_balances', "name='$exchange'");
if (is_object($savebalance)) {
$savebalance->balance = 0;
$savebalance->save();
}
$balances = cryptsy_api_query('getinfo');
if(!$balances) return;
if(!isset($balances['return'])) {
debuglog("$exchange balance: ".arraySafeVal($balances,'error'));
return;
}
foreach($balances['return']['balances_available'] as $symbol=>$balance)
{
if($symbol == 'BTC') {
if (is_object($savebalance)) {
$savebalance->balance = floatval($balance);
$savebalance->save();
}
continue;
}
if ($updatebalances) {
// store available balance in market table
$coins = getdbolist('db_coins', "symbol=:symbol OR symbol2=:symbol",
array(':symbol'=>$symbol)
);
if (empty($coins)) continue;
foreach ($coins as $coin) {
$market = getdbosql('db_markets', "coinid=:coinid AND name='{$exchange}'", array(':coinid'=>$coin->id));
if (!$market) continue;
$market->balance = $available;
$market->balancetime = time();
$market->save();
}
}
}
if (!YAAMP_ALLOW_EXCHANGE) return;
$flushall = rand(0, 8) == 0;
if($quick) $flushall = false;
$orders = cryptsy_api_query('allmyorders');
if(empty($orders)) return;
if(!is_array($orders) || !isset($orders['return'])) {
debuglog("-------------- doCryptsyTrading() $flushall ".json_encode($orders));
return;
}
// add orders
foreach($orders['return'] as $order)
{
if(!isset($order['marketid'])) continue;
if(!isset($order['orderid'])) continue;
$market = getdbosql('db_markets', "marketid=:marketid", array(':marketid'=>$order['marketid']));
if(!$market) continue;
$coin = getdbo('db_coins', $market->coinid);
if(!$coin) continue;
$symbol = $coin->symbol;
$ticker = getCryptsyTicker($market->marketid);
if(!$ticker || !isset($ticker->return->$symbol->sellorders[0])) continue;
$ask = bitcoinvaluetoa($ticker->return->$symbol->sellorders[0]->price);
$sellprice = bitcoinvaluetoa($order['price']);
// flush orders not on the ask
if($ask+0.00000005 < $sellprice || $flushall)
{
// debuglog("cryptsy cancel order for $coin->symbol ($ask != $sellprice)");
cryptsy_api_query('cancelorder', array('orderid'=>$order['orderid']));
$db_order = getdbosql('db_orders', "uuid=:uuid", array(':uuid'=>$order['orderid']));
if($db_order) $db_order->delete();
sleep(1);
}
// add existing orders (shouldnt happen after init)
else
{
$db_order = getdbosql('db_orders', "uuid=:uuid", array(':uuid'=>$order['orderid']));
if($db_order) continue;
debuglog("adding order $coin->symbol");
$db_order = new db_orders;
$db_order->market = 'cryptsy';
$db_order->coinid = $coin->id;
$db_order->amount = $order['quantity'];
$db_order->price = $sellprice;
$db_order->ask = $ticker->return->$symbol->sellorders[0]->price;
$db_order->bid = isset($ticker->return->$symbol->buyorders)? $ticker->return->$symbol->buyorders[0]->price: 0;
$db_order->uuid = $order['orderid'];
$db_order->created = time();
$db_order->save();
}
}
$list = getdbolist('db_orders', "market='cryptsy'");
foreach($list as $db_order)
{
$coin = getdbo('db_coins', $db_order->coinid);
$found = false;
foreach($orders['return'] as $order)
{
if(!isset($order['orderid'])) continue;
if($order['orderid'] == $db_order->uuid)
{
$found = true;
break;
}
}
if(!$found)
{
debuglog("cryptsy deleting order $coin->name $db_order->amount");
$db_order->delete();
}
}
// if($flushall)
// {
// debuglog("cryptsy flushall");
// return;
// }
sleep(2);
foreach($balances['return']['balances_available'] as $symbol=>$balance)
{
if($symbol == 'Points') continue;
if($symbol == 'BTC') continue;
$balance = floatval($balance);
if(!$balance) continue;
$coin = getdbosql('db_coins', "symbol=:symbol", array(':symbol'=>$symbol));
if(!$coin || $coin->dontsell) continue;
$market = getdbosql('db_markets', "coinid=$coin->id and name='cryptsy'");
if(!$market) continue;
$market->lasttraded = time();
$market->save();
if($balance*$market->price < 0.00001000) continue;
$ticker = getCryptsyTicker($market->marketid);
if(!$ticker || !isset($ticker->return->$symbol->buyorders[0])) continue;
// for 0 to 4
{
$nextbuy = $ticker->return->$symbol->buyorders[0];
if($balance >= $nextbuy->quantity && $nextbuy->quantity*$nextbuy->price > 0.00001000)
{
$sellprice = bitcoinvaluetoa($nextbuy->price);
debuglog("cryptsy selling market $coin->symbol, $nextbuy->quantity, $sellprice");
$res = cryptsy_api_query('createorder',
array('marketid'=>$market->marketid, 'ordertype'=>'Sell', 'quantity'=>$nextbuy->quantity, 'price'=>$sellprice));
if($res) $balance -= $nextbuy->quantity;
// TradingClearExchangeCoin($coin, $nextbuy->quantity, $ticker->return->$symbol->buyorders[1]->price, 'cryptsy');
sleep(1);
}
if($coin->sellonbid && $balance*$nextbuy->price > 0.00001000)
{
$sellprice = bitcoinvaluetoa($nextbuy->price);
debuglog("cryptsy selling market $coin->symbol, $balance, $sellprice");
$res = cryptsy_api_query('createorder',
array('marketid'=>$market->marketid, 'ordertype'=>'Sell', 'quantity'=>$balance, 'price'=>$sellprice));
// TradingClearExchangeCoin($coin, $balance, $ticker->return->$symbol->buyorders[1]->price, 'cryptsy');
sleep(1);
continue;
}
}
if($coin->sellonbid)
$sellprice = $ticker->return->$symbol->buyorders[0]->price;
else
$sellprice = $ticker->return->$symbol->sellorders[0]->price;
// if($balance * $sellprice < 0.0001) continue;
// debuglog("cryptsy selling $coin->symbol, $sellprice, $balance");
$res = cryptsy_api_query('createorder',
array('marketid'=>$market->marketid, 'ordertype'=>'Sell', 'quantity'=>$balance, 'price'=>$sellprice));
if(!$res || !isset($res['orderid'])) continue;
$db_order = new db_orders;
$db_order->market = 'cryptsy';
$db_order->coinid = $coin->id;
$db_order->amount = $balance;
$db_order->price = $sellprice;
$db_order->ask = $ticker->return->$symbol->sellorders[0]->price;
$db_order->bid = $ticker->return->$symbol->buyorders[0]->price;
$db_order->uuid = $res['orderid'];
$db_order->created = time();
$db_order->save();
}
if(is_object($savebalance))
if(floatval(EXCH_AUTO_WITHDRAW) > 0 && $savebalance->balance >= (EXCH_AUTO_WITHDRAW + 0.0002))
{
$btcaddr = YAAMP_BTCADDRESS; //'14LS7Uda6EZGXLtRrFEZ2kWmarrxobkyu9';
$amount = $savebalance->balance; // - 0.001;
debuglog("cryptsy withdraw $amount to $btcaddr");
sleep(1);
$res = cryptsy_api_query('makewithdrawal',
array('address'=>$btcaddr, 'amount'=>$amount));
debuglog($res);
if($res && $res['success'])
{
$withdraw = new db_withdraws;
$withdraw->market = 'cryptsy';
$withdraw->address = $btcaddr;
$withdraw->amount = $amount;
$withdraw->time = time();
// $withdraw->uuid = $res->result->uuid;
$withdraw->save();
// $savebalance->balance = 0;
}
}
// debuglog('-------------- doCryptsyTrading() done');
}

View file

@ -1,275 +0,0 @@
<?php
// note: sleep(1) are added to limit the api calls frequency (interval required of 1 second for safecex)
function doSafecexCancelOrder($orderID)
{
if (empty($orderID)) return false;
sleep(1);
$res = safecex_api_user('cancelorder', "&id={$orderID}");
if($res && $res->status == 'ok')
{
$db_order = getdbosql('db_orders', "market=:market AND uuid=:uuid", array(
':market'=>'safecex', ':uuid'=>$orderID
));
if($db_order) $db_order->delete();
return true;
}
return false;
}
function doSafecexTrading($quick=false)
{
$exchange = 'safecex';
$updatebalances = true;
if (exchange_get($exchange, 'disabled')) return;
// {"symbol":"BTC","balance":0.01056525,"pending":0,"orders":0,"total":0.01056525,"deposit":"15pQYjcBJxo3RQfJe6C5pYxHcxAjzVyTfv","withdraw":"1E1..."}
$balances = safecex_api_user('getbalances');
if(empty($balances)) return;
$savebalance = getdbosql('db_balances', "name='$exchange'");
foreach($balances as $balance)
{
if ($balance->symbol == 'BTC') {
if (is_object($savebalance)) {
$savebalance->balance = $balance->balance;
$savebalance->save();
}
continue;
}
if ($updatebalances) {
// store available balance in market table
$coins = getdbolist('db_coins', "symbol=:symbol OR symbol2=:symbol",
array(':symbol'=>$balance->symbol)
);
if (empty($coins)) continue;
foreach ($coins as $coin) {
$market = getdbosql('db_markets', "coinid=:coinid AND name='$exchange'", array(':coinid'=>$coin->id));
if (!$market) continue;
$market->balance = $balance->balance;
$market->ontrade = $balance->orders;
if (!empty($balance->deposit) && $market->deposit_address != $balance->deposit) {
debuglog("$exchange: {$coin->symbol} deposit address updated");
$market->deposit_address = $balance->deposit;
}
$market->balancetime = time();
$market->save();
}
}
}
if (!YAAMP_ALLOW_EXCHANGE) return;
$flushall = rand(0, 8) == 0;
if($quick) $flushall = false;
// minimum order allowed by the exchange
$min_btc_trade = exchange_get($exchange, 'trade_min_btc', 0.00010000);
// sell on ask price + 5%
$sell_ask_pct = exchange_get($exchange, 'trade_sell_ask_pct', 1.05);
// cancel order if our price is more than ask price + 20%
$cancel_ask_pct = exchange_get($exchange, 'trade_cancel_ask_pct', 1.20);
sleep(1);
$orders = safecex_api_user('getopenorders');
if(!empty($orders))
foreach($orders as $order)
{
// order: {"id":"1569917","market":"XXX\/BTC","type":"sell","time":"1457380288","price":"0.0000075","amount":"43.61658","remain":"43.61658"}
$pairs = explode("/", $order->market);
$symbol = $pairs[0];
if ($pairs[1] != 'BTC') continue;
$coin = getdbosql('db_coins', "symbol=:symbol OR symbol2=:symbol", array(':symbol'=>$symbol));
if(!$coin || is_array($coin)) continue;
if($coin->dontsell) continue;
// ignore buy orders
if($order->type != 'sell') continue;
sleep(1);
$ticker = safecex_api_query('getmarket', "?market={$order->market}");
// {"name":"Coin","market":"XXX\/BTC","open":"0","last":"0.00000596","low":null,"high":null,"bid":"0.00000518","ask":"0.00000583","volume":null,"volumebtc":"0"}
if(empty($ticker)) continue;
$ask = bitcoinvaluetoa($ticker->ask);
$sellprice = bitcoinvaluetoa($order->price);
// flush orders over the 20% range of the current (lowest) ask
if($sellprice > $ask*$cancel_ask_pct || $flushall)
{
debuglog("safecex: cancel order {$order->market} at $sellprice, ask price is now $ask");
sleep(1);
doSafecexCancelOrder($order->id);
}
// store existing orders in the db
else
{
$db_order = getdbosql('db_orders', "market=:market AND uuid=:uuid", array(
':market'=>$exchange, ':uuid'=>$order->id
));
if($db_order) continue;
debuglog("safecex: store new order of {$order->amount} {$coin->symbol} at $sellprice BTC");
$db_order = new db_orders;
$db_order->market = $exchange;
$db_order->coinid = $coin->id;
$db_order->amount = $order->amount;
$db_order->price = $sellprice;
$db_order->ask = $ticker->ask;
$db_order->bid = $ticker->bid;
$db_order->uuid = $order->id;
$db_order->created = $order->time;
$db_order->save();
}
}
// flush obsolete orders
$list = getdbolist('db_orders', "market='$exchange'");
if (!empty($list) && !empty($orders))
foreach($list as $db_order)
{
$coin = getdbo('db_coins', $db_order->coinid);
if(!$coin) continue;
$found = false;
foreach($orders as $order) {
if($order->type != 'sell') continue;
if($order->id == $db_order->uuid) {
// debuglog("$exchange: order waiting, {$order->amount} {$coin->symbol}");
$found = true;
break;
}
}
if(!$found) {
debuglog("$exchange: delete db order {$db_order->amount} {$coin->symbol}");
$db_order->delete();
}
}
// add orders
foreach($balances as $balance)
{
if($balance->symbol == 'BTC') continue;
$amount = floatval($balance->balance);
if(!$amount) continue;
$coin = getdbosql('db_coins', "symbol=:symbol OR symbol2=:symbol", array(':symbol'=>$balance->symbol));
if(!$coin || is_array($coin) || $coin->dontsell) continue;
$symbol = $coin->symbol;
if (!empty($coin->symbol2)) $symbol = $coin->symbol2;
$market = getdbosql('db_markets', "coinid={$coin->id} AND name='$exchange'");
if($market)
{
$market->lasttraded = time();
$market->balance = bitcoinvaluetoa($balance->orders);
$market->save();
}
if($amount*$coin->price < $min_btc_trade) continue;
$pair = "{$balance->symbol}/BTC";
sleep(1);
$data = safecex_api_query('getorderbook', "?market=$pair");
if(empty($data)) continue;
// {"bids":[{"price":"0.00000517","amount":"20"},{"price":"0.00000457","amount":"1528.13069274"},..],"asks":[{...}]
if($coin->sellonbid)
for($i = 0; $i < 5 && $amount >= 0; $i++)
{
if(!isset($data->bids[$i])) break;
$nextbuy = $data->bids[$i];
if($amount*1.1 < $nextbuy->amount) break;
$sellprice = bitcoinvaluetoa($nextbuy->price);
$sellamount = min($amount, $nextbuy->amount);
if($sellamount*$sellprice < $min_btc_trade) continue;
debuglog("$exchange: selling $sellamount $symbol at $sellprice");
sleep(1);
$res = safecex_api_user('selllimit', "&market={$pair}&price={$sellprice}&amount={$sellamount}");
if(!$res || $res->status != 'ok')
{
debuglog("selllimit bid: ".json_encode($res));
break;
}
$amount -= $sellamount;
}
if($amount <= 0) continue;
sleep(1);
$ticker = safecex_api_query('getmarket', "?market=$pair");
if(empty($ticker)) continue;
if($coin->sellonbid)
$sellprice = bitcoinvaluetoa($ticker->bid);
else
$sellprice = bitcoinvaluetoa($ticker->ask * $sell_ask_pct); // lowest ask price +5%
if($amount*$sellprice < $min_btc_trade) continue;
debuglog("$exchange: selling $amount $symbol at $sellprice");
sleep(1);
$res = safecex_api_user('selllimit', "&market={$pair}&price={$sellprice}&amount={$amount}");
if(!$res || $res->status != 'ok')
{
debuglog("selllimit: ".json_encode($res));
continue;
}
if (property_exists($res,'id')) {
$db_order = new db_orders;
$db_order->market = $exchange;
$db_order->coinid = $coin->id;
$db_order->amount = $amount;
$db_order->price = $sellprice;
$db_order->ask = $ticker->ask;
$db_order->bid = $ticker->bid;
$db_order->uuid = $res->id;
$db_order->created = time();
$db_order->save();
}
}
/* withdraw API doesn't exist
$withdraw_min = exchange_get($exchange, 'withdraw_min_btc', EXCH_AUTO_WITHDRAW);
$withdraw_fee = exchange_get($exchange, 'withdraw_fee_btc', 0.0002);
$db_balance = getdbosql('db_balances', "name='$exchange'");
if($withdraw_min > 0 && $db_balance->balance >= ($withdraw_min + $withdraw_fee))
{
$btcaddr = exchange_get($exchange, 'withdraw_btc_address', YAAMP_BTCADDRESS);
$amount = $db_balance->balance - $withdraw_fee;
debuglog("$exchange: withdraw $amount to $btcaddr");
sleep(1);
$res = safecex_api_user('withdraw', "&currency=BTC&amount={$amount}&address={$btcaddr}");
debuglog("$exchange: withdraw: ".json_encode($res));
if($res && $res->success)
{
$withdraw = new db_withdraws;
$withdraw->market = $exchange;
$withdraw->address = $btcaddr;
$withdraw->amount = $amount;
$withdraw->time = time();
$withdraw->uuid = $res->id;
$withdraw->save();
$db_balance->balance = 0;
}
}
*/
}

View file

@ -4,15 +4,12 @@ require_once('poloniex_trading.php');
require_once('bittrex_trading.php');
require_once('bleutrade_trading.php');
require_once('bter_trading.php');
require_once('cryptsy_trading.php');
require_once('c-cex_trading.php');
require_once('kraken_trading.php');
require_once('yobit_trading.php');
require_once('alcurex_trading.php');
require_once('cryptomic_trading.php');
require_once('cryptopia_trading.php');
require_once('nova_trading.php');
require_once('safecex_trading.php');
function cancelExchangeOrder($order=false)
{
@ -31,9 +28,6 @@ function cancelExchangeOrder($order=false)
case 'bleutrade':
doBleutradeCancelOrder($order->uuid);
break;
case 'safecex':
doSafecexCancelOrder($order->uuid);
break;
case 'cryptopia':
doCryptopiaCancelOrder($order->uuid);
break;
@ -50,12 +44,6 @@ function runExchange($exchangeName=false)
updateAlcurexMarkets();
break;
case 'banx':
case 'cryptomic':
doCryptomicTrading(true);
updateCryptomicMarkets();
break;
case 'bter':
doBterTrading(true);
updateBterMarkets();
@ -66,11 +54,6 @@ function runExchange($exchangeName=false)
updateCryptopiaMarkets();
break;
case 'cryptsy':
//doCryptsyTrading(true);
updateCryptsyMarkets();
break;
case 'bitstamp':
getBitstampBalances();
break;
@ -90,11 +73,6 @@ function runExchange($exchangeName=false)
//updateEmpoexMarkets();
break;
case 'safecex':
doSafecexTrading(true);
updateSafecexMarkets();
break;
case 'yobit':
doYobitTrading(true);
updateYobitMarkets();

View file

@ -134,8 +134,6 @@ class CronjobController extends CommonController
getBitstampBalances();
doBittrexTrading();
doCryptopiaTrading();
doSafecexTrading();
//doCryptsyTrading();
doKrakenTrading();
doPoloniexTrading();
break;
@ -145,7 +143,6 @@ class CronjobController extends CommonController
doYobitTrading();
doCCexTrading();
doCryptomicTrading();
doBterTrading();
doBleutradeTrading();
doNovaTrading();