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
| Type | Host |
|---|---|
| REST | https://openapi.lbank.com |
| websocket private channel | wss://openapi.lbank.com/wss/openapi/user/private |
| websocket public channel | wss://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
| Header | Required | Description |
|---|---|---|
| ex-api-key | Required for private endpoints. | Platform-issued API Key |
| ex-timestamp | Required for private endpoints. | Current Unix timestamp in nanoseconds (19 digits). |
| ex-nonce | Required for private endpoints. | random string, unique for each request, recommended 16-byte random hex |
| ex-signature | Required 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}
| Field | GET request | POST request |
|---|---|---|
method | GET, uppercase | POST, uppercase |
path | URL path, excluding query string | URL path, excluding query string |
canonicalQueryString | Query string sorted in lexicographical order by key-value dictionary | Fixed as empty string |
bodyHash | Fixed as empty string | SHA-256 hash of the original request body in bytes, in lowercase hexadecimal |
timestamp | Nanosecond-precision Unix timestamp, 19 digits | Same as GET |
nonce | Random string, unique for each request | Same 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
#fragmentportion 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
| Algorithm | Client-held | Signature Encoding |
|---|---|---|
HmacSHA256 | secretKey | lowercase hexadecimal, 64 characters |
SHA256withRSA | RSA private key | Standard Base64 |
RSASSA-PSS-SHA256 | RSA private key | Standard 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-timestampuses current nanosecond-level timestamp, andex-nonceis 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
- Timestamp is in nanoseconds (19 digits), not milliseconds (13 digits).
- 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.
- Nonce recommended to use 16-byte random number in hex format.
- The RSA public key must be in X.509 PEM format (
BEGIN PUBLIC KEY). PKCS#1 (BEGIN RSA PUBLIC KEY) is not supported. - Use standard Base64 for RSA signatures, including
+,/, and=. Keep the standard alphabet when sending signatures. - It is recommended to pass
APIinstead ofex-client-typeto 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
}