· 6 years ago · Feb 18, 2019, 09:48 PM
1function getCh($command, $params, $apiKeys) {
2 usleep(1000 * PAUSE_MS);
3 $publicKey = $apiKeys['public'];
4 $secretKey = $apiKeys['secret'];
5 $time = time() * 1000;
6 ksort($params);
7 $params = array_reverse($params);
8 $suffix = "";
9 if (!empty($params)) {
10 $suffix = '?'.http_build_query($params);
11 }
12 $strToSign = $time."GET"."/api/v1/".$command.$suffix;
13
14 $signature = base64_encode(hash_hmac('sha256', $strToSign, utf8_encode($secretKey), true)); // Hashing it
15
16 $ch = curl_init(API_URL."/v1/".$command.$suffix);
17
18 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
19 curl_setopt($ch, CURLOPT_HTTPHEADER,[
20 'Content-Type: application/json',
21 "KC-API-KEY: $publicKey",
22 "KC-API-TIMESTAMP: $time",
23 "KC-API-SIGN: $signature",
24 "KC-API-PASSPHRASE: cointracking",
25 ]);
26 return $ch;
27}