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