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 SDK is primarily designed for Node.js server-side environments, but it can also be bundled for use in browser-based applications using the included webpack configuration. The package ships with isomorphic-ws for WebSocket compatibility across environments, making it possible to use both REST and WebSocket functionality in the browser with some important caveats.
Never embed private API keys in client-side or browser code. Any API key included in a browser bundle can be extracted from the JavaScript source by anyone who visits your page. Use browser builds only for public, unauthenticated endpoints (e.g. reading public market tickers) — all authenticated trading operations must be performed server-side.

Supported Environments

EnvironmentSupport level
Node.js (v16+)✅ Full support — recommended for all trading applications
Browser (via webpack bundle)⚠️ Partial support — public endpoints only; some Node.js-only features are excluded
Edge/Serverless (Cloudflare Workers, etc.)⚠️ May work for REST; not officially tested
The SDK’s webpack configuration explicitly excludes the Node.js http and https core modules (which power the keepAlive connection pool feature) because those are not available in the browser. All other features compile cleanly.
// webpack/webpack.config.cjs — relevant section
resolve: {
  fallback: {
    // Node.js core modules not available in browsers
    // The REST client's https.Agent (for keepAlive) is Node.js-only
    "http": false,
    "https": false,
  },
},
This means keepAlive and keepAliveMsecs options in RestClientOptions are silently ignored in browser builds — connection pooling is handled automatically by the browser itself.

Building the Webpack Bundle

1

Install dependencies

Clone or download the gateio-api repository and install all dependencies, including the webpack dev dependencies:
npm install
2

Compile TypeScript

Run the TypeScript compiler to generate the compiled JavaScript output in dist/. This step produces both ESM (dist/mjs/) and CommonJS (dist/cjs/) builds:
npm run build
The webpack bundler uses the CommonJS output (dist/cjs/index.js) as its entry point.
3

Bundle with webpack

Run the webpack bundler to produce a single browser-compatible UMD bundle:
npm run pack
This runs webpack --config webpack/webpack.config.cjs and writes the output to dist/gateapi.js (with an accompanying dist/gateapi.map source map).

Bundle Output

After running npm run pack, the following files are written to the dist/ directory:
FileDescription
dist/gateapi.jsMinified UMD bundle — include this in your HTML or frontend build
dist/gateapi.mapSource map for debugging
doc/bundleReport.htmlBundle analyser report generated by webpack-bundle-analyzer
The bundle exposes the library as a UMD module named gateapi, making it accessible as window.gateapi when loaded via a <script> tag or importable by any module system that supports UMD.

Using the Bundle in HTML

<script src="dist/gateapi.js"></script>
<script>
  // Access the library via the UMD global
  const { RestClient } = window.gateapi;

  // Safe to use for public endpoints only
  const client = new RestClient();

  client.getSpotTicker({ currency_pair: 'BTC_USDT' }).then((ticker) => {
    console.log('BTC_USDT ticker:', ticker);
  });
</script>

Proxy and Custom Base URL Configuration

If your browser application routes requests through a backend proxy (recommended for authenticated calls), you can override the SDK’s base URL:
import { RestClient } from 'gateio-api';

const client = new RestClient({
  // Point the SDK at your own proxy server
  baseUrl: 'https://your-proxy.example.com/gate/v4',
});
For HTTP proxy support at the axios transport level, pass proxy configuration via the second networkOptions parameter, which is forwarded directly to axios:
import { RestClient } from 'gateio-api';

const client = new RestClient(
  {},
  {
    // axios proxy config — see https://axios-http.com/docs/req_config
    proxy: {
      protocol: 'http',
      host: '127.0.0.1',
      port: 8080,
    },
  },
);
Axios proxy configuration uses Node.js http/https agents and may not work in all browser environments. For browser-based proxying, a service worker or a custom baseUrl pointing to your own backend is more reliable.

Available baseUrlKey Options

Instead of specifying a full URL, you can select one of the SDK’s built-in base URL aliases:
const client = new RestClient({
  baseUrlKey: 'live',               // https://api.gateio.ws/api/v4 (default)
  // baseUrlKey: 'futuresLiveAlternative', // https://fx-api.gateio.ws/api/v4
  // baseUrlKey: 'futuresTestnet',         // https://fx-api-testnet.gateio.ws/api/v4
});

WebSocket Support in the Browser

The SDK uses isomorphic-ws, which automatically selects the native browser WebSocket API when running in a browser context. No additional configuration is required:
const { WebsocketClient } = window.gateapi;

// Public WebSocket streams work in the browser
const ws = new WebsocketClient({});

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

ws.subscribeTopic('spotV4', 'spot.tickers', ['BTC_USDT']);
Private WebSocket subscriptions require an API key and secret in the client options. Including credentials in browser code exposes them to end users. Restrict authenticated WebSocket usage to server-side Node.js processes.

Build docs developers (and LLMs) love