From 2afb9c3952c08ec7afea6ca86067c9754d091138 Mon Sep 17 00:00:00 2001 From: Edson Medina Date: Sat, 13 Sep 2014 14:31:10 +0100 Subject: [PATCH] More api methods --- test.php => example.php | 2 +- src/edsonmedina/bittrex/Client.php | 89 +++++++++++++++++++++++++++++- 2 files changed, 88 insertions(+), 3 deletions(-) rename test.php => example.php (86%) diff --git a/test.php b/example.php similarity index 86% rename from test.php rename to example.php index 0b47993..dda0328 100644 --- a/test.php +++ b/example.php @@ -8,6 +8,6 @@ $secret = '6171690af7364ea2a951dc85d00e1130'; $b = new Client ($key, $secret); - var_dump ($b->getOpenOrders ()); + var_dump ($b->getOrderHistory ()); echo "\n\n"; \ No newline at end of file diff --git a/src/edsonmedina/bittrex/Client.php b/src/edsonmedina/bittrex/Client.php index 8efb114..42bc670 100644 --- a/src/edsonmedina/bittrex/Client.php +++ b/src/edsonmedina/bittrex/Client.php @@ -68,13 +68,15 @@ private function callMarket ($query) */ private function callAccount ($query) { - $uri = $this->baseUrl.'account/'.$query.'&apikey='.$this->apiKey; + $uri = $this->baseUrl.'account/'.$query; + $uri .= strpos ($uri, '?') === FALSE ? '?' : '&'; + $uri .= 'apikey='.$this->apiKey.'&nonce='.time(); $sign = hash_hmac ('sha512', $uri, $this->apiSecret); $ch = curl_init ($uri); - curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt ($ch, CURLOPT_HTTPHEADER, array('apisign: '.$sign)); + curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true); $result = curl_exec($ch); return json_decode($result); @@ -220,6 +222,89 @@ public function getOpenOrders ($market = null) $params = empty ($market) ? '' : '?market='.$market; return $this->callMarket ('getopenorders'.$params); } + + /** + * Retrieve all balances from your account + * @return array + */ + public function getBalances () + { + return $this->callAccount ('getbalances'); + } + + /** + * Retrieve the balance from your account for a specific currency + * @param string $currency literal for the currency (ex: LTC) + * @return array + */ + public function getBalance ($currency) + { + return $this->callAccount ('getbalance?currency='.$currency); + } + + /** + * Retrieve or generate an address for a specific currency. If one + * does not exist, the call will fail and return ADDRESS_GENERATING + * until one is available. + * @param string $currency literal for the currency (ex: LTC) + * @return array + */ + public function getDepositAddress ($currency) + { + return $this->callAccount ('getdepositaddress?currency='.$currency); + } + + /** + * Withdraw funds from your account. note: please account for txfee. + * @param string $currency literal for the currency (ex: LTC) + * @param float $quantity the quantity of coins to withdraw + * @param float $address the address where to send the funds + * @param float $paymentid (optional) used for CryptoNotes/BitShareX/Nxt optional field (memo/paymentid) + * @return array + */ + public function withdraw ($currency, $quantity, $address, $paymentid = null) + { + $params = 'currency='.$currency.'&quantity='.$quantity.'&address='.$address; + + if ($paymentid) { + $params .= '&paymentid='.$paymentid; + } + + return $this->callAccount ('withdraw?'.$params); + } + + /** + * Retrieve a single order by uuid + * @param string $uuid the uuid of the buy or sell order + * @return array + */ + public function getOrder ($uuid) + { + return $this->callAccount ('getorder?uuid='.$uuid); + } + + /** + * Retrieve your order history + * @param string $market (optional) a string literal for the market (ie. BTC-LTC). If ommited, will return for all markets + * @param integer $count (optional) the number of records to return + * @return array + */ + public function getOrderHistory ($market = null, $count = null) + { + $params = ''; + $separator = '?'; + + if ($market) { + $params .= $separator.'market='.$market; + $separator = '&'; + } + + if ($count) { + $params .= $separator.'count='.$count; + } + + return $this->callAccount ('getorderhistory'.$params); + } } // vim: noexpandtab