· 7 years ago · Aug 10, 2018, 05:54 PM
1<?php
2function btcid_query($method, array $req = array()) { // API settings
3$key = 'BLTN6YZJ-CQPDYOCI-A3XQJ0AA-OFF5R9DJ-POVKX5WF'; // your API-key $secret = 'a6683507c8af089095619f1065c67441db28762244ec8bfffdb7e73782374cecf51e71d3f8f89263'; // your Secret-key
4$req['method'] = $method; $req['nonce'] = time();
5// generate the POST data string $post_data = http_build_query($req, '', '&');
6$sign = hash_hmac('sha512', $post_data, $secret);
7// generate the extra headers $headers = array( 'Sign: '.$sign,
8'Key: '.$key,
9);
10// our curl handle (initialize if required) static $ch = null; if (is_null($ch)) { $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; INDODAXCOM PHP client; '.php_uname('s').'; PHP/'.phpversion().')');
11} curl_setopt($ch, CURLOPT_URL, 'https://indodax.com/tapi/');
12curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
13// run the query
14$res = curl_exec($ch);
15if ($res === false) throw new Exception('Could not get reply: '.curl_error($ch)); $dec = json_decode($res, true);
16if (!$dec) throw new Exception('Invalid data received, please make sure connection is working and requested API exists: '.$res);
17curl_close($ch); $ch = null; return $dec;
18}
19$result = btcid_query('getInfo'); print_r($result);