How to call private endpoints
Practical guide on how to start calling Kuna's private endpoints
First of all, please generate API keys, so you may start calling private endpoints.
After the exploration is completed, we highly recommend using signed requests option.
Header settings if a single API key is used
Header | Value | Description |
---|---|---|
accept | application/json | The client expects response data as JSON. |
content-type | application/json | The client sends data as JSON in the request body. |
api-key | YOUR_API_KEY | A single API keys string to authenticate. |
account | pro | To identify your account as a PRO account (Only for PRO accounts). |
Example. Get account balance using API key
const apiKey = "YOUR_API_KEY"; // put here your Api key
const url = "https://api.kuna.io";
const path = "/v4/private/getBalance"; // put here request path. To get your account balance: /v4/private/getBalance
const options = {
method: "GET",
headers: {
accept: "application/json",
"Content-Type": "application/json",
"api-key": apiKey,
},
};
fetch(url + path, options)
.then((response) => response.json())
.then((showResponse) => console.log(showResponse.data));
import requests
api_key = "YOUR_API_KEY" # put here your Api key
url = "https://api.kuna.io"
path = "/v4/private/getBalance" # put here request path. To get your account balance: /v4/private/getBalance
headers = {
"accept": "application/json",
"Content-Type": "application/json",
"api-key": api_key,
}
request = requests.get(url + path, headers=headers)
print(request.json())
Example. Create order using API key
Here we used single api-key
for authorization, no parameters, and we send this JSON in the request body:
const apiKey = "YOUR_API_KEY";
const url = "https://api.kuna.io";
const path = "/v4/order/private/create";
const body = {
type: "Limit",
orderSide: "Bid",
pair: "TRX_UAH",
quantity: "10.00",
price: "2.062",
};
const options = {
method: "POST",
headers: {
accept: "application/json",
"Content-Type": "application/json",
"api-key": apiKey,
},
body: JSON.stringify(body),
};
fetch(url + path, options)
.then((response) => response.json())
.then((showResponse) => console.log(showResponse.data));
import requests
api_key = "YOUR_API_KEY"
url = "https://api.kuna.io"
path = "/v4/order/private/create"
headers = {
"accept": "application/json",
"Content-Type": "application/json",
"api-key": api_key,
}
body = {
"type": "Limit",
"orderSide": "Bid",
"pair": "TRX_UAH",
"quantity": "10.00",
"price": "2.062",
}
request = requests.post(url + path, headers=headers, json=body)
print(request.json())
Header settings if public + private keys are used
Header | Value | Description |
---|---|---|
accept | application/json | The client expects response data as JSON. |
content-type | application/json | The client sends data as JSON in the request body. |
nonce | NONCE | Request Time Stamp. Put in Unix Time Stamp format in milliseconds (ms). |
public-key | YOUR_PUBLIC_KEY | Public key (It is in the second field when generating keys) string to authenticate. |
signature | SIGNATURE | Unique signature for your request. Check authorization section for more info. |
account | pro | To identify your account as a PRO account (Only for PRO accounts). |
Example. Get account balance using public + private keys
const crypto = require("crypto");
const publicKey = "YOUR_PUBLIC_KEY"; // put here your public key
const privateKey = "YOUR_PRIVATE_KEY"; // put here your private key
const url = "https://api.kuna.io";
const path = "/v4/private/getBalance";
const body = {}; // empty object for GET request
// Get UTC time in milliseconds
const nonce = +new Date(); // nonce is a number that is always higher than the previous request number
// Hashing signature
const signature = crypto
.createHmac("sha384", privateKey)
.update(`${path}${nonce}${JSON.stringify(body)}`)
.digest("hex");
const options = {
method: "GET",
headers: {
accept: "application/json",
"Content-Type": "application/json",
"public-key": publicKey,
nonce: nonce.toString(),
signature: signature,
},
};
fetch(url + path, options)
.then((response) => response.json())
.then((showResponse) => console.log(showResponse.data));
import json
import requests
import time
import hashlib
import hmac
public_key = "YOUR_PUBLIC_KEY" # put here your public key
private_key = "YOUR_PRIVATE_KEY" # put here your private key
url = "https://api.kuna.io"
path = "/v4/private/getBalance"
body = {} # empty object for GET request
# Get UTC time in milliseconds
nonce = str(int(time.time() * 1000)) # nonce is a number that is always higher than the previous request number
query_string = path + nonce + json.dumps(body)
# Hashing signature
signature = hmac.new(private_key.encode("utf-8"), query_string.encode("utf-8"), hashlib.sha384).hexdigest()
headers = {
"accept": "application/json",
"Content-Type": "application/json",
"public-key": public_key,
"nonce": nonce,
"signature": signature,
}
request = requests.get(url + path, headers=headers, json=body)
print(request.json())
Example. Create order using public + private keys
const crypto = require('crypto');
const publicKey = "YOUR_PUBLIC_KEY"; // put here your public key
const privateKey = "YOUR_PRIVATE_KEY"; // put here your private key
const url = "https://api.kuna.io";
const path = "/v4/order/private/create";
const body = {
type: "Limit",
orderSide: "Bid",
pair: "TRX_UAH",
quantity: "10.00",
price: "2.062",
};
// Get UTC time in milliseconds
const nonce = +new Date();
// Hashing signature
const signature = crypto
.createHmac("sha384", privateKey)
.update(`${path}${nonce}${JSON.stringify(body)}`)
.digest("hex");
const options = {
method: "POST",
headers: {
accept: "application/json",
"Content-Type": "application/json",
"public-key": publicKey,
nonce: nonce.toString(),
signature: signature,
},
body: JSON.stringify(body),
};
fetch(url + path, options)
.then((response) => response.json())
.then((showResponse) => console.log(showResponse.data));
import json
import requests
import time
import hashlib
import hmac
public_key = "YOUR_PUBLIC_KEY" # put here your public key
private_key = "YOUR_PRIVATE_KEY" # put here your private key
url = "https://api.kuna.io"
path = "/v4/order/private/create"
body = {
"type": "Limit",
"orderSide": "Bid",
"pair": "TRX_UAH",
"quantity": "10.00",
"price": "2.062",
}
# Get UTC time in milliseconds
nonce = str(int(time.time() * 1000)) # nonce is a number that is always higher than the previous request number
query_string = path + nonce + json.dumps(body, separators=(',', ':'))
# Hashing signature
signature = hmac.new(private_key.encode("utf-8"), query_string.encode("utf-8"), hashlib.sha384).hexdigest()
headers = {
"accept": "application/json",
"Content-Type": "application/json",
"public-key": public_key,
"nonce": nonce,
"signature": signature,
}
request = requests.post(url + path, headers=headers, json=body)
print(request.json())
Updated over 1 year ago