Skip to main content

Documentation 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.

The gateio-api package ships with a comprehensive set of TypeScript type definitions that cover every request parameter, API response shape, and WebSocket message structure in the SDK. Using these types brings three concrete benefits: your IDE can autocomplete field names as you type, the TypeScript compiler rejects missing required fields or incorrectly typed values at build time, and future SDK upgrades that change an interface will surface breaking changes immediately rather than silently at runtime.
For the full, searchable type browser with TSDoc comments, visit tsdocs.dev/docs/gateio-api. Every interface, type alias, and enum exported from the package is listed there with its field-level documentation.

How Types Are Exported

All request types, response types, and WebSocket types are re-exported from the single gateio-api entry point. You never need to import from a deep path like gateio-api/src/types/request/spot — just import from the package root:
import type { SubmitSpotOrderReq, SpotOrder } from 'gateio-api';
The main index.ts re-exports every module so your imports stay clean and stable across SDK versions.

Type Categories

Request types describe the parameters accepted by each REST endpoint or WebSocket API call. They live in src/types/request/ and are grouped by product area. Every module is re-exported from the package root.Available request modules:
ModuleProduct Area
request/spotSpot & margin trading
request/futuresPerpetual futures
request/deliveryDelivery futures
request/optionsOptions contracts
request/marginIsolated margin
request/marginuniUnified margin
request/walletWallet & deposits/withdrawals
request/withdrawalWithdrawal management
request/accountAccount settings
request/subaccountSub-account management
request/earnEarn / staking products
request/earnuniUnified earn
request/autoinvestAuto-invest plans
request/flashswapFlash swap
request/collateralLoanCollateral loans
request/multicollateralLoanMulti-collateral loans
request/unifiedUnified account
request/rebateReferral & rebate
request/crossexCross-exchange settlement
request/alphaAlpha products
request/otcOTC trading
request/p2pMerchantP2P merchant
request/tradfiTradFi products
Example: SubmitSpotOrderReq
import type { SubmitSpotOrderReq } from 'gateio-api';

// SubmitSpotOrderReq — parameters for placing a spot order
const order: SubmitSpotOrderReq = {
  currency_pair: 'BTC_USDT',
  side: 'buy',
  amount: '0.001',
  price: '60000',
  type: 'limit',
  time_in_force: 'gtc',
  account: 'spot',
};
Example: GetSpotOrdersReq
import type { GetSpotOrdersReq } from 'gateio-api';

// GetSpotOrdersReq — parameters for listing spot orders
const query: GetSpotOrdersReq = {
  currency_pair: 'ETH_USDT',
  status: 'open',
  limit: 50,
  account: 'unified',
};
Example: GetSpotOrderBookReq
import type { GetSpotOrderBookReq } from 'gateio-api';

const req: GetSpotOrderBookReq = {
  currency_pair: 'BTC_USDT',
  limit: 20,
  with_id: true,
};
Response types describe the shape of data returned by REST API calls. They live in src/types/response/ and mirror the request module organisation. Pass them as explicit type annotations or let TypeScript infer them from the client’s return types.Available response modules:
ModuleProduct Area
response/spotSpot markets, orders, balances
response/futuresPerpetual futures
response/deliveryDelivery futures
response/optionsOptions contracts
response/marginIsolated margin
response/marginuniUnified margin
response/walletWallet & transfers
response/accountAccount info
response/subaccountSub-account data
response/earnEarn products
response/earnuniUnified earn
response/flashswapFlash swap quotes & orders
response/collateralloanCollateral loan details
response/multicollateralLoanMulti-collateral loan details
response/unifiedUnified account balances
response/rebateRebate records
response/crossexCross-exchange data
response/alphaAlpha product responses
response/otcOTC responses
response/p2pMerchantP2P merchant data
response/tradfiTradFi responses
Example: SpotOrder
import type { SpotOrder } from 'gateio-api';

// SpotOrder — shape of a spot order returned by the REST API
// Key fields:
// id?: string                                — exchange-assigned order ID
// status?: 'open' | 'closed' | 'cancelled'  — current order state
// currency_pair: string                      — e.g. 'BTC_USDT'
// side: 'buy' | 'sell'
// amount: string                             — order quantity (string to preserve precision)
// price?: string                             — limit price
// filled_total?: string                      — total quote value filled
// avg_deal_price?: string                    — volume-weighted average fill price
// finish_as?: 'open' | 'filled' | 'cancelled' | 'ioc' | 'poc' | 'stp'

function printOrder(order: SpotOrder): void {
  console.log(`${order.id}: ${order.status} — filled ${order.filled_total}`);
}
Example: SpotTicker
import type { SpotTicker } from 'gateio-api';

function formatTicker(t: SpotTicker): string {
  return `${t.currency_pair}  last=${t.last}  24h vol=${t.base_volume}`;
}
These types control the WebsocketClient constructor and describe the shape of every real-time event you receive.WSClientConfigurableOptionsThe configuration interface accepted by the WebsocketClient constructor. All fields are optional.
import type { WSClientConfigurableOptions } from 'gateio-api';

const opts: WSClientConfigurableOptions = {
  apiKey: process.env.GATE_API_KEY,
  apiSecret: process.env.GATE_API_SECRET,
  useTestnet: false,
  recvWindow: 5000,
  pingInterval: 10000,
  pongTimeout: 5000,
  reconnectTimeout: 500,
  reauthWSAPIOnReconnect: true,
};
Key fields:
FieldTypeDescription
apiKeystringGate.io API key for authenticated channels
apiSecretstringGate.io API secret for signing
useTestnetbooleanConnect to testnet WebSocket URLs
recvWindownumberSignature validity window in ms
pingIntervalnumberHow often to send heartbeat pings (ms)
pongTimeoutnumberHow long to wait for a pong before reconnecting (ms)
reconnectTimeoutnumberDelay before attempting reconnection (ms)
reauthWSAPIOnReconnectbooleanRe-authenticate WS API automatically after reconnect
customSignMessageFn(msg, secret) => Promise<string>Custom HMAC signing function
WsKey and FuturesWsKeySee the WsKeys reference for the full listing of connection key types.
The WS API types describe the request and response shapes for Gate.io’s real-time order management API. These let you place, amend, cancel, and query orders over WebSocket with full type coverage.WSAPIResponse<T>Every WS API call resolves to a WSAPIResponse<T> where T is the specific result type. The generic wrapper carries metadata alongside the result:
import type { WSAPIResponse, WSAPISpotOrder } from 'gateio-api';

// WSAPIResponse<T> shape:
// {
//   wsKey: WsKey;                        — which connection produced this response
//   header: WSAPIResponseHeader<TChannel>; — response_time, status, channel, event
//   data: { result: T };                 — the actual payload
//   request_id: string;                  — auto-generated correlation ID
// }

async function placeOrder(ws: WebsocketAPIClient): Promise<void> {
  const response: WSAPIResponse<WSAPISpotOrder> =
    await ws.sendWSAPIRequest(
      'spotV4',
      'spot.order_place',
      {
        currency_pair: 'BTC_USDT',
        side: 'buy',
        amount: '0.001',
        price: '60000',
        type: 'limit',
      },
    );

  console.log('Order ID:', response.data.result.id);
  console.log('Status:', response.header.status); // '200' if successful
}
Spot WS API request types
TypeTopicDescription
WSAPISpotOrderPlaceReqspot.order_placePlace a new spot order
WSAPISpotOrderCancelReqspot.order_cancelCancel an order by ID
WSAPISpotOrderCancelIdsReqspot.order_cancel_idsCancel multiple orders by ID
WSAPISpotOrderCancelCPReqspot.order_cancel_cpCancel all orders for a currency pair
WSAPISpotOrderAmendReqspot.order_amendAmend price/amount of an open order
WSAPISpotOrderStatusReqspot.order_statusQuery a single order’s current state
WSAPISpotOrderListReqspot.order_listList open or closed orders
Futures WS API request types
TypeTopicDescription
WSAPIFuturesOrderPlaceReqfutures.order_placePlace a new futures order
WSAPIFuturesOrderCancelReqfutures.order_cancelCancel a futures order by ID
WSAPIFuturesOrderCancelCPReqfutures.order_cancel_cpCancel all orders for a contract
WSAPIFuturesOrderAmendReqfutures.order_amendAmend a futures order
WSAPIFuturesOrderListReqfutures.order_listList futures orders
WSAPIFuturesOrderStatusReqfutures.order_statusQuery a futures order’s state
WS API topic types
import type { SpotWSAPITopic, FuturesWSAPITopic, WSAPITopic } from 'gateio-api';

// SpotWSAPITopic — valid topic strings for spot WS API calls:
// 'spot.login' | 'spot.order_place' | 'spot.order_cancel' |
// 'spot.order_cancel_ids' | 'spot.order_cancel_cp' |
// 'spot.order_amend' | 'spot.order_status' | 'spot.order_list'

// FuturesWSAPITopic — valid topic strings for futures WS API calls:
// 'futures.login' | 'futures.order_place' | 'futures.order_batch_place' |
// 'futures.order_cancel' | 'futures.order_cancel_cp' | 'futures.order_amend' |
// 'futures.order_list' | 'futures.order_status' | 'futures.order_cancel_ids'

// WSAPITopic — union of both

Where Types Live in Source

src/
├── types/
│   ├── request/         # REST API request parameter types
│   │   ├── spot.ts
│   │   ├── futures.ts
│   │   ├── delivery.ts
│   │   ├── options.ts
│   │   └── ...
│   ├── response/        # REST API response shape types
│   │   ├── spot.ts
│   │   ├── futures.ts
│   │   └── ...
│   ├── websockets/      # WebSocket client config & message types
│   │   ├── client.ts    # WSClientConfigurableOptions, WebsocketClientOptions
│   │   ├── wsAPI.ts     # WSAPIResponse, WS API request/response types
│   │   ├── requests.ts  # Internal WebSocket request wrapper types
│   │   └── events.ts    # WebSocket event types
│   └── shared.ts        # Shared primitives (GateBaseUrlKey, CurrencyPair, etc.)

Practical Example: Typed Order Function

This example combines request types, response types, and the REST client to create a fully type-safe order placement helper:
import {
  RestClient,
  SubmitSpotOrderReq,
  SpotOrder,
} from 'gateio-api';

const client = new RestClient({
  apiKey: process.env.GATE_API_KEY,
  apiSecret: process.env.GATE_API_SECRET,
});

async function placeLimitBuy(
  pair: string,
  amount: string,
  price: string,
): Promise<SpotOrder> {
  const req: SubmitSpotOrderReq = {
    currency_pair: pair,
    side: 'buy',
    type: 'limit',
    amount,
    price,
    time_in_force: 'gtc',
    account: 'spot',
  };

  // The return type is inferred from the SDK's overloaded method signatures
  const order = await client.submitSpotOrder(req);
  return order;
}

// TypeScript enforces the shape at the call site:
// ✅ valid
const order = await placeLimitBuy('BTC_USDT', '0.001', '60000');
console.log(order.id, order.status);

// ❌ compile error — 'side' is required
// const bad = await client.submitSpotOrder({ currency_pair: 'BTC_USDT', amount: '0.001' });

Build docs developers (and LLMs) love