DEV Community

Siebly
Siebly

Posted on Originally published at siebly.io

Gate.io JavaScript SDK quickstart for Node.js and TypeScript

Gate.io's API covers Spot, Margin, Unified, Perpetual Futures, Delivery, Options and several WebSocket connections. Product routing (currency pair vs contract, settlement currency, account type, WS key) is easy to get wrong. This quickstart walks through gateio-api, an MIT-licensed Node.js and TypeScript SDK maintained under the Siebly organisation, from install to a TestNet-ready flow.

The full reference lives in the Gate JavaScript SDK docs. This post mirrors the canonical Gate API JavaScript tutorial.

What you get

  • One RestClient for public and private REST across Gate product groups.
  • A WebsocketClient for public market streams and private account streams.
  • A WebsocketAPIClient for awaitable Spot and Futures order commands.
  • Explicit routing helpers (WS_KEY_MAP, settle, account, currency_pair, contract).
  • TestNet, regional hosts and optional HTTP/WebSocket proxy support.
  • TypeScript declarations with dual ESM and CommonJS builds.

Install

npm install gateio-api
Enter fullscreen mode Exit fullscreen mode

The package is published on npm as gateio-api and developed at github.com/sieblyio/gateio-api.

Your first public REST calls

Public Spot methods need no credentials. Start with server time, pair metadata, a ticker, a short order book and recent candles:

import { RestClient } from 'gateio-api';

const client = new RestClient();

async function main() {
  const time = await client.getServerTime();
  console.log('Server time:', time.server_time);

  const pair = await client.getSpotCurrencyPair({
    currency_pair: 'BTC_USDT',
  });
  console.log('BTC_USDT metadata:', pair);

  const tickers = await client.getSpotTicker({
    currency_pair: 'BTC_USDT',
  });
  console.log('BTC_USDT ticker:', tickers[0]);

  const orderBook = await client.getSpotOrderBook({
    currency_pair: 'BTC_USDT',
    limit: 5,
  });
  console.log('Best bid:', orderBook.bids[0]);
  console.log('Best ask:', orderBook.asks[0]);

  const candles = await client.getSpotCandles({
    currency_pair: 'BTC_USDT',
    interval: '1h',
    limit: 10,
  });
  console.log('Latest candle:', candles[0]);
}

main().catch((error) => {
  console.error('Request failed:', error);
});
Enter fullscreen mode Exit fullscreen mode

Keep product fields explicit: Spot uses currency_pair, Futures and Delivery use settle plus contract, and Spot orders that touch a specific account pass account.

Authenticated REST setup

Private methods need an API key and secret from Gate. Keep them in environment variables on a trusted backend only:

import { RestClient } from 'gateio-api';

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

const balances = await client.getSpotAccounts();
console.log('Spot balances:', balances.slice(0, 3));
Enter fullscreen mode Exit fullscreen mode

For Futures, pass settle on each request (for example 'usdt'). Use a separate TestNet key when you point the client at Gate's TestNet host.

WebSocket subscriptions

Public and private streams go through WebsocketClient. Pick the connection with WS_KEY_MAP so Spot and perpetual streams do not collide:

import { WebsocketClient } from 'gateio-api';

const ws = new WebsocketClient();

ws.on('update', (data) => {
  console.log('Update:', data);
});

ws.on('exception', (err) => {
  console.error('WebSocket error:', err);
});

// Public Spot ticker stream (second arg selects the Gate WS connection)
ws.subscribe(
  { topic: 'spot.tickers', payload: ['BTC_USDT'] },
  'spotV4',
);
Enter fullscreen mode Exit fullscreen mode

Private streams need the same API credentials as REST. Subscribe only after the client reports a successful auth on that connection.

WebSocket API order commands

When you want request/response style order commands over WebSocket, use WebsocketAPIClient for Spot or Futures, await the reply, then confirm final state over REST or a private fill stream. Details and examples are in the Gate tutorial.

TestNet, hosts and proxies

  • Keep live and TestNet API keys separate.
  • Select the matching baseUrl / wsUrl (or the SDK's TestNet option) before you send signed traffic.
  • Configure an HTTP(S) agent when your environment requires a proxy.

Next steps

Siebly also publishes typed SDKs for Binance, Bybit, OKX, Bitget, KuCoin, Coinbase, Kraken, HTX and Hyperliquid. See the Siebly SDK overview for the full set.

Top comments (0)