WebsocketAPIClient route through the private WebSocket channel and return a Promise that resolves when the server response arrives.
Response shape
Every method returns aWSAPIResponse<TData, TOperation>:
A
code other than '0' does not throw by default — check res.code and
the per-item sCode field inside res.data for operation-level errors.
Network or timeout errors will reject the promise.submitNewOrder()
Place a single order.Parameters
string
Instrument ID (e.g.
'BTC-USDT'). Deprecated from March 2026 — prefer instIdCode for lower latency.number
Numeric instrument ID code. Takes precedence over
instId when both are provided.
Use the Get instruments endpoint to map instrument names to codes.TradeMode
required
Trading mode:
'cash', 'cross', or 'isolated'.OrderSide
required
Order side:
'buy' or 'sell'.OrderType
required
Order type:
'market', 'limit', 'post_only', 'fok', 'ioc', etc.string
required
Quantity to buy or sell, as a numeric string.
string
Order price. Required for
limit, post_only, fok, and ioc order types.string
Client-assigned order ID (up to 32 alphanumeric characters). Used to identify the order in subsequent operations.
PositionSide
Position side in hedge mode:
'long' or 'short'.boolean
Whether the order can only reduce the position size.
'base_ccy' | 'quote_ccy'
Currency unit for
sz in spot orders. 'base_ccy' means sz is in the base currency; 'quote_ccy' means sz is in the quote currency.'cancel_maker' | 'cancel_taker' | 'cancel_both'
Self-trade prevention mode.
Example
submitMultipleOrders()
Place multiple orders in a single batch request.WSAPIPlaceOrderRequestV5 (same fields as submitNewOrder). The response data array has one entry per submitted order, each with its own sCode.
Example
cancelOrder()
Cancel a single open order.OrderIdRequest requires instId and at least one of ordId or clOrdId.
The response data contains:
Example
cancelMultipleOrders()
Cancel multiple open orders in one request.Example
amendOrder()
Amend the price or quantity of a single open order.Example
amendMultipleOrders()
Amend multiple open orders in a single request.Example
massCancelOrders()
Cancel all open orders for a given instrument type and family in one operation. Useful for risk management or when you need to flatten all positions quickly.data[0].result is true when the mass cancel was accepted.
Example
Promise-based error handling
The promise returned by each method:- Resolves with a
WSAPIResponseobject when a response arrives from the server, regardless of whether the operation succeeded at the business logic level. - Rejects when the request cannot be delivered (e.g. the WebSocket connection drops before the response is received, or a timeout occurs).

