Simple API to get last price of BTC/DIGI.
Our API looks to be complicated, but really it isn't so difficult.
Please have a PHP code below to use it to get the last price BTC/DIGI, you can use as a framework to all your API requests (PRIVATE requests need authorization via /private/authenticate)
You will return with last ask price = $askprice
You will return with last bid price = $bidprice
<?php
$markets["market"] = "DIGI-BTC";
$markets["count"] = 1;
$postContent = json_encode($markets); // must send json encoded
// put together the request
$market = curl_init();
curl_setopt($market, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($market, CURLOPT_HTTPHEADER, array('Auth-Token: '.$headers['Auth-Token']));
curl_setopt($market, CURLOPT_RETURNTRANSFER, true);
curl_setopt($market, CURLOPT_URL, "
https://capitaldigi.com:443/gateway/public/bestOffer");
curl_setopt($market, CURLOPT_POST, true);
curl_setopt($market, CURLOPT_POSTFIELDS, $postContent);
curl_setopt($market, CURLOPT_HEADER, 1); // we want to see HTTP response headers to read the auth token
// now get the response and split into $responseHeader and $responseBody
$response = curl_exec($market);
$headerSize = curl_getinfo($market, CURLINFO_HEADER_SIZE);
$responseHeader = substr($response, 0, $headerSize);
$responeBody = substr($response, $headerSize);
// create key/value array from HTTP header
$headers_market = array();
foreach (preg_split("/\r?\n/", $responseHeader) as $line) {
if (strpos($line, ':') !== false) {
list($key, $value) = explode(': ', $line, 2);
$headers_market[$key] = $value;
}
}
// create array from JSON response body
$apiResponse = json_decode($responeBody, true);
if ($apiResponse['success']) {
$askprice = $apiResponse['results']['lastQuote'];
$bidprice = $apiResponse['results']['lastQuote'];
}
else {
echo "Request failed.\n\n";
}
echo '<br/>';
curl_close($market);
?>