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.
WebsocketAPIClient is a high-level convenience wrapper around WebsocketClient that exposes Gate.io’s WebSocket API as a set of typed, promise-returning methods. Instead of calling sendWSAPIRequest() directly with raw channel strings, you call named methods like submitNewSpotOrder() or submitNewFuturesOrder() and receive strongly-typed responses. Under the hood, every method delegates to the embedded WebsocketClient, so all the same connection management, auto-reconnect, and re-authentication logic applies.
For the conceptual overview of how the WS API works, including topic structure and authentication flow, see the WebsocketClient reference.
Installation and Import
Constructor
WSClientConfigurableOptions (the same options as WebsocketClient) with the WSAPIClientConfigurableOptions fields specific to this client.
All options are optional.
Your Gate.io API key. Required to call any trading method — all WS API operations are authenticated.
Your Gate.io API secret. Required for request signing.
Default:
false. When true, connects to Gate.io testnet WebSocket endpoints. Do not pass a custom wsKey when using testnet — set this flag instead.Milliseconds added to the current timestamp when generating a WS API request signature. Useful for adjusting for minor clock skew between your system and Gate.io’s servers.
How often (in milliseconds) the underlying WebSocket connection sends a heartbeat ping.
How long (in milliseconds) to wait for a pong reply before treating the connection as dead.
Delay in milliseconds before attempting to reconnect after a dropped connection.
Default:
true. When true, the SDK automatically re-authenticates the WS API connection after any reconnect. Emits authenticated on success or exception (type wsapi.auth) after repeated failures. Set to false to handle re-authentication yourself via getWSClient().on('reconnected', ...).Default:
true. When true, the WebsocketAPIClient automatically attaches default console.log / console.error event listeners to the embedded WebsocketClient for high-level lifecycle events (open, reconnect, reconnected, authenticated, exception). Set to false if you want to configure your own listeners exclusively — you should then call getWSClient().on(...) to set them up.Provide a custom HMAC signing function. Useful for using Node.js’s
createHmac for faster signature generation. See the examples folder in the repository for a demonstration.A custom logger instance passed through to the embedded
WebsocketClient.Utility Methods
getWSClient()
WebsocketClient instance. Use this to attach event listeners, subscribe to market data topics, or call sendWSAPIRequest() directly for channels not yet covered by named methods.
setTimeOffsetMs(offset)
WSAPIResponse<T> Shape
Every trading method returns Promise<WSAPIResponse<T>>. The response object has the following structure:
response.data.result.
The Optional wsKey Parameter
Every trading method accepts an optional wsKey as its last argument. This lets you route the request through a specific WebSocket connection — for example, to use a BTC-settled futures connection instead of the default USDT-settled one.
- Spot methods default to
WS_KEY_MAP.spotV4 - Futures methods default to
WS_KEY_MAP.perpFuturesUSDTV4
Spot Trading Methods
Spot Trading Methods
All spot methods route through the
Place a new spot order. Equivalent to the REST
Cancel a single spot order by its order ID and currency pair.
Cancel multiple spot orders by providing an array of
Cancel all open spot orders for a specific currency pair, optionally filtered by side.
Amend (modify) an open spot order. You can update the price, amount, or both.
Fetch the current status of a single spot order.
List spot orders with flexible filtering options.
spotV4 WebSocket connection by default.submitNewSpotOrder(params, wsKey?)
POST /spot/orders endpoint but executed over WebSocket.Key parameters:| Field | Type | Required | Description |
|---|---|---|---|
currency_pair | string | ✅ | Trading pair, e.g. 'BTC_USDT' |
side | 'buy' | 'sell' | ✅ | Order side |
amount | string | ✅ | Order amount |
type | 'limit' | 'market' | — | Default: 'limit' |
price | string | — | Required for limit orders |
time_in_force | 'gtc' | 'ioc' | 'poc' | 'fok' | — | Time in force |
account | 'spot' | 'margin' | 'unified' | 'cross_margin' | — | Account type |
auto_borrow | boolean | — | Auto-borrow for margin |
auto_repay | boolean | — | Auto-repay after fill |
stp_act | 'cn' | 'co' | 'cb' | — | Self-trade prevention action |
action_mode | 'ACK' | 'RESULT' | 'FULL' | — | Response detail level |
text | string | — | Custom order label |
cancelSpotOrder(params, wsKey?)
| Field | Type | Required | Description |
|---|---|---|---|
order_id | string | ✅ | The order ID to cancel |
currency_pair | string | ✅ | Trading pair |
account | string | — | Account type |
cancelSpotOrderById(params, wsKey?)
{ id, currency_pair } objects. Returns an array of results, one per requested cancellation, each with a succeeded boolean.cancelSpotOrderForSymbol(params, wsKey?)
| Field | Type | Required | Description |
|---|---|---|---|
currency_pair | string | ✅ | Trading pair |
side | 'buy' | 'sell' | — | Filter by order side |
account | string | — | Account type |
updateSpotOrder(params, wsKey?)
| Field | Type | Required | Description |
|---|---|---|---|
order_id | string | ✅ | Order to amend |
currency_pair | string | ✅ | Trading pair |
price | string | — | New price |
amount | string | — | New amount |
amend_text | string | — | Custom amendment note |
account | string | — | Account type |
getSpotOrderStatus(params, wsKey?)
| Field | Type | Required | Description |
|---|---|---|---|
order_id | string | ✅ | Order ID |
currency_pair | string | ✅ | Trading pair |
account | string | — | Account type |
getSpotOrders(params, wsKey?)
| Field | Type | Required | Description |
|---|---|---|---|
currency_pair | string | ✅ | Trading pair |
status | 'open' | 'finished' | ✅ | Filter by order status |
page | number | — | Page number |
limit | number | — | Results per page |
account | string | — | Account type |
from | number | — | Start timestamp (Unix seconds) |
to | number | — | End timestamp (Unix seconds) |
side | 'buy' | 'sell' | — | Filter by side |
Futures Trading Methods
Futures Trading Methods
All futures methods default to the
Place a single perpetual futures order. Defaults to the USDT-settled perpetual futures connection.
Submit an array of futures orders in a single WS API call. Returns an array of result items, each extending
Cancel a single open futures order by ID.
Cancel multiple futures orders by providing an array of order ID strings. Returns one result item per order with an optional
Cancel all open futures orders for a specific contract, optionally filtered by side.
Amend (modify) an open futures order’s price or size.
List futures orders with filtering options.
Fetch the current status of a single futures order.
perpFuturesUSDTV4 connection (USDT-settled perpetual futures). Pass an explicit wsKey to route to a different futures connection.submitNewFuturesOrder(params, wsKey?)
submitNewFuturesBatchOrder(params, wsKey?)
WSAPIFuturesOrder with a succeeded boolean.cancelFuturesOrder(params, wsKey?)
cancelFuturesOrderById(params, wsKey?)
succeeded field and message on failure.cancelFuturesAllOpenOrders(params, wsKey?)
updateFuturesOrder(params, wsKey?)
getFuturesOrders(params, wsKey?)
getFuturesOrderStatus(params, wsKey?)
WSAPIFuturesOrder response shape: