diff --git a/bitfinex.v2.class.php b/bitfinex.v2.class.php index 0da43ad..37e0d91 100644 --- a/bitfinex.v2.class.php +++ b/bitfinex.v2.class.php @@ -1,11 +1,11 @@ api_secret)); @@ -35,23 +35,42 @@ private function headers($path) } /* Authenticated Endpoints Request */ - private function send_auth_endpoint_request($data) { + private function send_auth_endpoint_request($data, $postdata) { $ch=curl_init(); $url=self::API_URL.$data["request"]; - $headers=$this->headers($data); - + $headers=$this->headers($data, $postdata); + + if($postdata==false) + { + $postdata="{}"; + //echo 'Error to Here 1'; + $postdata2 ='{}'; + } + else if($postdata=="{}") + { + $postdata="{}"; + //echo 'Error to Here 2'; + $postdata2 ='{}'; + } + else + { + $postdata2 = http_build_query($postdata); + //echo $postdata2."
"; + } + curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, self::API_TIMEOUT); - curl_setopt($ch, CURLOPT_POSTFIELDS, "{}"); - + curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata2); + if(!$result=curl_exec($ch)) { return $this->curl_error($ch); } else { - return $this->output($result, $this->is_bitfinex_error($ch), $data); + //下方有一個output函數有修改過 + return $this->output($result, $this->is_bitfinex_error($ch), $data, $postdata); } } @@ -101,18 +120,23 @@ private function is_bitfinex_error($ch) { } /* Retrieve CURL response, if API err or RATE LIMIT hit, recall routine. Need to implement max retries. */ - private function output($result, $is_error=false, $command) { + private function output($result, $is_error=false, $command, $postdata) { $response=json_decode($result, true); if ($response[0]=="error" or $response["error"]=="ERR_RATE_LIMIT") { if (!is_array($command)) { - //echo "Retrying... '".$command."' in 10 seconds.\n"; + //echo "Retrying... '".$command."' in 10 seconds.
"; + //echo "First Type Error:".$response["error"]."
"; + //echo "First Type Error:".$response[0]."
"; sleep(10); return $this->send_public_endpoint_request($command); } else { - //echo "Retrying... '".$command["request"]."' in 10 seconds.\n"; + //echo "Retrying... '".$command["request"]."' in 10 seconds.
"; + //echo "Second Type Error:".$response["error"]."
"; + //echo "Second Type Error:".$response[0]."
"; sleep(10); - return $this->send_auth_endpoint_request($command); + //return $this->send_auth_endpoint_request($command, $postdata); + return $this->send_auth_endpoint_request($command,"{}"); } } else { if ($is_error) { @@ -168,7 +192,7 @@ public function get_orders() { $request=$this->build_url_path("auth/r/orders"); $data=array("request" => $request); - $orders=$this->send_auth_endpoint_request($data); + $orders=$this->send_auth_endpoint_request($data,"{}"); $o=array(); for ($z=0; $zbuild_url_path("auth/r/wallets"); $data=array("request" => $request); - - $balances=$this->send_auth_endpoint_request($data); + + $balances=$this->send_auth_endpoint_request($data,'{}'); $b=array(); $count=0; for ($z=0; $zbuild_url_path("auth/r/orders/".$symbol."/hist"); $data=array("request" => $request); - $balances=$this->send_auth_endpoint_request($data); + $balances=$this->send_auth_endpoint_request($data,'{}'); //format data $b=array(); $count=0; @@ -239,5 +263,33 @@ public function get_orderhist($symbol){ } return $b; } + + /* API: Get Ledgers - by symbol */ + public function get_ledgers($symbol){ + $request=$this->build_url_path("auth/r/ledgers/".$symbol."/hist"); + //$request=$this->build_url_path("auth/r/ledgers/hist"); + $data=array("request" => $request); + $limit = 30; + + $ledgerDetails = array('limit' => $limit); + + $balances=$this->send_auth_endpoint_request($data,$ledgerDetails); + //format data + $b=array(); + $count=0; + for ($z=0; $z