Skip to main content

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/

HeaderValue
Content-Typeapplication/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.

FieldTypeDescription
chainIdnumberFixed value 56 (BSC Mainnet)
accountstringWallet 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:

  1. Connect Wallet — Go to https://kuant.ai/ and connect your wallet (MetaMask or any EVM-compatible wallet).
  2. Deposit Funds — Deposit assets on https://kuant.ai/ and ensure the deposit has been confirmed on-chain.
  3. Authenticate via API — Follow the authentication flow below to obtain a dex-token for 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-token

EIP-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

LayerFieldFixed ValueNotes
domainname"Dex"Must not be changed
domainversion"1.0.0"Must not be changed
domainchainId56BSC Mainnet; in JSON use string "56", in code use number
messageaction"Enable Trading"Case-sensitive, includes space
messagesignDomain"kuant.ai"Must not be changed
primaryType"UserAuth"Must not be changed

UserAuth Type Field Order

The UserAuth array field order must be:

  1. action (string)
  2. signDomain (string)

Order affects EIP-712 hash computation — must match exactly.

Signing Method by Environment

EnvironmentRecommended Method
Node.js (ethers v6)wallet.signTypedData(domain, types, message)
Node.js (viem)walletClient.signTypedData({ domain, types, primaryType, message })
MetaMask / Browserethereum.request({ method: "eth_signTypedData_v4", params: [address, jsonString] })
Pythoneth_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

HeaderValueRequired
Content-Typeapplication/jsonYes

Request Body

FieldTypeRequiredDescription
chainIdnumberYesChain ID (56 for BSC Mainnet)
userAddressstringYesUser wallet address
signatureTypeintegerYesSignature type: 2 = EIP-712, 3 = ethSign
rstringYesSignature r component
sstringYesSignature s component
vstringYesSignature v value ("27" or "28")
invitedCodestringNoReferral/invitation code

Example Request Body

{
  "chainId": 56,
  "userAddress": "0xYourWalletAddress",
  "signatureType": 2,
  "r": "0x...",
  "s": "0x...",
  "v": "27",
  "invitedCode": ""
}

Response

FieldTypeDescription
codenumberStatus code
msgstringStatus message
data.tokenstringThe 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.