Gate.com’s WebSocket API lets you send trading commands — place orders, cancel orders, amend orders, query order status — over the same persistent WebSocket connection used for data streams. Because the commands travel over an already-open socket rather than opening a new HTTP connection for each request, round-trip latency is significantly lower than a traditional REST call. TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/tiagosiebler/gateio-api/llms.txt
Use this file to discover all available pages before exploring further.
gateio-api SDK exposes this capability through two complementary interfaces: a lower-level event-driven method on WebsocketClient, and a higher-level promise-based WebsocketAPIClient that feels almost identical to a REST client.
Two Approaches at a Glance
- Event-Driven (WebsocketClient)
- Promise-Based (WebsocketAPIClient)
Use
sendWSAPIRequest(wsKey, channel, params) directly on a WebsocketClient instance. Each call returns a promise, but you can choose to fire-and-forget and receive the result asynchronously via the response event handler instead.Event-Driven Approach: sendWSAPIRequest
sendWSAPIRequest(wsKey, channel, params) is defined on WebsocketClient. It handles signing, connection assertion, and authentication assertion internally before dispatching the request over the wire.
Signature:
| Parameter | Type | Description |
|---|---|---|
wsKey | WSAPIWsKey | Which connection to use: 'spotV4', 'perpFuturesUSDTV4', 'perpFuturesBTCV4', 'deliveryFuturesUSDTV4', or 'deliveryFuturesBTCV4' |
channel | SpotWSAPITopic | FuturesWSAPITopic | The WS API channel, e.g. 'spot.order_place' |
params | Typed per channel | The request parameters (equivalent to req_param in Gate docs). Signature is generated automatically. |
Promise that resolves with the server’s response on success, or rejects if the connection drops or the server returns an exception. You can either await it directly (promise-driven) or call it without await and handle the result via ws.on('response', cb) (event-driven).
Promise-Based Approach: WebsocketAPIClient
WebsocketAPIClient is a thin, convenient wrapper over WebsocketClient that provides one method per trading operation. It is the recommended approach when you prefer a REST-like programming model.
Setup
Create an instance
WebsocketAPIClient attaches its own event listeners and logs connection lifecycle events to the console. Set attachEventListeners: false to suppress them and attach your own via wsApiClient.getWSClient().on(...).Authentication happens automatically before your first request. The
WebsocketAPIClient calls assertIsAuthenticated(wsKey) internally, so you never need to send a manual spot.login or futures.login frame. If reauthWSAPIOnReconnect: true is set (recommended), the SDK will also re-authenticate automatically up to five times after any reconnection event.Spot Methods
All spot methods default to thespotV4 WsKey. Pass an explicit wsKey as the second argument only if you need to route the request through a different supported connection.
| Method | Channel | Description |
|---|---|---|
submitNewSpotOrder(params) | spot.order_place | Place a new spot limit or market order |
cancelSpotOrder(params) | spot.order_cancel | Cancel an order by order_id |
cancelSpotOrderById(params[]) | spot.order_cancel_ids | Cancel a list of orders by id array |
cancelSpotOrderForSymbol(params) | spot.order_cancel_cp | Cancel all orders for a currency pair |
updateSpotOrder(params) | spot.order_amend | Amend the price or amount of an open order |
getSpotOrderStatus(params) | spot.order_status | Fetch the current status of a single order |
getSpotOrders(params) | spot.order_list | List open or finished orders |
Futures Methods
Futures methods default to theperpFuturesUSDTV4 WsKey. Pass a different WsKey (perpFuturesBTCV4, deliveryFuturesUSDTV4, deliveryFuturesBTCV4) as the second argument to target a different futures product.
| Method | Channel | Description |
|---|---|---|
submitNewFuturesOrder(params) | futures.order_place | Place a single futures order |
submitNewFuturesBatchOrder(params[]) | futures.order_batch_place | Place multiple futures orders in one request |
cancelFuturesOrder(params) | futures.order_cancel | Cancel an order by order_id |
cancelFuturesOrderById(params[]) | futures.order_cancel_ids | Cancel multiple orders by string ID array |
cancelFuturesAllOpenOrders(params) | futures.order_cancel_cp | Cancel all open orders for a contract |
updateFuturesOrder(params) | futures.order_amend | Amend price or size of an open order |
getFuturesOrders(params) | futures.order_list | List open or finished futures orders |
getFuturesOrderStatus(params) | futures.order_status | Get the status of a single futures order |
Full End-to-End Example
The following example demonstrates the completeWebsocketAPIClient workflow: instantiate, place a spot order, check its status, then cancel it.
Accessing the Underlying WebsocketClient
If you need to attach extra event listeners or subscribe to data streams alongside WS API calls, retrieve the internalWebsocketClient via getWSClient():