· 6 years ago · Mar 13, 2019, 01:18 PM
1function btcid_query($method, array $req = array()) {
2// API settings
3$key = ''; // your API-key
4$secret = ''; // your Secret-key
5$req['method'] = $method;
6$req['nonce'] = time();
7// generate the POST data string
8$post_data = http_build_query($req, '', '&');
9$sign = hash_hmac('sha512', $post_data, $secret);
10// generate the extra headers
11$headers = array(
12'Sign: '.$sign,
13'Key: '.$key,
14);
15// our curl handle (initialize if required)
16static $ch = null;
17if (is_null($ch)) {
18$ch = curl_init();
19curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
20curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; INDODAXCOM PHP client;
21'.php_uname('s').'; PHP/'.phpversion().')');
22}
23curl_setopt($ch, CURLOPT_URL, 'https://indodax.com/tapi/');
24curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
25curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
26curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
27// run the query
28$res = curl_exec($ch);
29if ($res === false) throw new Exception('Could not get reply: '.curl_error($ch));
30$dec = json_decode($res, true);
31if (!$dec) throw new Exception('Invalid data received, please make sure connection is working and
32requested API exists: '.$res);
33curl_close($ch);
34$ch = null;
35return $dec;
36}
37$result = btcid_query('getInfo');
38print_r($result);