You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Automatically handle silent websocket disconnections through timed heartbeats, including the scheduled 24hr disconnect.
34
34
- Automatically handle listenKey persistence and expiration/refresh.
35
35
- Emit `reconnected` event when dropped connection is restored.
36
-
- Websocket API for Gate.io Spot, Margin, Perpetual Futures & Delivery Futures.
36
+
- Websocket API for Gate.com Spot, Margin, Perpetual Futures & Delivery Futures.
37
37
- Automatic connectivity via existing WebsocketClient, just call sendWSAPIRequest to trigger a request.
38
38
- Automatic authentication, just call sendWSAPIRequest with channel & parameters.
39
39
- Choose between two interfaces for WS API communication:
40
40
- Event-driven interface, fire & forget via sendWSAPIRequest and receive async replies via wsClient's event emitter.
41
-
- Promise-driven interface, simply call and await sendWSAPIRequest for a REST-API-like behaviour with the WS API.
41
+
- Promise-driven interface, simply use the WebsocketAPIClient for a REST-like experience. Use the WebSocket API like a REST API! See [examples/ws-api-client.ts](./examples/ws-api-client.ts) for a demonstration.
42
42
- Proxy support via axios integration.
43
43
- Active community support & collaboration in telegram: [Node.js Algo Traders](https://t.me/nodetraders).
44
44
@@ -78,7 +78,7 @@ Check out my related JavaScript/TypeScript/Node.js projects:
78
78
79
79
Most methods accept JS objects. These can be populated using parameters specified by gateio's API documentation.
80
80
81
-
-[Gate.io API Documentation](https://www.gate.io/docs/developers/apiv4/en/)
81
+
-[Gate.com/gate.io API Documentation](https://www.gate.com/docs/developers/apiv4/en/)
82
82
-[REST Endpoint Function List](./docs/endpointFunctionList.md)
83
83
-[TSDoc Documentation (autogenerated using typedoc)](https://tsdocs.dev/docs/gateio-api)
84
84
@@ -95,11 +95,11 @@ This project uses typescript. Resources are stored in 2 key structures:
95
95
96
96
Create API credentials
97
97
98
-
-[Gate.io API Key Management](https://www.gate.io/myaccount/api_key_manage)
98
+
-[Gate.com API Key Management](https://www.gate.com/myaccount/api_key_manage)
99
99
100
100
### REST API
101
101
102
-
To use any of Gate.io's REST APIs in JavaScript/TypeScript/Node.js, import (or require) the `RestClient`:
102
+
To use any of Gate.com's REST APIs in JavaScript/TypeScript/Node.js, import (or require) the `RestClient`:
103
103
104
104
```javascript
105
105
const { RestClient } =require('gateio-api');
@@ -252,107 +252,114 @@ See [WebsocketClient](./src/WebsocketClient.ts) for further information and make
252
252
253
253
### Websocket API
254
254
255
-
The [WebsocketClient](./src/WebsocketClient.ts) supports this exchange's Websocket API. There are two ways to use the WS API, depending on individual preference:
255
+
Gate.com supports sending requests (commands) over an active WebSocket connection. This is called the WebSocket API.
256
+
257
+
The WebSocket API is available through two approaches, depending on individual preference:
258
+
259
+
#### Event Driven API
260
+
261
+
The WebSocket API is available in the [WebsocketClient](./src/WebsocketClient.ts) via the `sendWSAPIRequest(wsKey, channel, params)` method.
262
+
263
+
Each call to this method is wrapped in a promise, which you can async await for a response, or handle it in a raw event-driven design.
256
264
257
265
- event-driven:
258
-
- send requests via `client.sendWSAPIRequest(wsKey, channel, params)`, fire and forget, don't use await
266
+
- send requests via `client.sendWSAPIRequest(wsKey, channel, params).catch(e => console.error('WS API exception for channel', channel, e))`, fire and forget, don't use await
259
267
- handle async replies via event handlers on `client.on('exception', cb)` and `client.on('response', cb)`
260
268
- promise-driven:
261
269
- send requests via `const result = await client.sendWSAPIRequest(wsKey, channel, params)`, which returns a promise
262
270
- await each call
263
271
- use try/catch blocks to handle promise rejections
264
272
265
-
The below example demonstrates the promise-driven approach, which behaves similar to a REST API. For more detailed examples, refer to the [examples](./examples/) folder (e.g the [ws-private-spot-wsapi.ts](./examples/ws-private-spot-wsapi.ts) example).
273
+
#### REST-like API
274
+
275
+
The WebSocket API is also available in a promise-wrapped REST-like format. Either, as above, await any calls to `sendWSAPIRequest(...)`, or directly use the convenient WebsocketAPIClient. This class is very similar to existing REST API classes (such as the RestClient).
276
+
277
+
It provides one function per endpoint, feels like a REST API and will automatically route your request via an automatically persisted, authenticated and health-checked WebSocket API connection.
278
+
279
+
Below is an example showing how easy it is to use the WebSocket API without any concern for the complexity of managing WebSockets.
* To authenticate, send an empty request to "spot.login". The SDK will handle all the parameters.
325
-
*
326
-
* By default (reauthWSAPIOnReconnect: true), if we get reconnected later on (e.g. connection temporarily lost), we will try to re-authenticate the WS API automatically when the connection is restored.
Copy file name to clipboardExpand all lines: docs/endpointFunctionList.md
+26-1Lines changed: 26 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,6 +20,7 @@ All REST clients are in the [src](/src) folder. For usage examples, make sure to
20
20
21
21
List of clients:
22
22
-[RestClient](#RestClientts)
23
+
-[WebsocketAPIClient](#WebsocketAPIClientts)
23
24
24
25
25
26
If anything is missing or wrong, please open an issue or let us know in our [Node.js Traders](https://t.me/nodetraders) telegram group!
@@ -333,4 +334,28 @@ This table includes all endpoints from the official Exchange API docs and corres
333
334
|[getPartnerSubordinateList()](https://github.com/tiagosiebler/gateio-api/blob/master/src/RestClient.ts#L4472)|:closed_lock_with_key:| GET |`/rebate/partner/sub_list`|
334
335
|[getBrokerCommissionHistory()](https://github.com/tiagosiebler/gateio-api/blob/master/src/RestClient.ts#L4486)|:closed_lock_with_key:| GET |`/rebate/broker/commission_history`|
335
336
|[getBrokerTransactionHistory()](https://github.com/tiagosiebler/gateio-api/blob/master/src/RestClient.ts#L4499)|:closed_lock_with_key:| GET |`/rebate/broker/transaction_history`|
336
-
|[getUserRebateInfo()](https://github.com/tiagosiebler/gateio-api/blob/master/src/RestClient.ts#L4508)|:closed_lock_with_key:| GET |`/rebate/user/info`|
337
+
|[getUserRebateInfo()](https://github.com/tiagosiebler/gateio-api/blob/master/src/RestClient.ts#L4508)|:closed_lock_with_key:| GET |`/rebate/user/info`|
338
+
339
+
# WebsocketAPIClient.ts
340
+
341
+
This table includes all endpoints from the official Exchange API docs and corresponding SDK functions for each endpoint that are found in [WebsocketAPIClient.ts](/src/WebsocketAPIClient.ts).
342
+
343
+
This client provides WebSocket API endpoints which allow for faster interactions with the Gate.io API via a WebSocket connection.
// This example shows how to call this Gate.io WebSocket API endpoint with either node.js, javascript (js) or typescript (ts) with the npm module "gateio-api" for Gate.io exchange
4
+
// This Gate.io API SDK is available on npm via "npm install gateio-api"
5
+
// WS API ENDPOINT: futures.order_cancel_cp
6
+
// METHOD: WebSocket API
7
+
// PUBLIC: NO
8
+
9
+
// Create a WebSocket API client instance
10
+
constclient=newWebsocketAPIClient({
11
+
apiKey: 'insert_api_key_here',
12
+
apiSecret: 'insert_api_secret_here',
13
+
});
14
+
15
+
// The WebSocket connection is established automatically when needed
16
+
// You can use the client to make requests immediately
17
+
18
+
// Example use of the cancelFuturesAllOpenOrders method
// This example shows how to call this Gate.io WebSocket API endpoint with either node.js, javascript (js) or typescript (ts) with the npm module "gateio-api" for Gate.io exchange
4
+
// This Gate.io API SDK is available on npm via "npm install gateio-api"
5
+
// WS API ENDPOINT: futures.order_cancel
6
+
// METHOD: WebSocket API
7
+
// PUBLIC: NO
8
+
9
+
// Create a WebSocket API client instance
10
+
constclient=newWebsocketAPIClient({
11
+
apiKey: 'insert_api_key_here',
12
+
apiSecret: 'insert_api_secret_here',
13
+
});
14
+
15
+
// The WebSocket connection is established automatically when needed
16
+
// You can use the client to make requests immediately
// This example shows how to call this Gate.io WebSocket API endpoint with either node.js, javascript (js) or typescript (ts) with the npm module "gateio-api" for Gate.io exchange
4
+
// This Gate.io API SDK is available on npm via "npm install gateio-api"
5
+
// WS API ENDPOINT: futures.order_cancel_ids
6
+
// METHOD: WebSocket API
7
+
// PUBLIC: NO
8
+
9
+
// Create a WebSocket API client instance
10
+
constclient=newWebsocketAPIClient({
11
+
apiKey: 'insert_api_key_here',
12
+
apiSecret: 'insert_api_secret_here',
13
+
});
14
+
15
+
// The WebSocket connection is established automatically when needed
16
+
// You can use the client to make requests immediately
17
+
18
+
// Example use of the cancelFuturesOrderById method
0 commit comments