Skip to main content

V3 API Integration Guide

Prerequisites​

To use the V3 API, your account must meet the following requirements:

  • Upgrade account to V3 version: to upgrade your account to V3 version, please contact Business Development (BD) or customer service
  • Create V3 version of API Key: after the account is upgraded to V3 version, please log in first API Management , create a V3 API Key, and follow this documentation to integrate the V3 API.

Important note: Some V3 API endpoints (order placement, order modification, withdrawal, transfer) are currently in beta testing and not yet open to the public. If you'd like to participate in beta testing, please contact Business Development (BD) or customer service for application.

Host​

TypeHost
RESThttps://openapi.lbank.com
websocket private channelwss://openapi.lbank.com/wss/openapi/user/private
websocket public channelwss://openapi.lbank.com/wss/openapi/public

Protocol and Authentication​

  • Protocol: HTTP/REST
  • API version: v3
  • Authentication: All private interfaces require API Key authentication. Public market data does not require authentication
  • Unified response format: {"code": 200, "message": "Success", "data": {...}}

Integration Example​

Request Headers

HeaderRequiredDescription
ex-api-keyRequired for private endpoints.Platform-issued API Key
ex-timestampRequired for private endpoints.Current Unix timestamp in nanoseconds (19 digits).
ex-nonceRequired for private endpoints.random string, unique for each request, recommended 16-byte random hex
ex-signatureRequired for private endpoints.Generated Signature Value

Signing

Private interfaces must include a complete signature in the Header. Users need to generate the signed string according to the rules in this document and compute the signature. The server will verify the signature based on timestamp, nonce, signature, and request content. The signed string consists of 6 segments, separated by a newline character \n:

{method}\n
{path}\n
{canonicalQueryString}\n
{bodyHash}\n
{timestamp}\n
{nonce}
FieldGET requestPOST request
methodGET, uppercasePOST, uppercase
pathURL path, excluding query stringURL path, excluding query string
canonicalQueryStringQuery string sorted in lexicographical order by key-value dictionaryFixed as empty string
bodyHashFixed as empty stringSHA-256 hash of the original request body in bytes, in lowercase hexadecimal
timestampNanosecond-precision Unix timestamp, 19 digitsSame as GET
nonceRandom string, unique for each requestSame as GET

Query sorting rules

  • Parameters are separated by &, sorted first by the ASCII order of keys, and then by values if keys are the same.
  • Retain the original percent-encoding in the URL. Do not perform additional encoding or decoding.
  • Remove the #fragment portion of the URL.
Original: symbol=BTCUSDT&side=BUY&recvWindow=&side=ASK
Sorted: recvWindow=&side=ASK&side=BUY&symbol=BTCUSDT

Original: b=+&a=2&b=%2B&a=1
Sorted: a=1&a=2&b=%2B&b=+

Signing Algorithms

AlgorithmClient-heldSignature Encoding
HmacSHA256secretKeylowercase hexadecimal, 64 characters
SHA256withRSARSA private keyStandard Base64
RSASSA-PSS-SHA256RSA private keyStandard Base64, PSS parameters with MGF1(SHA-256), salt length = 32
HmacSHA256:
signingKey = secretKey
signature = HMAC-SHA256(signingKey, payload) # Output as lowercase hex

SHA256withRSA:
signature = RSA-PKCS1v15-SHA256-sign(privateKey, UTF-8(payload)) # Output as standard Base64

RSASSA-PSS-SHA256:
signature = RSA-PSS-SHA256-sign(privateKey, UTF-8(payload)) # Output as standard Base64

Signing notes

  • Ensure ex-timestamp uses current nanosecond-level timestamp, and ex-nonce is unique for each request. Rapidly resubmitting identical business requests may be rejected by the server;
  • Do not simply replace the timestamp and nonce and repeatedly replay the same business request.
  • If a timestamp, nonce, signature, or duplicate request error is received, first verify that the local clock, nonce generation, payload concatenation, and body serialization match the actual sent content.
  • The body bytes used for POST request signing must exactly match the actual sent payload

HmacSHA256 signature example (Python)

import hashlib
import hmac
import json
import secrets
import time

def get_timestamp_ns() -> str:
return str(time.time_ns())

def new_nonce() -> str:
return secrets.token_hex(16)

def canonical_query_string(raw_qs: str) -> str:
if not raw_qs:
return ""
raw_qs = raw_qs.split("#")[0]
parts = raw_qs.split("&")
parts.sort(key=lambda p: (p.split("=", 1)[0], p.split("=", 1)[1] if "=" in p else ""))
return "&".join(parts)

def build_payload_get(path: str, canonical_qs: str, timestamp: str, nonce: str) -> str:
return f"GET\n{path}\n{canonical_qs}\n\n{timestamp}\n{nonce}"

def build_payload_post(path: str, body_bytes: bytes, timestamp: str, nonce: str) -> str:
body_hash = hashlib.sha256(body_bytes).hexdigest()
return f"POST\n{path}\n\n{body_hash}\n{timestamp}\n{nonce}"

def sign_hmac(secret_key: str, payload: str) -> str:
signing_key = secret_key.encode("utf-8")
return hmac.new(signing_key, payload.encode("utf-8"), hashlib.sha256).hexdigest()

# POST example: serialize once and use the same bytes for bodyHash and the HTTP body.
timestamp = get_timestamp_ns()
nonce = new_nonce()
path = "/api/v3/order/create"
body = {"category": "spot", "symbol": "btc_usdt", "side": "BUY", "orderType": "Limit", "qty": "1", "price": "100", "timeInForce": "GTC"}
body_bytes = json.dumps(body, separators=(",", ":")).encode("utf-8")
payload = build_payload_post(path, body_bytes, timestamp, nonce)
signature = sign_hmac("your_secret_key", payload)

Access considerations

  1. Timestamp is in nanoseconds (19 digits), not milliseconds (13 digits).
  2. The body bytes used for signing in a POST request must exactly match the actual sent data. Do not sign the request and then format the JSON or adjust field order.
  3. Nonce recommended to use 16-byte random number in hex format.
  4. The RSA public key must be in X.509 PEM format (BEGIN PUBLIC KEY). PKCS#1 (BEGIN RSA PUBLIC KEY) is not supported.
  5. Use standard Base64 for RSA signatures, including +, /, and =. Keep the standard alphabet when sending signatures.
  6. It is recommended to pass API instead of ex-client-type to facilitate downstream monitoring and troubleshooting

Order placement example

POST /api/v3/order/create HTTP/1.1
Host: openapi.lbank.com
Content-Type: application/json
ex-api-key: your_api_key
ex-timestamp: 1716508800000000000
ex-nonce: a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4
ex-signature: your_signature
ex-client-type: API

{
"category": "spot",
"symbol": "btc_usdt",
"side": "BUY",
"orderType": "Limit",
"qty": "20",
"price": "0.7",
"timeInForce": "GTC"
}
{
"code": 200,
"message": "Success",
"data": {
"orderId": "example_order_id",
"orderLinkId": "example_order_link_id"
},
"extras": null
}