diff --git a/web/yaamp/core/exchange/bitstamp.php b/web/yaamp/core/exchange/bitstamp.php index 2b86158..0431129 100644 --- a/web/yaamp/core/exchange/bitstamp.php +++ b/web/yaamp/core/exchange/bitstamp.php @@ -86,7 +86,8 @@ function getBitstampBalances() if (is_object($savebalance)) { $balances = bitstamp_api_user('balance'); if (is_array($balances)) { - $savebalance->balance = arraySafeVal($balances, 'btc_balance'); + $savebalance->balance = arraySafeVal($balances, 'btc_balance',0.) - arraySafeVal($balances, 'btc_reserved'); + $savebalance->onsell = arraySafeVal($balances, 'btc_reserved'); $savebalance->save(); } } diff --git a/web/yaamp/core/exchange/cexio.php b/web/yaamp/core/exchange/cexio.php index e095f66..51e5b0d 100644 --- a/web/yaamp/core/exchange/cexio.php +++ b/web/yaamp/core/exchange/cexio.php @@ -100,7 +100,8 @@ function getCexIoBalances() $balances = cexio_api_user('balance'); if (is_array($balances)) { $b = arraySafeVal($balances, 'BTC'); - $savebalance->balance = arraySafeVal($b, 'available',0.) + arraySafeVal($b, 'orders',0.); + $savebalance->balance = arraySafeVal($b, 'available',0.); + $savebalance->onsell = arraySafeVal($b, 'orders',0.); $savebalance->save(); } } diff --git a/web/yaamp/core/trading/binance_trading.php b/web/yaamp/core/trading/binance_trading.php index 467eb35..3cad356 100644 --- a/web/yaamp/core/trading/binance_trading.php +++ b/web/yaamp/core/trading/binance_trading.php @@ -25,6 +25,7 @@ function doBinanceTrading($quick=false) if ($balance->asset == 'BTC') { if (is_object($savebalance)) { $savebalance->balance = $balance->free; + $savebalance->onsell = $balance->locked; $savebalance->save(); } continue; diff --git a/web/yaamp/core/trading/bittrex_trading.php b/web/yaamp/core/trading/bittrex_trading.php index 9240eac..8f67cec 100644 --- a/web/yaamp/core/trading/bittrex_trading.php +++ b/web/yaamp/core/trading/bittrex_trading.php @@ -27,7 +27,8 @@ function doBittrexTrading($quick=false) $savebalance = getdbosql('db_balances', "name='$exchange'"); if (is_object($savebalance)) { - $savebalance->balance = 0; + $savebalance->balance = 0.; + $savebalance->onsell = 0.; $savebalance->save(); } @@ -36,6 +37,7 @@ function doBittrexTrading($quick=false) if ($balance->Currency == 'BTC') { if (is_object($savebalance)) { $savebalance->balance = $balance->Available; + $savebalance->onsell = (double) $balance->Balance - (double) $balance->Available; $savebalance->save(); } continue; diff --git a/web/yaamp/core/trading/bleutrade_trading.php b/web/yaamp/core/trading/bleutrade_trading.php index b5a31f5..6d800e3 100644 --- a/web/yaamp/core/trading/bleutrade_trading.php +++ b/web/yaamp/core/trading/bleutrade_trading.php @@ -28,6 +28,7 @@ function doBleutradeTrading($quick=false) $savebalance = getdbosql('db_balances', "name='$exchange'"); if (is_object($savebalance)) { $savebalance->balance = 0; + $savebalance->onsell = 0; $savebalance->save(); } @@ -36,6 +37,7 @@ function doBleutradeTrading($quick=false) if ($balance->Currency == 'BTC') { if (is_object($savebalance)) { $savebalance->balance = $balance->Available; + $savebalance->onsell = (double) $balance->Balance - (double) $balance->Available; $savebalance->save(); } continue; diff --git a/web/yaamp/core/trading/bter_trading.php b/web/yaamp/core/trading/bter_trading.php index 7736905..5d38a1f 100644 --- a/web/yaamp/core/trading/bter_trading.php +++ b/web/yaamp/core/trading/bter_trading.php @@ -27,6 +27,7 @@ function doBterTrading($quick=false) if ($symbol == 'BTC') { if (is_object($savebalance)) { $savebalance->balance = $balance->available; + $savebalance->onsell = arraySafeVal($balances['locked_funds'],$symbol,0); $savebalance->save(); } continue; diff --git a/web/yaamp/core/trading/c-cex_trading.php b/web/yaamp/core/trading/c-cex_trading.php index f91c8ce..a9d4351 100644 --- a/web/yaamp/core/trading/c-cex_trading.php +++ b/web/yaamp/core/trading/c-cex_trading.php @@ -39,6 +39,7 @@ function doCCexTrading($quick=false) if ($symbol == 'BTC') { if (!is_object($savebalance)) continue; $savebalance->balance = arraySafeVal($balance,'Available'); + $savebalance->onsell = arraySafeVal($balance,'Balance',0.) - arraySafeVal($balance,'Available'); $savebalance->save(); continue; } diff --git a/web/yaamp/core/trading/cryptopia_trading.php b/web/yaamp/core/trading/cryptopia_trading.php index 7956c6f..4a026b9 100644 --- a/web/yaamp/core/trading/cryptopia_trading.php +++ b/web/yaamp/core/trading/cryptopia_trading.php @@ -27,6 +27,7 @@ function doCryptopiaTrading($quick=false) $savebalance = getdbosql('db_balances', "name='$exchange'"); if (is_object($savebalance)) { $savebalance->balance = 0; + $savebalance->onsell = 0; $savebalance->save(); } @@ -36,6 +37,7 @@ function doCryptopiaTrading($quick=false) if ($balance->Symbol == 'BTC') { if (is_object($savebalance)) { $savebalance->balance = $balance->Available; + $savebalance->onsell = $balance->HeldForTrades; $savebalance->save(); } continue; diff --git a/web/yaamp/core/trading/hitbtc_trading.php b/web/yaamp/core/trading/hitbtc_trading.php index ba6a38d..db380ea 100644 --- a/web/yaamp/core/trading/hitbtc_trading.php +++ b/web/yaamp/core/trading/hitbtc_trading.php @@ -25,6 +25,7 @@ function doHitBTCTrading($quick=false) if ($balance->currency_code == 'BTC') { if (is_object($savebalance)) { $savebalance->balance = $balance->cash; + $savebalance->onsell = $balance->reserved; $savebalance->save(); } continue; diff --git a/web/yaamp/core/trading/kraken_trading.php b/web/yaamp/core/trading/kraken_trading.php index d8a7c0f..580bcff 100644 --- a/web/yaamp/core/trading/kraken_trading.php +++ b/web/yaamp/core/trading/kraken_trading.php @@ -10,12 +10,16 @@ function doKrakenTrading($quick=false) $balances = kraken_api_user('Balance'); if(!$balances || !is_array($balances)) return; + //$total = kraken_api_user('TradeBalance', array('asset'=>'XXBT')); + //if(!$total || !is_array($total)) return; + foreach($balances as $symbol => $balance) { if ($symbol == 'BTC') { $db_balance = getdbosql('db_balances', "name='$exchange'"); if ($db_balance) { $db_balance->balance = $balance; + //$db_balance->onsell = (double) $total['result']['tb'] - $balance; $db_balance->save(); } continue; diff --git a/web/yaamp/core/trading/kucoin_trading.php b/web/yaamp/core/trading/kucoin_trading.php index 394a614..dd33182 100644 --- a/web/yaamp/core/trading/kucoin_trading.php +++ b/web/yaamp/core/trading/kucoin_trading.php @@ -25,6 +25,7 @@ function doKuCoinTrading($quick=false) if ($balance->coinType == 'BTC') { if (is_object($savebalance)) { $savebalance->balance = $balance->balance; + $savebalance->onsell = $balance->freezeBalance; $savebalance->save(); } continue; diff --git a/web/yaamp/core/trading/livecoin_trading.php b/web/yaamp/core/trading/livecoin_trading.php index a014fdd..40676d2 100644 --- a/web/yaamp/core/trading/livecoin_trading.php +++ b/web/yaamp/core/trading/livecoin_trading.php @@ -52,13 +52,17 @@ function doLiveCoinTrading($quick = false) foreach ($balances as $balance) { if ($balance->currency == 'BTC' && $balance->type == "available") { - if (!is_object($savebalance)) { - continue; - } + if (!is_object($savebalance)) continue; $savebalance->balance = $balance->value; $savebalance->save(); continue; } + if ($balance->currency == 'BTC' && $balance->type == "trade") { + if (!is_object($savebalance)) continue; + $savebalance->onsell = $balance->value; + $savebalance->save(); + continue; + } if ($updatebalances) { // store available balance in market table diff --git a/web/yaamp/core/trading/nova_trading.php b/web/yaamp/core/trading/nova_trading.php index ca32216..4e7b268 100644 --- a/web/yaamp/core/trading/nova_trading.php +++ b/web/yaamp/core/trading/nova_trading.php @@ -38,6 +38,7 @@ function doNovaTrading($quick=false) $savebalance = getdbosql('db_balances', "name='{$exchange}'"); if (is_object($savebalance)) { $savebalance->balance = 0; + $savebalance->onsell = 0; $savebalance->save(); } else { dborun("INSERT INTO balances (name,balance) VALUES ('$exchange',0)"); @@ -49,6 +50,7 @@ function doNovaTrading($quick=false) if ($balance->currency == 'BTC') { if (is_object($savebalance)) { $savebalance->balance = $balance->amount; + $savebalance->onsell = $balance->amount_trades; $savebalance->save(); } continue; diff --git a/web/yaamp/core/trading/poloniex_trading.php b/web/yaamp/core/trading/poloniex_trading.php index e817bdf..1aef2b2 100644 --- a/web/yaamp/core/trading/poloniex_trading.php +++ b/web/yaamp/core/trading/poloniex_trading.php @@ -33,7 +33,8 @@ function doPoloniexTrading() { if ($symbol == 'BTC') { if (is_object($savebalance)) { - $savebalance->balance = $balance['available']; + $savebalance->balance = arraySafeVal($balance,'available'); + $savebalance->onsell = arraySafeVal($balance,'onOrders'); $savebalance->save(); } continue; diff --git a/web/yaamp/core/trading/yobit_trading.php b/web/yaamp/core/trading/yobit_trading.php index ddc483a..f794a6f 100644 --- a/web/yaamp/core/trading/yobit_trading.php +++ b/web/yaamp/core/trading/yobit_trading.php @@ -37,6 +37,7 @@ function doYobitTrading($quick=false) if ($symbol == 'btc') { if (is_object($savebalance)) { $savebalance->balance = $amount; + $savebalance->onsell = arraySafeVal($balances['return']['funds_incl_orders'],$symbol,0.) - $amount; $savebalance->save(); } continue; @@ -51,6 +52,7 @@ function doYobitTrading($quick=false) $market = getdbosql('db_markets', "coinid=:coinid AND name='$exchange'", array(':coinid'=>$coin->id)); if (!$market) continue; $market->balance = $amount; + $market->ontrade = arraySafeVal($balances['return']['funds_incl_orders'],$symbol,0.) - $amount; $market->balancetime = time(); $market->save(); } diff --git a/web/yaamp/modules/site/common_results.php b/web/yaamp/modules/site/common_results.php index 3c25577..a5b93b0 100644 --- a/web/yaamp/modules/site/common_results.php +++ b/web/yaamp/modules/site/common_results.php @@ -222,34 +222,6 @@ echo ''; // ---------------------------------------------------------------------------------------------------- -if (YAAMP_ALLOW_EXCHANGE) { -echo 'sell orders'; -foreach($markets as $market) -{ - $exchange = $market->name; - $onsell = bitcoinvaluetoa(dboscalar("select sum(amount*bid) from orders where market='$exchange'")); - $salebalances[$exchange] = $onsell; - - if($onsell > 0.2) - echo ''.$onsell.''; - else if($onsell > 0.1) - echo ''.$onsell.''; - else if($onsell == 0.0) - echo '-'; - else - echo ''.$onsell.''; - - $total_onsell += $onsell; -} - -$total_onsell = bitcoinvaluetoa($total_onsell); - -echo ''.$total_onsell.''; -echo ''; -} // YAAMP_ALLOW_EXCHANGE - -// ---------------------------------------------------------------------------------------------------- - echo 'BTC'; foreach($markets as $market) { @@ -274,6 +246,45 @@ echo ''; // ---------------------------------------------------------------------------------------------------- +echo 'orders'; +if (YAAMP_ALLOW_EXCHANGE) { + // yaamp mode + foreach($markets as $market) { + $exchange = $market->name; + $onsell = bitcoinvaluetoa(dboscalar("SELECT sum(amount*bid) FROM orders WHERE market='$exchange'")); + $salebalances[$exchange] = $onsell; + + if($onsell > 0.2) + echo ''.$onsell.''; + else if($onsell > 0.1) + echo ''.$onsell.''; + else if($onsell == 0.0) + echo '-'; + else + echo ''.$onsell.''; + + $total_onsell += $onsell; + } +} else { + // yiimp mode + $ontrade = dbolist("SELECT name, onsell FROM balances B ORDER by name"); + foreach($ontrade as $row) { + $exchange = $row['name']; + $onsell = bitcoinvaluetoa($row['onsell']); + $salebalances[$exchange] = $onsell; + + echo ''.($onsell == 0 ? '-' : $onsell).''; + + $total_onsell += (double) $onsell; + } + +} +$total_onsell = bitcoinvaluetoa($total_onsell); +echo ''.$total_onsell.''; +echo ''; + +// ---------------------------------------------------------------------------------------------------- + $t = time() - 48*60*60; $altmarkets = dbolist(" SELECT B.name, SUM((M.balance+M.ontrade)*M.price) AS balance