Authentication V1
All API calls that touch a user account require authentication.
You must provide these headers on every private request:
X-PCK: API public key.X-Stamp: Current time in milliseconds since the Unix epoch (UTC).X-Signature: HMAC-SHA256 signature.X-Nonce(optional): Size, in milliseconds, of the acceptable backward time window forX-Stamp. See Nonce window below.
For API key instructions visit API Access Permissions
X-Stamp
X-Stamp is the current time in milliseconds since the Unix epoch (UTC). Keep your clock synchronised with NTP.
X-Nonce (time window)
X-Nonce controls how far back in time a request's X-Stamp is allowed to be, relative to the server's clock:
- If omitted or
<= 0, it defaults to5000(5 seconds). - Values above
60000(60 seconds) are clamped down to60000. - A request is accepted only if:
now - X-Nonce <= X-Stamp <= now + 5000
That is, X-Stamp may be up to X-Nonce milliseconds in the past, and up to a fixed 5000 milliseconds in the future (this forward tolerance is not configurable). Requests outside this window are rejected with 401 Unauthorized - Invalid Nonce.
X-Signature
X-Signature is a Base64-encoded HMAC-SHA256 signature computed over the concatenation of your public key and the X-Stamp value (publicKey + timestamp), signed with your Base64-decoded private key.
Each signature can be used for one request only; a repeated signature is rejected with 401 Invalid Signature. A signature is identified by your public key and X-Stamp, so give every request its own X-Stamp.
Code Example
- C#
- Python
- curl
var apiKey = "YOUR_API_PUBLIC_KEY";
var apiSecret = "YOUR_API_SECRET";
var nonce = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
string message = apiKey + nonce;
using (HMACSHA256 hmac = new HMACSHA256(Convert.FromBase64String(apiSecret)))
{
byte[] signatureBytes = hmac.ComputeHash(Encoding.UTF8.GetBytes(message));
string xSignature = Convert.ToBase64String(signatureBytes);
}
// Headers to send:
// X-PCK: {apiKey}
// X-Stamp: {nonce}
// X-Signature: {xSignature}
// X-Nonce: 5000 (optional, defaults to 5000 if omitted)
import base64, hashlib, hmac, time
apiKey = "YOUR_API_PUBLIC_KEY"
apiSecret = base64.b64decode("YOUR_API_SECRET")
stamp = str(int(time.time() * 1000))
data = "{}{}".format(apiKey, stamp).encode('utf-8')
signature = hmac.new(apiSecret, data, hashlib.sha256).digest()
signature = base64.b64encode(signature)
headers = {
"X-PCK": apiKey,
"X-Stamp": stamp,
"X-Signature": signature,
"Content-Type": "application/json"
}
curl -X GET "https://api.global.btcturk.com/api/v1/users/balances" \
-H "X-PCK: YOUR_API_PUBLIC_KEY" \
-H "X-Stamp: 1735866257711" \
-H "X-Signature: COMPUTED_SIGNATURE" \
-H "Content-Type: application/json"