Authentication
All API calls related to a user account, require authentication. You need to provide 4 parameters to authenticate a request:
| Key | Value |
|---|---|
| X-PCK | API Public Key |
| X-Stamp | Timestamp |
| X-Nonce | Delay Tolerance |
| X-Signature | Signature of Request |
warning
All these parameters must be sent from the header before sending a new request.
Signature
Signature is a HMAC-SHA256 encoded message. The HMAC-SHA256 code must be generated using a private key that contains a current timestamp and your API key.
Nonce
Nonce is a integer number. The value sent determines the connection delay tolerance. For example, if the Nonce value is 15000 (15 seconds), and your request meets the condition (X-Stamp + X-Nonce < Current Server Timestamp), your request will fail. This is because the request you sent reaches the server later than the Nonce value
Code Examples:
- C#
- Python
- Node.js
public async Task Connect()
{
string publicKey = "PUBLIC_KEY";
string privateKey = "PRIVATE_KEY";
long nonce = 60000;
long timestamp = DateTimeExtension.ToUnixTime(DateTime.UtcNow);
string baseString = $"{publicKey}{timestamp}";
string signature = ComputeHash(privateKey, baseString);
Dictionary<string, string> headers = new Dictionary<string, string>
{
{"X-PCK", publicKey},
{"X-Signature", signature},
{"X-Stamp", timestamp.ToString()},
{"X-Nonce", nonce.ToString()}
};
}
private string ComputeHash(string privateKey, string message)
{
byte[] key = Convert.FromBase64String(privateKey);
string hashString;
using (HMACSHA256 hmac = new HMACSHA256(key))
{
byte[] hash = hmac.ComputeHash(Encoding.UTF8.GetBytes(message));
hashString = Convert.ToBase64String(hash);
}
return hashString;
}
class InterfaceWS:
def __init__(self, exchange_name: str = None) -> None:
self.exchange_name = "HFT API"
self.uri = "ws://{BASEURL}:8080"
async def authenticate_ws(self) -> bool:
publicKey = "PUBLIC_KEY"
privateKey = "PRIVATE_KEY"
nonce = 15000 //
timestamp = round(time.time() * 1000)
baseString = "{}{}".format(publicKey, timestamp).encode("utf-8")
signature = hmac.new(
base64.b64decode(privateKey), baseString, hashlib.sha256
).digest()
signature = base64.b64encode(signature)
headers = {
"X-PCK": publicKey,
"X-Nonce": str(nonce),
"X-Stamp": str(timestamp),
"X-Signature": signature.decode("utf-8")
}
const nonce = 15000;
const stamp = (new Date()).getTime();
const baseString = `${publicKey}${stamp}`;
const data = Buffer.from(baseString, 'utf8');
const buffer = crypto.createHmac('sha256', Buffer.from(privateKey, 'base64'));
buffer.update(data);
const signature = buffer.digest().toString('base64');
const headers = {
"X-PCK": publicKey,
"X-Nonce": String(nonce),
"X-Stamp": String(stamp),
"X-Signature": signature
};