Skip to content

[Patch 1] PHP language coding for my-order-history #124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions sample/php/my-order-history.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
$key = ''; //Fill in your key
$secret_key = ''; //Fill in your secret key
$API_HOST = 'https://api.bitkub.com';
// Step 1 : Request server time API
$ch1 = curl_init();
curl_setopt($ch1, CURLOPT_URL, "$API_HOST/api/servertime");
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, TRUE);
$responsetime = curl_exec($ch1);
$jsonArrayResponse = json_decode($responsetime);
curl_close($ch1);
$data =json_encode(array(
'sym' => 'THB_ADA',
'ts' => $jsonArrayResponse
),JSON_NUMERIC_CHECK);
// Step 2 : Hash Secret key with share256 with data
$signature = hash_hmac('sha256', $data, $secret_key);
echo (Int)$jsonArrayResponse;
//Prepare array data for POST with your cryptocurrency name
$postRequest =json_encode(array(
"sig" => $signature,
'sym' => 'THB_ADA', //change your cryptocurrency
'ts' => $jsonArrayResponse
),JSON_NUMERIC_CHECK);

var_dump($postRequest);

// Step 3 : Request API my-order-history with postRequest
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "$API_HOST/api/market/my-order-history");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postRequest);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json","Accept: application/json","X-BTK-APIKEY: ".$key));
$response = curl_exec($ch);
curl_close($ch);

// Here is result
echo $response;

?>