diff --git a/web/yaamp/core/exchange/ccexapi.php b/web/yaamp/core/exchange/ccexapi.php index b2c1a46..c87664a 100644 --- a/web/yaamp/core/exchange/ccexapi.php +++ b/web/yaamp/core/exchange/ccexapi.php @@ -94,13 +94,39 @@ class CcexAPI return $this->jsonQuery($this->api_url."r.html?key={$this->api_key}&a=makeorder&pair={$pair}&q={$quantity}&t={$type}&r={$price}"); } - public function cancelOrder($order){ + public function cancelOrder($order) { return $this->jsonQuery($this->api_url."r.html?key={$this->api_key}&a=cancelorder&id={$order}"); } - public function getBalance(){ + public function getBalance() { return $this->jsonQuery($this->api_url."r.html?key={$this->api_key}&a=getbalance"); } + // If not exists - will generate new + public function getDepositAddress($symbol) { + $coin = strtolower($symbol); + return $this->jsonQuery($this->api_url."r.html?key={$this->api_key}&a=getaddress&coin={$coin}"); + } + + public function checkDeposit($symbol, $txid) { + $coin = strtolower($symbol); + return $this->jsonQuery($this->api_url."r.html?key={$this->api_key}&a=checkdeposit&coin={$coin}&tid={$txid}"); + } + + public function withdraw($symbol, $amount, $address) { + $coin = strtolower($symbol); + return $this->jsonQuery($this->api_url."r.html?key={$this->api_key}&a=withdraw&coin={$coin}&amount={$amount}&address={$address}"); + } + + public function getDepositHistory($symbol, $limit=100) { + $coin = strtolower($symbol); + return $this->jsonQuery($this->api_url."r.html?key={$this->api_key}&a=deposithistory&coin={$coin}&limit={$limit}"); + } + + public function getWithdrawalHistory($symbol, $limit=100) { + $coin = strtolower($symbol); + return $this->jsonQuery($this->api_url."r.html?key={$this->api_key}&a=withdrawalhistory&coin={$coin}&limit={$limit}"); + } + } diff --git a/web/yaamp/core/trading/c-cex_trading.php b/web/yaamp/core/trading/c-cex_trading.php index 7500c7e..d7951ca 100644 --- a/web/yaamp/core/trading/c-cex_trading.php +++ b/web/yaamp/core/trading/c-cex_trading.php @@ -192,6 +192,28 @@ function doCCexTrading($quick=false) $db_order->save(); } + if(floatval(EXCH_AUTO_WITHDRAW) > 0 && $savebalance->balance >= (EXCH_AUTO_WITHDRAW + 0.0002)) + { + $btcaddr = YAAMP_BTCADDRESS; + $amount = $savebalance->balance - 0.0002; + debuglog("[ccex] - withdraw $amount to $btcaddr"); + sleep(1); + $res = $ccex->withdraw('BTC', $amount, $btcaddr); + debuglog("[ccex] - withdraw: ".json_encode($res)); + if(isset($res['return'])) + { + $withdraw = new db_withdraws; + $withdraw->market = 'c-cex'; + $withdraw->address = $btcaddr; + $withdraw->amount = $amount; + $withdraw->time = time(); + $withdraw->uuid = $res['return']; + $withdraw->save(); + + $savebalance->balance = 0; + $savebalance->save(); + } + } // debuglog('-------------- doCCexTrading() done'); }