commit 07717698f5158351c8e7bbae89a73c1b87425f30 Author: Payeer-D Date: Tue May 3 12:54:43 2022 +0300 prototype php 5.6 diff --git a/class.php b/class.php new file mode 100644 index 0000000..00beb5e --- /dev/null +++ b/class.php @@ -0,0 +1,124 @@ +arParams = $params; + } + + + private function Request($req = array()) + { + $msec = round(microtime(true) * 1000); + $req['post']['ts'] = $msec; + + $post = json_encode($req['post']); + + $sign = hash_hmac('sha256', $req['method'].$post, $this->arParams['key']); + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, "https://payeer.com/api/trade/".$req['method']); + + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_HEADER, false); + //curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); + + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, $post); + + curl_setopt($ch, CURLOPT_HTTPHEADER, array( + "Content-Type: application/json", + "API-ID: ".$this->arParams['id'], + "API-SIGN: ".$sign + )); + + $response = curl_exec($ch); + curl_close($ch); + + $arResponse = json_decode($response, true); + + if ($arResponse['success'] !== true) + { + $this->arError = $arResponse['error']; + throw new Exception($arResponse['error']['code']); + } + + return $arResponse; + } + + + public function GetError() + { + return $this->arError; + } + + + public function Info() + { + $res = $this->Request(array( + 'method' => 'info', + )); + + return $res; + } + + + public function Orders($pair = 'BTC_USDT') + { + $res = $this->Request(array( + 'method' => 'orders', + 'post' => array( + 'pair' => $pair, + ), + )); + + return $res['pairs']; + } + + + public function Account() + { + $res = $this->Request(array( + 'method' => 'account', + )); + + return $res['balances']; + } + + + public function OrderCreate($req = array()) + { + $res = $this->Request(array( + 'method' => 'order_create', + 'post' => $req, + )); + + return $res; + } + + + public function OrderStatus($req = array()) + { + $res = $this->Request(array( + 'method' => 'order_status', + 'post' => $req, + )); + + return $res['order']; + } + + + public function MyOrders($req = array()) + { + $res = $this->Request(array( + 'method' => 'my_orders', + 'post' => $req, + )); + + return $res['items']; + } +}