BTCex.cz api documentation

Overview

This page is documentation for RESTful API of project BTCex.cz

This API is mainly for our business partners, however, there are public methods which everybody can use and can be found useful.

If you are not a partner and want to be, please contact us at [email protected].

If you are a partner and need help with implementation or have improvement suggestions, please contact [email protected].

Technical details

Zalando RESTful API and Event Guidelines are followed.

For exact details of each endpoint please see OpenAPI specs.

Authentication

PHP example:

$body = null;
$key = 'syoihuudkjqc3882';
$nonce = rand() << 32 | rand();
$private = 'z2z77e0pl8rhtn9w';

$signature = hash_hmac('sha256',
    $key
    . "$"
    . $nonce
    . "$"
    . json_encode($body ?: [])//please note json_encode always inputs array even if $body is NULL
    ,
    $private);

// curl call itself
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://api.btcex.cz/');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);

if (!is_null($body)) {//post method if $body is not NULL
    curl_setopt($ch, CURLOPT_POST, true);
    $dataJson = json_encode($body);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $dataJson);
}

curl_setopt($ch, CURLOPT_HTTPHEADER, [
    "Content-Type: application/json",
    "btcex-key: $key",
    "btcex-nonce: $nonce",
    "btcex-signature: $signature",
    "btcex-test: 1",
]);
$response = curl_exec($ch);
curl_close($ch);


$rType = (string)curl_getinfo($ch, CURLINFO_CONTENT_TYPE);//application/json
$rCode = (int)curl_getinfo($ch, CURLINFO_RESPONSE_CODE);//return code
$rData = json_decode($response, true);//json decoded data

var_dump($rType);
var_dump($rCode);
var_dump($rData);
die();

On successful call you should get partner example.com

See following input and output variables for signature function in order to test you have it right:

$nonce = 4835119959885924862;
$key = 'syoihuudkjqc3882';
$private = 'z2z77e0pl8rhtn9w';
//-----
$body = null;
$signature = 'cb11e4c0411ced017a6fda9df5c34cc78898685e488b2b05769acc01c9cdf5b6';

$body = [];
$signature = 'cb11e4c0411ced017a6fda9df5c34cc78898685e488b2b05769acc01c9cdf5b6';

$body = ['foo' => 'bar'];
$signature = '9eb77611ed3afdee9d864b72014213d3bea615422feac0fa74b985e9c5c40aeb';

JS example:

At first you need to install libraries yarn add crypto axios

//Include libraries
var crypto = require("crypto");
var axios = require("axios");
//Initialize parameters
var body = null;
var key = "syoihuudkjqc3882";
var privateKey = "z2z77e0pl8rhtn9w";
var nonce = "4835119959885924862";
//Create hash
var hasher = crypto.createHmac("sha256", privateKey);

var hashKey = key + "$" + nonce + "$" + JSON.stringify(body || []);
var hash = hasher.update(hashKey).digest("hex");

//Send request
var apiUrl = "https://api.btcex.cz/";
var headers = {
    "Content-Type": "application/json",
    "btcex-key": key,
    "btcex-nonce": nonce,
    "btcex-signature": hash,
    "btcex-test": "1"
};

if (body) {
    axios.post(apiUrl, body, {headers: headers})
        .then(function (res) { console.log(res) })
        .catch(function (err) { console.log(err) });
} else {
    axios.get(apiUrl, {headers: headers})
        .then(function (res) { console.log(res) })
        .catch(function (err) { console.log(err) });
}
Created by BTCex.cz, Copyright © 2022 All Rights Reserved.