Overview
WebsocketAPIClient is a minimal, promise-driven wrapper around WebsocketClient. It lets you submit, cancel, and amend orders over WebSocket using async/await, without managing the underlying connection lifecycle yourself.
Each method sends a request over the appropriate private or business WebSocket connection and returns a promise that resolves when the matching response arrives from OKX.
WebsocketAPIClient uses WebsocketClient internally. You can access the underlying client at any time via wsApiClient.getWSClient() to subscribe to channels, listen to events, or call sendWSAPIRequest() directly.Constructor
object
Accepts all
WSClientConfigurableOptions fields (credentials, market, demo trading, etc.) plus the additional options below.DefaultLogger
Optional custom logger.
Additional options (WSAPIClientConfigurableOptions)
boolean
default:"true"
When
true, the client automatically attaches default event listeners that log connection lifecycle events (open, reconnect, reconnected, authenticated, exception) to the console.Set to false if you want to handle all events yourself via getWSClient().on(...).Utility methods
getWSClient()
WebsocketClient instance. Use this to subscribe to channels, listen to raw events, or call sendWSAPIRequest() directly.
connectWSAPI()
setTimeOffsetMs(offsetMs)
WebsocketClient.
Order management methods
All order methods require authentication. Credentials must be provided in the constructor options.submitNewOrder(params)
WSAPIPlaceOrderRequestV5
required
Order parameters. Key fields include:
instId(string, required) — Instrument ID, e.g.'BTC-USDT'.tdMode(string, required) — Trade mode:'cash','cross', or'isolated'.side(string, required) —'buy'or'sell'.ordType(string, required) — Order type:'market','limit','post_only','fok','ioc', etc.sz(string, required) — Order size.px(string) — Price. Required for limit orders.ccy(string) — Margin currency. Required for cross-margin on non-USDT pairs.clOrdId(string) — Client-assigned order ID.tag(string) — Order tag.
submitMultipleOrders(params)
WSAPIPlaceOrderRequestV5[]
required
Array of order parameter objects. Each entry follows the same shape as
submitNewOrder().cancelOrder(params)
OrderIdRequest
required
instId(string, required) — Instrument ID.ordId(string) — OKX order ID. EitherordIdorclOrdIdis required.clOrdId(string) — Client order ID.
cancelMultipleOrders(params)
OrderIdRequest[]
required
Array of order ID objects. Each entry follows the same shape as
cancelOrder().amendOrder(params)
WSAPIAmendOrderRequestV5
required
instId(string, required) — Instrument ID.ordId(string) — OKX order ID. EitherordIdorclOrdIdis required.clOrdId(string) — Client order ID.newSz(string) — New order size.newPx(string) — New order price.reqId(string) — Client-assigned request ID, echoed back in the response.
amendMultipleOrders(params)
WSAPIAmendOrderRequestV5[]
required
Array of amendment objects. Each entry follows the same shape as
amendOrder().massCancelOrders(params)
WSAPIMassCancelOrdersRequestV5
required
instType(string, required) — Instrument type, e.g.'OPTION'.instFamily(string, required) — Instrument family, e.g.'BTC-USD'.
Spread order methods
Spread order methods route through the business WebSocket connection.submitSpreadOrder(params)
WSAPIPlaceSpreadOrderRequestV5
required
sprdId(string, required) — Spread instrument ID.side(string, required) —'buy'or'sell'.ordType(string, required) — Order type:'limit','market','post_only','ioc', etc.sz(string, required) — Order size (number of contracts).px(string) — Price. Required for limit orders.clOrdId(string) — Client-assigned order ID.tag(string) — Order tag.
amendSpreadOrder(params)
WSAPIAmendSpreadOrderRequestV5
required
ordId(string) — OKX order ID. EitherordIdorclOrdIdis required.clOrdId(string) — Client order ID.newSz(string) — New order size.newPx(string) — New order price.reqId(string) — Client-assigned request ID, echoed back in the response.
cancelSpreadOrder(params)
WSAPICancelSpreadOrderRequestV5
required
ordId(string) — OKX order ID. EitherordIdorclOrdIdis required.clOrdId(string) — Client order ID.
massCancelSpreadOrders(params)
WSAPISpreadMassCancelOrdersRequestV5
required
sprdId(string, optional) — Spread instrument ID to target. Omit to cancel all open spread orders.

