Node.js quickstart with JavaScript
Read the live BTC_USDT last price. This public request needs no API key or secret.
Installation
TypeScript definitions are included.
Install the npm package with your preferred tool:
npm install gateio-apipnpm add gateio-apiyarn add gateio-apibun add gateio-apideno add npm:gateio-apiPackage: gateio-api
npm: https://www.npmjs.com/package/gateio-apiFor other npm-compatible tools, use the same package from npm. Runtime-specific setup is covered below.
Choose your setup
Follow the guide for your runtime or framework. Each includes a complete project with commands to install dependencies and run it.
| Setup | Guides |
|---|---|
| Node.js | JavaScript or TypeScript |
| Alternative runtimes | Bun or Deno |
| Browser apps | React with Vite or Vite with plain JavaScript |
| Next.js | Node.js server Route Handler |
| Cloudflare Workers | Public prices and authenticated orders |
| Mobile apps | React Native / Expo for iOS and Android |
Browser and Expo guides include SDK-specific bundler configuration and polyfills where needed. See Runtime setup for project recipes and required configuration.
Use Node.js 24 for this quickstart. For other runtimes and required polyfills, see Runtime compatibility.
Make a request
Save this as prices.mjs:
import { RestClient } from 'gateio-api';
const client = new RestClient({}, { timeout: 10000 });
async function main() {
const tickers = await client.getSpotTicker({ currency_pair: 'BTC_USDT' });
const ticker = tickers[0];
if (!ticker) {
throw new Error('No BTC_USDT ticker returned.');
}
console.log('BTC_USDT last price:', ticker.last);
}
main().catch(() => {
console.error('Unable to read the public ticker.');
process.exitCode = 1;
});node prices.mjsExample output
BTC_USDT last price: 65000.1Your price will differ. getSpotTicker() returns an array, even when you request one pair. Price and quantity fields such as last are decimal strings. Pair names use underscores, as in BTC_USDT.
Module formats
The .mjs extension selects ES modules. For CommonJS, save a .cjs file, replace the import with const { RestClient } = require('gateio-api'), and keep the async function. TypeScript uses the same import with included types.
Market data · Streaming · Runtime setup · API reference
TypeScript integrations
The SDK works with both JavaScript and TypeScript. TypeScript is optional, but we strongly recommend it for SDK integrations: the included types help catch invalid method names, parameter shapes and response assumptions at build time, before requests reach the exchange. If you choose TypeScript, follow the TypeScript setup and run npx tsc --noEmit during development and CI. Type checking does not replace runtime validation or exchange-side checks.
Some runtimes can execute TypeScript directly. For example, Node.js type stripping supports erasable TypeScript syntax without a separate compiler, but does not check types. If your runtime cannot execute the syntax used by a TypeScript example, compile that example to JavaScript or use a compatible TypeScript runner. Examples with local .js imports that refer to TypeScript source files can use the compiler-based setup above. Plain JavaScript usage does not need any TypeScript tooling.
See TestNet for testing credentials, client settings and limitations.