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.

Getting up and running with gateio-api takes just a few minutes. You’ll install the package, create API credentials on Gate.com, instantiate a client, and make your first live API call. This guide walks through each step and includes ready-to-run code for both TypeScript and JavaScript environments.
1
Install the package
2
Add gateio-api to your project using your preferred package manager.
3
npm
npm install gateio-api
yarn
yarn add gateio-api
pnpm
pnpm add gateio-api
4
The package ships with built-in TypeScript declarations — no separate @types/ package is needed.
5
Create your API credentials
6
Log in to your Gate.com account and navigate to the API Key Management page. Create a new API key and note both the API Key and API Secret. You’ll also need to configure the appropriate permissions (read, trade, etc.) depending on what your application needs to do.
7
Never commit your API key or secret to source control. Use environment variables or a secrets manager to keep credentials out of your codebase. Anyone who obtains your secret can trade on your behalf and withdraw funds if withdrawal permissions are enabled.
8
Create a client instance
9
Instantiate a RestClient with your credentials. Both TypeScript (ES module imports) and CommonJS (require) are supported.
10
TypeScript
import { RestClient } from 'gateio-api';

const client = new RestClient({
  apiKey: process.env.GATE_API_KEY,
  apiSecret: process.env.GATE_API_SECRET,
});
JavaScript (CommonJS)
const { RestClient } = require('gateio-api');

const client = new RestClient({
  apiKey: process.env.GATE_API_KEY,
  apiSecret: process.env.GATE_API_SECRET,
});
11
For public endpoints (market data that requires no authentication), you can omit the credentials entirely:
12
import { RestClient } from 'gateio-api';

const client = new RestClient();
13
Fetch spot tickers
14
Call getSpotTicker() with no arguments to retrieve all available spot trading pairs. This is a public endpoint and does not require API credentials.
15
TypeScript
import { RestClient } from 'gateio-api';

const client = new RestClient();

async function main() {
  try {
    const tickers = await client.getSpotTicker();
    console.log('All spot tickers:', tickers);
  } catch (e) {
    console.error('Error fetching tickers:', e);
  }
}

main();
JavaScript (CommonJS)
const { RestClient } = require('gateio-api');

const client = new RestClient();

async function main() {
  try {
    const tickers = await client.getSpotTicker();
    console.log('All spot tickers:', tickers);
  } catch (e) {
    console.error('Error fetching tickers:', e);
  }
}

main();
16
To fetch a single ticker, pass the currency_pair parameter:
17
const btcTicker = await client.getSpotTicker({ currency_pair: 'BTC_USDT' });
console.log('BTC_USDT ticker:', btcTicker);
18
Place a spot limit order
19
submitSpotOrder() places an order on the spot market. This is a private endpoint — your client must be initialised with valid credentials.
20
TypeScript
import { RestClient } from 'gateio-api';

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

async function placeLimitOrder() {
  try {
    const order = await client.submitSpotOrder({
      currency_pair: 'BTC_USDT',
      type: 'limit',
      account: 'spot',
      side: 'buy',
      amount: '0.001',
      price: '45000',
      time_in_force: 'gtc', // Good Till Cancelled
    });

    console.log('Order submitted:', order);
  } catch (e) {
    console.error('Order failed:', e);
  }
}

placeLimitOrder();
JavaScript (CommonJS)
const { RestClient } = require('gateio-api');

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

async function placeLimitOrder() {
  try {
    const order = await client.submitSpotOrder({
      currency_pair: 'BTC_USDT',
      type: 'limit',
      account: 'spot',
      side: 'buy',
      amount: '0.001',
      price: '45000',
      time_in_force: 'gtc',
    });

    console.log('Order submitted:', order);
  } catch (e) {
    console.error('Order failed:', e);
  }
}

placeLimitOrder();
21
Set price below the current market price when testing a buy order so it rests in the order book rather than filling immediately. Remember to cancel test orders when you’re done.
22
Subscribe to real-time WebSocket data
23
Use the WebsocketClient to subscribe to live spot ticker updates. The client manages the connection automatically and emits data through Node.js events.
24
TypeScript
import { WebsocketClient } from 'gateio-api';

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

// Listen for real-time updates
ws.on('update', (data) => {
  console.log('WebSocket update:', data);
});

ws.on('open', ({ wsKey }) => {
  console.log('Connection opened:', wsKey);
});

ws.on('response', (response) => {
  console.log('Subscription response:', response);
});

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

// Subscribe to spot ticker updates for BTC_USDT and ETH_USDT
ws.subscribe(
  {
    topic: 'spot.tickers',
    payload: ['BTC_USDT', 'ETH_USDT'],
  },
  'spotV4',
);
JavaScript (CommonJS)
const { WebsocketClient } = require('gateio-api');

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

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

ws.on('open', ({ wsKey }) => {
  console.log('Connection opened:', wsKey);
});

ws.on('response', (response) => {
  console.log('Subscription response:', response);
});

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

ws.subscribe(
  {
    topic: 'spot.tickers',
    payload: ['BTC_USDT', 'ETH_USDT'],
  },
  'spotV4',
);

Fetch Spot Account Balances

Once your client is authenticated, you can retrieve your spot account balances using getSpotAccounts():
import { RestClient } from 'gateio-api';

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

async function getBalances() {
  try {
    const balances = await client.getSpotAccounts();
    console.log('Spot balances:', balances);
  } catch (e) {
    console.error('Error fetching balances:', e);
  }
}

getBalances();

Next Steps

Authentication

Understand HMAC signing, testnet configuration, and security best practices.

Gate.com API Reference

Browse all available REST endpoints across every market.

Build docs developers (and LLMs) love