API
Welcome to the Kuant.ai Perpetual DEX API. This documentation provides a complete REST API reference covering contract information, trading, positions, conditional orders, and all other features.
Complete API Documentation
Below is the complete API reference covering all endpoints with request/response parameter descriptions.
Base URL
https://api-dex.kuant.ai/
| Header | Value |
|---|---|
| Content-Type | application/json |
| dex-token | <token> (for authenticated endpoints) |
Common Request Body
Most endpoints automatically inject the following common body fields. They are not repeated in the endpoint-by-endpoint reference below, but you must include them in every authenticated request.
| Field | Type | Description |
|---|---|---|
chainId | number | Fixed value 56 (BSC Mainnet) |
account | string | Wallet address |
Important: Except for /dex/v1/user/auth, all endpoints require these two fields in the request body in addition to any endpoint-specific parameters listed in the API reference.
Prerequisites
Before using the API, complete the following steps:
- Connect Wallet — Go to https://kuant.ai/ and connect your wallet (MetaMask or any EVM-compatible wallet).
- Deposit Funds — Deposit assets on https://kuant.ai/ and ensure the deposit has been confirmed on-chain.
- Authenticate via API — Follow the authentication flow below to obtain a
dex-tokenfor subsequent API calls.
Authentication Flow
Kuant uses EIP-712 typed data signatures for user authentication. The full flow is:
1. Construct EIP-712 Typed Data (fixed structure, see below)
↓
2. Sign with wallet (eth_signTypedData_v4)
→ produces 65-byte signature (0x + 130 hex chars)
↓
3. Split signature into r, s, v
↓
4. POST /dex/v1/user/auth
body: { chainId, userAddress, signatureType, r, s, v }
↓
5. Extract response.data.token → this is your dex-tokenEIP-712 Signature Specification
The following typed data must be exactly identical — any change in field names, types, order, or values will cause signature verification to fail.
Complete Typed Data (for eth_signTypedData_v4)
{
"types": {
"EIP712Domain": [
{ "name": "name", "type": "string" },
{ "name": "version", "type": "string" },
{ "name": "chainId", "type": "uint256" }
],
"UserAuth": [
{ "type": "string", "name": "action" },
{ "type": "string", "name": "signDomain" }
]
},
"domain": {
"name": "Dex",
"version": "1.0.0",
"chainId": "56"
},
"primaryType": "UserAuth",
"message": {
"action": "Enable Trading",
"signDomain": "kuant.ai"
}
}Field Reference
| Layer | Field | Fixed Value | Notes |
|---|---|---|---|
| domain | name | "Dex" | Must not be changed |
| domain | version | "1.0.0" | Must not be changed |
| domain | chainId | 56 | BSC Mainnet; in JSON use string "56", in code use number |
| message | action | "Enable Trading" | Case-sensitive, includes space |
| message | signDomain | "kuant.ai" | Must not be changed |
| primaryType | — | "UserAuth" | Must not be changed |
UserAuth Type Field Order
The UserAuth array field order must be:
action(string)signDomain(string)
Order affects EIP-712 hash computation — must match exactly.
Signing Method by Environment
| Environment | Recommended Method |
|---|---|
| Node.js (ethers v6) | wallet.signTypedData(domain, types, message) |
| Node.js (viem) | walletClient.signTypedData({ domain, types, primaryType, message }) |
| MetaMask / Browser | ethereum.request({ method: "eth_signTypedData_v4", params: [address, jsonString] }) |
| Python | eth_account.messages.encode_typed_data + sign_message |
Code Example (ethers v6 / viem)
const domain = { name: "Dex", version: "1.0.0", chainId: 56 };
const types = {
UserAuth: [
{ name: "action", type: "string" },
{ name: "signDomain", type: "string" },
],
};
const message = {
action: "Enable Trading",
signDomain: "kuant.ai",
};
const signature = await wallet.signTypedData(domain, types, message);
// → "0x" + 130 hex chars (65 bytes)Signature Splitting: r / s / v
The auth endpoint requires the signature split into r, s, and v components (not the full signature string).
Algorithm
Input: signature = "0x" + 130 hex characters (65 bytes total)
r = "0x" + signature[2:66] // first 32 bytes
s = "0x" + signature[66:130] // middle 32 bytes
v = signature[130:132] → parse as decimal; if < 27, add 27
// final v is "27" or "28"TypeScript Implementation
function splitSignature(signature: string): { r: string; s: string; v: string } {
if (!signature?.startsWith("0x")) throw new Error("Invalid signature");
const sig = signature.slice(2);
if (sig.length !== 130) throw new Error("Invalid signature length");
const r = "0x" + sig.slice(0, 64);
const s = "0x" + sig.slice(64, 128);
let vDec = parseInt(sig.slice(128, 130), 16);
if (vDec < 27) vDec += 27;
return { r, s, v: String(vDec) };
}Python Implementation
def split_signature(signature: str) -> dict:
if not signature.startswith("0x"):
raise ValueError("Invalid signature")
sig = signature[2:]
if len(sig) != 130:
raise ValueError("Invalid signature length")
r = "0x" + sig[0:64]
s = "0x" + sig[64:128]
v_dec = int(sig[128:130], 16)
if v_dec < 27:
v_dec += 27
return {"r": r, "s": s, "v": str(v_dec)}Submit Authentication Request
POST /dex/v1/user/auth
Request Headers
| Header | Value | Required |
|---|---|---|
| Content-Type | application/json | Yes |
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
| chainId | number | Yes | Chain ID (56 for BSC Mainnet) |
| userAddress | string | Yes | User wallet address |
| signatureType | integer | Yes | Signature type: 2 = EIP-712, 3 = ethSign |
| r | string | Yes | Signature r component |
| s | string | Yes | Signature s component |
| v | string | Yes | Signature v value ("27" or "28") |
| invitedCode | string | No | Referral/invitation code |
Example Request Body
{
"chainId": 56,
"userAddress": "0xYourWalletAddress",
"signatureType": 2,
"r": "0x...",
"s": "0x...",
"v": "27",
"invitedCode": ""
}Response
| Field | Type | Description |
|---|---|---|
| code | number | Status code |
| msg | string | Status message |
| data.token | string | The dex-token for authenticated requests |
Use the returned data.token value as the dex-token header in all subsequent authenticated API calls.
Complete API Reference
Below are detailed descriptions of all endpoints, including request parameters, response data structures, etc.