Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ Updated & performant JavaScript & Node.js SDK for the Gate.com (gate.io) REST AP
- [WebSocket API](#websocket-api)
- [Event Driven API](#event-driven-api)
- [REST-like API](#rest-like-api)
- [Why not raw ws?](#why-not-raw-ws)
- [Customise Logging](#customise-logging)
- [Browser/Frontend Usage](#browserfrontend-usage)
- [Webpack](#webpack)
Expand Down Expand Up @@ -228,8 +229,31 @@ client
});
```

TestNet: set `useTestnet: true` on `RestClient` or `WebsocketClient`.

See [RestClient](./src/RestClient.ts) for further information, or the [examples](./examples/) for lots of usage examples.

## Why not raw ws?

Gate publishes [`gate-api`](https://www.npmjs.com/package/gate-api) as a generated REST client. This package, `gateio-api`, covers the REST API and a WebSocket client.

`WebsocketClient` keeps a public or private stream running:

- reconnects after a drop, including Gate's scheduled 24 hour disconnect
- heartbeats, and treats a missed pong as a dead connection
- resubscribes to the topics you asked for after reconnect
- signs private channels and WebSocket API requests
- typed events: `update`, `response`, `reconnected`, `exception`

Public spot tickers:

```javascript
const { WebsocketClient } = require('gateio-api');
const ws = new WebsocketClient();
ws.on('update', (data) => console.log(data));
ws.subscribe({ topic: 'spot.tickers', payload: ['BTC_USDT'] }, 'spotV4');
```

## WebSockets

All WebSocket functionality is supported via the unified `WebsocketClient`. This client handles all Gate.com WebSocket streams with automatic connection management and reconnection.
Expand Down
22 changes: 10 additions & 12 deletions docs/GATE_SDK_QUICKSTART_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ import { RestClient } from 'gateio-api';
const client = new RestClient({
apiKey: process.env.GATE_TESTNET_API_KEY,
apiSecret: process.env.GATE_TESTNET_API_SECRET,
baseUrl: 'https://api-testnet.gateapi.io/api/v4',
useTestnet: true,
});

async function main() {
Expand Down Expand Up @@ -899,7 +899,7 @@ import { RestClient } from 'gateio-api';
const client = new RestClient({
apiKey: process.env.GATE_TESTNET_API_KEY,
apiSecret: process.env.GATE_TESTNET_API_SECRET,
baseUrl: 'https://api-testnet.gateapi.io/api/v4',
useTestnet: true,
});

async function main() {
Expand Down Expand Up @@ -1062,7 +1062,7 @@ This TestNet example uses the REST API only to read current market rules and the
import { RestClient, WebsocketAPIClient, WS_KEY_MAP } from 'gateio-api';

const rest = new RestClient({
baseUrl: 'https://api-testnet.gateapi.io/api/v4',
useTestnet: true,
});

const wsApi = new WebsocketAPIClient({
Expand Down Expand Up @@ -1237,7 +1237,7 @@ import { RestClient, WebsocketAPIClient, WS_KEY_MAP } from 'gateio-api';
const rest = new RestClient({
apiKey: process.env.GATE_TESTNET_API_KEY,
apiSecret: process.env.GATE_TESTNET_API_SECRET,
baseUrl: 'https://api-testnet.gateapi.io/api/v4',
useTestnet: true,
});

const wsApi = new WebsocketAPIClient({
Expand Down Expand Up @@ -1738,25 +1738,23 @@ Gate TestNet is a separate environment with separate credentials. Use it for all
| REST API | `https://api-testnet.gateapi.io/api/v4` |
| Spot WebSocket | `wss://ws-testnet.gate.com/v4/ws/spot` |
| USDT perpetual WebSocket | `wss://ws-testnet.gate.com/v4/ws/futures/usdt` |
| Options WebSocket | `wss://ws-testnet.gate.com/v4/ws/options` |

Set the REST API host with `baseUrl` and the WebSocket host with `wsUrl`. Prefer explicit hosts for TestNet examples:

- Spot WebSocket TestNet is not wired through `useTestnet: true` in this SDK. The Spot testnet map entry is a stub (`NoTestnetForSpotWebsockets!`), so set `wsUrl` to the Spot TestNet host above.
- For Futures-only REST TestNet, the SDK also accepts `baseUrlKey: 'futuresTestnet'`, which resolves to `https://fx-api-testnet.gateio.ws/api/v4`. The Global TestNet REST host in the table is the host used by the Spot and Futures order examples in this guide.
For TestNet, set `useTestnet: true`.

```javascript
import { RestClient, WebsocketClient } from 'gateio-api';

const rest = new RestClient({
apiKey: process.env.GATE_TESTNET_API_KEY,
apiSecret: process.env.GATE_TESTNET_API_SECRET,
baseUrl: 'https://api-testnet.gateapi.io/api/v4',
useTestnet: true,
});

const spotWs = new WebsocketClient({
apiKey: process.env.GATE_TESTNET_API_KEY,
apiSecret: process.env.GATE_TESTNET_API_SECRET,
wsUrl: 'wss://ws-testnet.gate.com/v4/ws/spot',
useTestnet: true,
});
```

Expand Down Expand Up @@ -2073,7 +2071,7 @@ async function main() {
main();
```

To combine a proxy with TestNet or a regional API, keep `baseUrl` or `wsUrl` in the first client argument and the agent in the same positions shown above.
To combine a proxy with TestNet, set `useTestnet: true`. For a regional API, keep `baseUrl` or `wsUrl` in the first client argument and the agent in the same positions shown above.

The proxy's egress IP is the address Gate sees. Add that address to the API key whitelist when whitelisting is enabled. Use a stable proxy endpoint, monitor its latency, and never use a proxy to bypass account or regional restrictions.

Expand Down Expand Up @@ -2200,7 +2198,7 @@ Futures `size` is the number of contracts. Use `quanto_multiplier` to find the u

### Can live credentials be used in TestNet?

No. TestNet and live trading use separate API keys and balances. Use the current TestNet `baseUrl` or `wsUrl` with TestNet credentials.
No. TestNet and live trading use separate API keys and balances. Set `useTestnet: true` with TestNet credentials.

### Can I use Gate US or Gate EU with the SDK?

Expand Down
Loading
Loading