gateio-api 0.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +251 -106
- package/dist/cjs/RestClient.d.ts +2534 -0
- package/dist/cjs/RestClient.js +2700 -0
- package/dist/cjs/RestClient.js.map +1 -0
- package/dist/cjs/WebsocketClient.d.ts +107 -0
- package/dist/cjs/WebsocketClient.js +504 -0
- package/dist/cjs/WebsocketClient.js.map +1 -0
- package/dist/cjs/index.d.ts +43 -0
- package/dist/cjs/index.js +64 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/lib/BaseRestClient.d.ts +63 -0
- package/dist/cjs/lib/BaseRestClient.js +324 -0
- package/dist/cjs/lib/BaseRestClient.js.map +1 -0
- package/dist/cjs/lib/BaseWSClient.d.ts +172 -0
- package/dist/cjs/lib/BaseWSClient.js +619 -0
- package/dist/cjs/lib/BaseWSClient.js.map +1 -0
- package/dist/cjs/lib/logger.d.ts +6 -0
- package/dist/cjs/lib/logger.js +16 -0
- package/dist/cjs/lib/logger.js.map +1 -0
- package/dist/cjs/lib/misc-util.d.ts +1 -0
- package/dist/cjs/lib/misc-util.js +8 -0
- package/dist/cjs/lib/misc-util.js.map +1 -0
- package/dist/cjs/lib/requestUtils.d.ts +38 -0
- package/dist/cjs/lib/requestUtils.js +47 -0
- package/dist/cjs/lib/requestUtils.js.map +1 -0
- package/dist/cjs/lib/webCryptoAPI.d.ts +10 -0
- package/dist/cjs/lib/webCryptoAPI.js +57 -0
- package/dist/cjs/lib/webCryptoAPI.js.map +1 -0
- package/dist/cjs/lib/websocket/WsStore.d.ts +57 -0
- package/dist/cjs/lib/websocket/WsStore.js +249 -0
- package/dist/cjs/lib/websocket/WsStore.js.map +1 -0
- package/dist/cjs/lib/websocket/WsStore.types.d.ts +44 -0
- package/dist/cjs/lib/websocket/WsStore.types.js +13 -0
- package/dist/cjs/lib/websocket/WsStore.types.js.map +1 -0
- package/dist/cjs/lib/websocket/websocket-util.d.ts +78 -0
- package/dist/cjs/lib/websocket/websocket-util.js +153 -0
- package/dist/cjs/lib/websocket/websocket-util.js.map +1 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/types/request/account.d.ts +10 -0
- package/dist/cjs/types/request/account.js +7 -0
- package/dist/cjs/types/request/account.js.map +1 -0
- package/dist/cjs/types/request/collateralLoan.d.ts +39 -0
- package/dist/cjs/types/request/collateralLoan.js +7 -0
- package/dist/cjs/types/request/collateralLoan.js.map +1 -0
- package/dist/cjs/types/request/delivery.d.ts +89 -0
- package/dist/cjs/types/request/delivery.js +7 -0
- package/dist/cjs/types/request/delivery.js.map +1 -0
- package/dist/cjs/types/request/earn.d.ts +16 -0
- package/dist/cjs/types/request/earn.js +7 -0
- package/dist/cjs/types/request/earn.js.map +1 -0
- package/dist/cjs/types/request/earnuni.d.ts +30 -0
- package/dist/cjs/types/request/earnuni.js +7 -0
- package/dist/cjs/types/request/earnuni.js.map +1 -0
- package/dist/cjs/types/request/flashswap.d.ts +28 -0
- package/dist/cjs/types/request/flashswap.js +7 -0
- package/dist/cjs/types/request/flashswap.js.map +1 -0
- package/dist/cjs/types/request/futures.d.ts +168 -0
- package/dist/cjs/types/request/futures.js +7 -0
- package/dist/cjs/types/request/futures.js.map +1 -0
- package/dist/cjs/types/request/margin.d.ts +47 -0
- package/dist/cjs/types/request/margin.js +7 -0
- package/dist/cjs/types/request/margin.js.map +1 -0
- package/dist/cjs/types/request/marginuni.d.ts +29 -0
- package/dist/cjs/types/request/marginuni.js +7 -0
- package/dist/cjs/types/request/marginuni.js.map +1 -0
- package/dist/cjs/types/request/multicollateralLoan.d.ts +55 -0
- package/dist/cjs/types/request/multicollateralLoan.js +7 -0
- package/dist/cjs/types/request/multicollateralLoan.js.map +1 -0
- package/dist/cjs/types/request/options.d.ts +81 -0
- package/dist/cjs/types/request/options.js +3 -0
- package/dist/cjs/types/request/options.js.map +1 -0
- package/dist/cjs/types/request/rebate.d.ts +26 -0
- package/dist/cjs/types/request/rebate.js +3 -0
- package/dist/cjs/types/request/rebate.js.map +1 -0
- package/dist/cjs/types/request/spot.d.ts +115 -0
- package/dist/cjs/types/request/spot.js +7 -0
- package/dist/cjs/types/request/spot.js.map +1 -0
- package/dist/cjs/types/request/subaccount.d.ts +19 -0
- package/dist/cjs/types/request/subaccount.js +3 -0
- package/dist/cjs/types/request/subaccount.js.map +1 -0
- package/dist/cjs/types/request/unified.d.ts +64 -0
- package/dist/cjs/types/request/unified.js +3 -0
- package/dist/cjs/types/request/unified.js.map +1 -0
- package/dist/cjs/types/request/wallet.d.ts +50 -0
- package/dist/cjs/types/request/wallet.js +3 -0
- package/dist/cjs/types/request/wallet.js.map +1 -0
- package/dist/cjs/types/request/withdrawal.d.ts +12 -0
- package/dist/cjs/types/request/withdrawal.js +7 -0
- package/dist/cjs/types/request/withdrawal.js.map +1 -0
- package/dist/cjs/types/response/account.d.ts +24 -0
- package/dist/cjs/types/response/account.js +7 -0
- package/dist/cjs/types/response/account.js.map +1 -0
- package/dist/cjs/types/response/collateralloan.d.ts +58 -0
- package/dist/cjs/types/response/collateralloan.js +7 -0
- package/dist/cjs/types/response/collateralloan.js.map +1 -0
- package/dist/cjs/types/response/delivery.d.ts +144 -0
- package/dist/cjs/types/response/delivery.js +7 -0
- package/dist/cjs/types/response/delivery.js.map +1 -0
- package/dist/cjs/types/response/earn.d.ts +60 -0
- package/dist/cjs/types/response/earn.js +7 -0
- package/dist/cjs/types/response/earn.js.map +1 -0
- package/dist/cjs/types/response/earnuni.d.ts +40 -0
- package/dist/cjs/types/response/earnuni.js +7 -0
- package/dist/cjs/types/response/earnuni.js.map +1 -0
- package/dist/cjs/types/response/flashswap.d.ts +32 -0
- package/dist/cjs/types/response/flashswap.js +7 -0
- package/dist/cjs/types/response/flashswap.js.map +1 -0
- package/dist/cjs/types/response/futures.d.ts +398 -0
- package/dist/cjs/types/response/futures.js +7 -0
- package/dist/cjs/types/response/futures.js.map +1 -0
- package/dist/cjs/types/response/margin.d.ts +96 -0
- package/dist/cjs/types/response/margin.js +7 -0
- package/dist/cjs/types/response/margin.js.map +1 -0
- package/dist/cjs/types/response/marginuni.d.ts +39 -0
- package/dist/cjs/types/response/marginuni.js +7 -0
- package/dist/cjs/types/response/marginuni.js.map +1 -0
- package/dist/cjs/types/response/multicollateralLoan.d.ts +151 -0
- package/dist/cjs/types/response/multicollateralLoan.js +7 -0
- package/dist/cjs/types/response/multicollateralLoan.js.map +1 -0
- package/dist/cjs/types/response/options.d.ts +192 -0
- package/dist/cjs/types/response/options.js +7 -0
- package/dist/cjs/types/response/options.js.map +1 -0
- package/dist/cjs/types/response/rebate.d.ts +40 -0
- package/dist/cjs/types/response/rebate.js +3 -0
- package/dist/cjs/types/response/rebate.js.map +1 -0
- package/dist/cjs/types/response/shared.d.ts +5 -0
- package/dist/cjs/types/response/shared.js +3 -0
- package/dist/cjs/types/response/shared.js.map +1 -0
- package/dist/cjs/types/response/spot.d.ts +224 -0
- package/dist/cjs/types/response/spot.js +7 -0
- package/dist/cjs/types/response/spot.js.map +1 -0
- package/dist/cjs/types/response/subaccount.d.ts +40 -0
- package/dist/cjs/types/response/subaccount.js +3 -0
- package/dist/cjs/types/response/subaccount.js.map +1 -0
- package/dist/cjs/types/response/unified.d.ts +113 -0
- package/dist/cjs/types/response/unified.js +3 -0
- package/dist/cjs/types/response/unified.js.map +1 -0
- package/dist/cjs/types/response/wallet.d.ts +181 -0
- package/dist/cjs/types/response/wallet.js +3 -0
- package/dist/cjs/types/response/wallet.js.map +1 -0
- package/dist/cjs/types/response/withdrawal.d.ts +12 -0
- package/dist/cjs/types/response/withdrawal.js +3 -0
- package/dist/cjs/types/response/withdrawal.js.map +1 -0
- package/dist/cjs/types/shared.d.ts +16 -0
- package/dist/cjs/types/shared.js +3 -0
- package/dist/cjs/types/shared.js.map +1 -0
- package/dist/cjs/types/websockets/client.d.ts +44 -0
- package/dist/cjs/types/websockets/client.js +6 -0
- package/dist/cjs/types/websockets/client.js.map +1 -0
- package/dist/cjs/types/websockets/events.d.ts +5 -0
- package/dist/cjs/types/websockets/events.js +3 -0
- package/dist/cjs/types/websockets/events.js.map +1 -0
- package/dist/cjs/types/websockets/requests.d.ts +36 -0
- package/dist/cjs/types/websockets/requests.js +3 -0
- package/dist/cjs/types/websockets/requests.js.map +1 -0
- package/dist/cjs/types/websockets/wsAPI.d.ts +101 -0
- package/dist/cjs/types/websockets/wsAPI.js +8 -0
- package/dist/cjs/types/websockets/wsAPI.js.map +1 -0
- package/dist/mjs/RestClient.d.ts +2534 -0
- package/dist/mjs/RestClient.js +2696 -0
- package/dist/mjs/RestClient.js.map +1 -0
- package/dist/mjs/WebsocketClient.d.ts +107 -0
- package/dist/mjs/WebsocketClient.js +500 -0
- package/dist/mjs/WebsocketClient.js.map +1 -0
- package/dist/mjs/index.d.ts +43 -0
- package/dist/mjs/index.js +48 -0
- package/dist/mjs/index.js.map +1 -0
- package/dist/mjs/lib/BaseRestClient.d.ts +63 -0
- package/dist/mjs/lib/BaseRestClient.js +317 -0
- package/dist/mjs/lib/BaseRestClient.js.map +1 -0
- package/dist/mjs/lib/BaseWSClient.d.ts +172 -0
- package/dist/mjs/lib/BaseWSClient.js +612 -0
- package/dist/mjs/lib/BaseWSClient.js.map +1 -0
- package/dist/mjs/lib/logger.d.ts +6 -0
- package/dist/mjs/lib/logger.js +13 -0
- package/dist/mjs/lib/logger.js.map +1 -0
- package/dist/mjs/lib/misc-util.d.ts +1 -0
- package/dist/mjs/lib/misc-util.js +4 -0
- package/dist/mjs/lib/misc-util.js.map +1 -0
- package/dist/mjs/lib/requestUtils.d.ts +38 -0
- package/dist/mjs/lib/requestUtils.js +41 -0
- package/dist/mjs/lib/requestUtils.js.map +1 -0
- package/dist/mjs/lib/webCryptoAPI.d.ts +10 -0
- package/dist/mjs/lib/webCryptoAPI.js +52 -0
- package/dist/mjs/lib/webCryptoAPI.js.map +1 -0
- package/dist/mjs/lib/websocket/WsStore.d.ts +57 -0
- package/dist/mjs/lib/websocket/WsStore.js +244 -0
- package/dist/mjs/lib/websocket/WsStore.js.map +1 -0
- package/dist/mjs/lib/websocket/WsStore.types.d.ts +44 -0
- package/dist/mjs/lib/websocket/WsStore.types.js +10 -0
- package/dist/mjs/lib/websocket/WsStore.types.js.map +1 -0
- package/dist/mjs/lib/websocket/websocket-util.d.ts +78 -0
- package/dist/mjs/lib/websocket/websocket-util.js +145 -0
- package/dist/mjs/lib/websocket/websocket-util.js.map +1 -0
- package/dist/mjs/package.json +3 -0
- package/dist/mjs/types/request/account.d.ts +10 -0
- package/dist/mjs/types/request/account.js +6 -0
- package/dist/mjs/types/request/account.js.map +1 -0
- package/dist/mjs/types/request/collateralLoan.d.ts +39 -0
- package/dist/mjs/types/request/collateralLoan.js +6 -0
- package/dist/mjs/types/request/collateralLoan.js.map +1 -0
- package/dist/mjs/types/request/delivery.d.ts +89 -0
- package/dist/mjs/types/request/delivery.js +6 -0
- package/dist/mjs/types/request/delivery.js.map +1 -0
- package/dist/mjs/types/request/earn.d.ts +16 -0
- package/dist/mjs/types/request/earn.js +6 -0
- package/dist/mjs/types/request/earn.js.map +1 -0
- package/dist/mjs/types/request/earnuni.d.ts +30 -0
- package/dist/mjs/types/request/earnuni.js +6 -0
- package/dist/mjs/types/request/earnuni.js.map +1 -0
- package/dist/mjs/types/request/flashswap.d.ts +28 -0
- package/dist/mjs/types/request/flashswap.js +6 -0
- package/dist/mjs/types/request/flashswap.js.map +1 -0
- package/dist/mjs/types/request/futures.d.ts +168 -0
- package/dist/mjs/types/request/futures.js +6 -0
- package/dist/mjs/types/request/futures.js.map +1 -0
- package/dist/mjs/types/request/margin.d.ts +47 -0
- package/dist/mjs/types/request/margin.js +6 -0
- package/dist/mjs/types/request/margin.js.map +1 -0
- package/dist/mjs/types/request/marginuni.d.ts +29 -0
- package/dist/mjs/types/request/marginuni.js +6 -0
- package/dist/mjs/types/request/marginuni.js.map +1 -0
- package/dist/mjs/types/request/multicollateralLoan.d.ts +55 -0
- package/dist/mjs/types/request/multicollateralLoan.js +6 -0
- package/dist/mjs/types/request/multicollateralLoan.js.map +1 -0
- package/dist/mjs/types/request/options.d.ts +81 -0
- package/dist/mjs/types/request/options.js +2 -0
- package/dist/mjs/types/request/options.js.map +1 -0
- package/dist/mjs/types/request/rebate.d.ts +26 -0
- package/dist/mjs/types/request/rebate.js +2 -0
- package/dist/mjs/types/request/rebate.js.map +1 -0
- package/dist/mjs/types/request/spot.d.ts +115 -0
- package/dist/mjs/types/request/spot.js +6 -0
- package/dist/mjs/types/request/spot.js.map +1 -0
- package/dist/mjs/types/request/subaccount.d.ts +19 -0
- package/dist/mjs/types/request/subaccount.js +2 -0
- package/dist/mjs/types/request/subaccount.js.map +1 -0
- package/dist/mjs/types/request/unified.d.ts +64 -0
- package/dist/mjs/types/request/unified.js +2 -0
- package/dist/mjs/types/request/unified.js.map +1 -0
- package/dist/mjs/types/request/wallet.d.ts +50 -0
- package/dist/mjs/types/request/wallet.js +2 -0
- package/dist/mjs/types/request/wallet.js.map +1 -0
- package/dist/mjs/types/request/withdrawal.d.ts +12 -0
- package/dist/mjs/types/request/withdrawal.js +6 -0
- package/dist/mjs/types/request/withdrawal.js.map +1 -0
- package/dist/mjs/types/response/account.d.ts +24 -0
- package/dist/mjs/types/response/account.js +6 -0
- package/dist/mjs/types/response/account.js.map +1 -0
- package/dist/mjs/types/response/collateralloan.d.ts +58 -0
- package/dist/mjs/types/response/collateralloan.js +6 -0
- package/dist/mjs/types/response/collateralloan.js.map +1 -0
- package/dist/mjs/types/response/delivery.d.ts +144 -0
- package/dist/mjs/types/response/delivery.js +6 -0
- package/dist/mjs/types/response/delivery.js.map +1 -0
- package/dist/mjs/types/response/earn.d.ts +60 -0
- package/dist/mjs/types/response/earn.js +6 -0
- package/dist/mjs/types/response/earn.js.map +1 -0
- package/dist/mjs/types/response/earnuni.d.ts +40 -0
- package/dist/mjs/types/response/earnuni.js +6 -0
- package/dist/mjs/types/response/earnuni.js.map +1 -0
- package/dist/mjs/types/response/flashswap.d.ts +32 -0
- package/dist/mjs/types/response/flashswap.js +6 -0
- package/dist/mjs/types/response/flashswap.js.map +1 -0
- package/dist/mjs/types/response/futures.d.ts +398 -0
- package/dist/mjs/types/response/futures.js +6 -0
- package/dist/mjs/types/response/futures.js.map +1 -0
- package/dist/mjs/types/response/margin.d.ts +96 -0
- package/dist/mjs/types/response/margin.js +6 -0
- package/dist/mjs/types/response/margin.js.map +1 -0
- package/dist/mjs/types/response/marginuni.d.ts +39 -0
- package/dist/mjs/types/response/marginuni.js +6 -0
- package/dist/mjs/types/response/marginuni.js.map +1 -0
- package/dist/mjs/types/response/multicollateralLoan.d.ts +151 -0
- package/dist/mjs/types/response/multicollateralLoan.js +6 -0
- package/dist/mjs/types/response/multicollateralLoan.js.map +1 -0
- package/dist/mjs/types/response/options.d.ts +192 -0
- package/dist/mjs/types/response/options.js +6 -0
- package/dist/mjs/types/response/options.js.map +1 -0
- package/dist/mjs/types/response/rebate.d.ts +40 -0
- package/dist/mjs/types/response/rebate.js +2 -0
- package/dist/mjs/types/response/rebate.js.map +1 -0
- package/dist/mjs/types/response/shared.d.ts +5 -0
- package/dist/mjs/types/response/shared.js +2 -0
- package/dist/mjs/types/response/shared.js.map +1 -0
- package/dist/mjs/types/response/spot.d.ts +224 -0
- package/dist/mjs/types/response/spot.js +6 -0
- package/dist/mjs/types/response/spot.js.map +1 -0
- package/dist/mjs/types/response/subaccount.d.ts +40 -0
- package/dist/mjs/types/response/subaccount.js +2 -0
- package/dist/mjs/types/response/subaccount.js.map +1 -0
- package/dist/mjs/types/response/unified.d.ts +113 -0
- package/dist/mjs/types/response/unified.js +2 -0
- package/dist/mjs/types/response/unified.js.map +1 -0
- package/dist/mjs/types/response/wallet.d.ts +181 -0
- package/dist/mjs/types/response/wallet.js +2 -0
- package/dist/mjs/types/response/wallet.js.map +1 -0
- package/dist/mjs/types/response/withdrawal.d.ts +12 -0
- package/dist/mjs/types/response/withdrawal.js +2 -0
- package/dist/mjs/types/response/withdrawal.js.map +1 -0
- package/dist/mjs/types/shared.d.ts +16 -0
- package/dist/mjs/types/shared.js +2 -0
- package/dist/mjs/types/shared.js.map +1 -0
- package/dist/mjs/types/websockets/client.d.ts +44 -0
- package/dist/mjs/types/websockets/client.js +5 -0
- package/dist/mjs/types/websockets/client.js.map +1 -0
- package/dist/mjs/types/websockets/events.d.ts +5 -0
- package/dist/mjs/types/websockets/events.js +2 -0
- package/dist/mjs/types/websockets/events.js.map +1 -0
- package/dist/mjs/types/websockets/requests.d.ts +36 -0
- package/dist/mjs/types/websockets/requests.js +2 -0
- package/dist/mjs/types/websockets/requests.js.map +1 -0
- package/dist/mjs/types/websockets/wsAPI.d.ts +101 -0
- package/dist/mjs/types/websockets/wsAPI.js +7 -0
- package/dist/mjs/types/websockets/wsAPI.js.map +1 -0
- package/package.json +49 -38
- package/index.js +0 -1
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -16
- package/lib/index.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,104 +1,135 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# Node.js & JavaScript SDK for Gate.io REST APIs, WebSockets & WebSocket API
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+

|
|
5
|
+
|
|
6
|
+
[][1]
|
|
7
|
+
[][1]
|
|
8
|
+
[][1]
|
|
9
|
+
[](https://github.com/tiagosiebler/gateio-api/actions/workflows/e2etest.yml)
|
|
4
10
|
[][1]
|
|
5
|
-
[](https://t.me/nodetraders)
|
|
6
12
|
|
|
7
13
|
[1]: https://www.npmjs.com/package/gateio-api
|
|
8
14
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
15
|
+
Updated & performant JavaScript & Node.js SDK for the Gate.io REST APIs and WebSockets:
|
|
16
|
+
|
|
17
|
+
- Extensive integration with Gate.io REST APIs and WebSockets.
|
|
18
|
+
- TypeScript support (with type declarations for most API requests & responses).
|
|
19
|
+
- Gate.io REST APIs for Gate.io Spot, Margin, Perpetual Futures, Delivery Futures, Options & Announcements APIs.
|
|
20
|
+
- Strongly typed on most requests and responses.
|
|
21
|
+
- Extremely robust & performant JavaScript/Node.js Gate.io SDK.
|
|
22
|
+
- Actively maintained with a modern, promise-driven interface.
|
|
23
|
+
- Support for seamless API authentication for private Gate.io REST API and WebSocket calls.
|
|
24
|
+
- Gate.io Spot, Margin, Perpetual Futures, Delivery Futures & Options.
|
|
25
|
+
- Event driven messaging.
|
|
26
|
+
- Smart websocket persistence
|
|
27
|
+
- Automatically handle silent websocket disconnections through timed heartbeats, including the scheduled 24hr disconnect.
|
|
28
|
+
- Automatically handle listenKey persistence and expiration/refresh.
|
|
29
|
+
- Emit `reconnected` event when dropped connection is restored.
|
|
30
|
+
- Websocket API for Gate.io Spot, Margin, Perpetual Futures & Delivery Futures.
|
|
31
|
+
- Automatic connectivity via existing WebsocketClient, just call sendWSAPIRequest to trigger a request.
|
|
32
|
+
- Automatic authentication, just call sendWSAPIRequest with channel & parameters.
|
|
33
|
+
- Choose between two interfaces for WS API communication:
|
|
34
|
+
- Event-driven interface, fire & forget via sendWSAPIRequest and receive async replies via wsClient's event emitter.
|
|
35
|
+
- Promise-driven interface, simply call and await sendWSAPIRequest for a REST-API-like behaviour with the WS API.
|
|
36
|
+
- Proxy support via axios integration.
|
|
37
|
+
- Active community support & collaboration in telegram: [Node.js Algo Traders](https://t.me/nodetraders).
|
|
12
38
|
|
|
13
39
|
## Installation
|
|
40
|
+
|
|
14
41
|
`npm install --save gateio-api`
|
|
15
42
|
|
|
16
43
|
## Issues & Discussion
|
|
44
|
+
|
|
17
45
|
- Issues? Check the [issues tab](https://github.com/tiagosiebler/gateio-api/issues).
|
|
18
46
|
- Discuss & collaborate with other node devs? Join our [Node.js Algo Traders](https://t.me/nodetraders) engineering community on telegram.
|
|
19
47
|
|
|
48
|
+
## Related projects
|
|
49
|
+
|
|
50
|
+
Check out my related JavaScript/TypeScript/Node.js projects:
|
|
51
|
+
|
|
52
|
+
- Try my REST API & WebSocket SDKs:
|
|
53
|
+
- [Bybit-api Node.js SDK](https://www.npmjs.com/package/bybit-api)
|
|
54
|
+
- [Binance Node.js SDK](https://www.npmjs.com/package/binance)
|
|
55
|
+
- [Okx-api Node.js SDK](https://www.npmjs.com/package/okx-api)
|
|
56
|
+
- [Gateio-api Node.js SDK](https://www.npmjs.com/package/gateio-api)
|
|
57
|
+
- [Bitget-api Node.js SDK](https://www.npmjs.com/package/bitget-api)
|
|
58
|
+
- [Bitmart-api Node.js SDK](https://www.npmjs.com/package/bitmart-api)
|
|
59
|
+
- Try my misc utilities:
|
|
60
|
+
- [OrderBooks Node.js](https://www.npmjs.com/package/orderbooks)
|
|
61
|
+
- [Crypto Exchange Account State Cache](https://www.npmjs.com/package/accountstate)
|
|
62
|
+
- Check out my examples:
|
|
63
|
+
- [awesome-crypto-examples Node.js](https://github.com/tiagosiebler/awesome-crypto-examples)
|
|
64
|
+
|
|
20
65
|
## Documentation
|
|
66
|
+
|
|
21
67
|
Most methods accept JS objects. These can be populated using parameters specified by gateio's API documentation.
|
|
68
|
+
|
|
22
69
|
- [Gate.io API Documentation](https://www.gate.io/docs/developers/apiv4/en/).
|
|
70
|
+
- [TSDoc Documentation (autogenerated using typedoc)](https://tsdocs.dev/docs/gateio-api)
|
|
23
71
|
|
|
24
72
|
## Structure
|
|
25
|
-
|
|
73
|
+
|
|
74
|
+
This project uses typescript. Resources are stored in 2 key structures:
|
|
75
|
+
|
|
26
76
|
- [src](./src) - the whole connector written in typescript
|
|
27
|
-
- [lib](./lib) - the javascript version of the project (compiled from typescript). This should not be edited directly, as it will be overwritten with each release.
|
|
28
|
-
- [dist](./dist) - the packed bundle of the project for use in browser environments.
|
|
29
77
|
- [examples](./examples) - some implementation examples & demonstrations. Contributions are welcome!
|
|
30
78
|
|
|
31
79
|
---
|
|
32
80
|
|
|
33
81
|
# Usage
|
|
34
|
-
<!-- Create API credentials at okx
|
|
35
|
-
- [OKX my-api](https://www.okx.com/account/my-api) -->
|
|
36
|
-
|
|
37
|
-
<!--
|
|
38
|
-
### REST Inverse
|
|
39
|
-
To use the inverse REST APIs, import the `InverseClient`:
|
|
40
|
-
|
|
41
|
-
```javascript
|
|
42
|
-
const { InverseClient } = require('gateio-api');
|
|
43
82
|
|
|
44
|
-
|
|
45
|
-
// override the max size of the request window (in ms)
|
|
46
|
-
recv_window?: number;
|
|
83
|
+
Create API credentials
|
|
47
84
|
|
|
48
|
-
|
|
49
|
-
sync_interval_ms?: number | string;
|
|
85
|
+
- [Gate.io API Key Management](https://www.gate.io/myaccount/api_key_manage)
|
|
50
86
|
|
|
51
|
-
|
|
52
|
-
disable_time_sync?: boolean;
|
|
87
|
+
### REST API
|
|
53
88
|
|
|
54
|
-
|
|
55
|
-
strict_param_validation?: boolean;
|
|
89
|
+
To use any of Gate.io's REST APIs in JavaScript/TypeScript/Node.js, import (or require) the `RestClient`:
|
|
56
90
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
baseUrl?: string;
|
|
60
|
-
|
|
61
|
-
// Default: true. whether to try and post-process request exceptions.
|
|
62
|
-
parse_exceptions?: boolean;
|
|
63
|
-
};
|
|
91
|
+
```javascript
|
|
92
|
+
const { RestClient } = require('gateio-api');
|
|
64
93
|
|
|
65
94
|
const API_KEY = 'xxx';
|
|
66
95
|
const PRIVATE_KEY = 'yyy';
|
|
67
|
-
const useLivenet = false;
|
|
68
|
-
|
|
69
|
-
const client = new InverseClient(
|
|
70
|
-
API_KEY,
|
|
71
|
-
PRIVATE_KEY,
|
|
72
96
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
// requestLibraryOptions
|
|
78
|
-
);
|
|
97
|
+
const client = new RestClient({
|
|
98
|
+
apiKey: API_KEY,
|
|
99
|
+
apiSecret: PRIVATE_KEY,
|
|
100
|
+
});
|
|
79
101
|
|
|
80
|
-
client
|
|
81
|
-
.
|
|
82
|
-
|
|
102
|
+
client
|
|
103
|
+
.getSpotTicker()
|
|
104
|
+
.then((result) => {
|
|
105
|
+
console.log('all spot tickers result: ', result);
|
|
83
106
|
})
|
|
84
|
-
.catch(err => {
|
|
85
|
-
console.error(
|
|
107
|
+
.catch((err) => {
|
|
108
|
+
console.error('spot ticker error: ', err);
|
|
86
109
|
});
|
|
87
110
|
|
|
88
|
-
client
|
|
89
|
-
.
|
|
90
|
-
|
|
111
|
+
client
|
|
112
|
+
.getSpotOrders({
|
|
113
|
+
currency_pair: 'BTC_USDT', // Specify the currency pair
|
|
114
|
+
status: 'open', // Specify the status of the orders to fetch
|
|
91
115
|
})
|
|
92
|
-
.
|
|
93
|
-
console.
|
|
116
|
+
.then((result) => {
|
|
117
|
+
console.log('getSpotOrders result: ', result);
|
|
118
|
+
})
|
|
119
|
+
.catch((err) => {
|
|
120
|
+
console.error('getSpotOrders error: ', err);
|
|
94
121
|
});
|
|
95
122
|
```
|
|
96
123
|
|
|
97
|
-
|
|
98
|
-
See [inverse-client.ts](./src/inverse-client.ts) for further information. -->
|
|
124
|
+
See [RestClient](./src/RestClient.ts) for further information, or the [examples](./examples/) for lots of usage examples.
|
|
99
125
|
|
|
100
126
|
## WebSockets
|
|
101
|
-
|
|
127
|
+
|
|
128
|
+
All available WebSockets can be used via a shared `WebsocketClient`. The WebSocket client will automatically open/track/manage connections as needed. Each unique connection (one per server URL) is tracked using a WsKey (each WsKey is a string - see [WS_KEY_MAP](src/lib/websocket/websocket-util.ts) for a list of supported values).
|
|
129
|
+
|
|
130
|
+
Any subscribe/unsubscribe events will need to include a WsKey, so the WebSocket client understands which connection the event should be routed to. See examples below or in the [examples](./examples/) folder on GitHub.
|
|
131
|
+
|
|
132
|
+
Data events are emitted from the WebsocketClient via the `update` event, see example below:
|
|
102
133
|
|
|
103
134
|
```javascript
|
|
104
135
|
const { WebsocketClient } = require('gateio-api');
|
|
@@ -107,22 +138,15 @@ const API_KEY = 'xxx';
|
|
|
107
138
|
const PRIVATE_KEY = 'yyy';
|
|
108
139
|
|
|
109
140
|
const wsConfig = {
|
|
110
|
-
|
|
111
|
-
|
|
141
|
+
apiKey: API_KEY,
|
|
142
|
+
apiSecret: PRIVATE_KEY,
|
|
112
143
|
|
|
113
144
|
/*
|
|
114
145
|
The following parameters are optional:
|
|
115
146
|
*/
|
|
116
147
|
|
|
117
|
-
//
|
|
118
|
-
//
|
|
119
|
-
|
|
120
|
-
// NOTE: to listen to multiple markets (spot vs inverse vs linear vs linearfutures) at once, make one WebsocketClient instance per market
|
|
121
|
-
|
|
122
|
-
// defaults to inverse:
|
|
123
|
-
// market: 'inverse'
|
|
124
|
-
// market: 'linear'
|
|
125
|
-
// market: 'spot'
|
|
148
|
+
// Livenet is used by default, use this to enable testnet:
|
|
149
|
+
// useTestnet: true
|
|
126
150
|
|
|
127
151
|
// how long to wait (in ms) before deciding the connection should be terminated & reconnected
|
|
128
152
|
// pongTimeout: 1000,
|
|
@@ -138,22 +162,51 @@ const wsConfig = {
|
|
|
138
162
|
|
|
139
163
|
// config for axios used for HTTP requests. E.g for proxy support
|
|
140
164
|
// requestOptions: { }
|
|
141
|
-
|
|
142
|
-
// override which URL to use for websocket connections
|
|
143
|
-
// wsUrl: 'wss://stream.bytick.com/realtime'
|
|
144
165
|
};
|
|
145
166
|
|
|
146
167
|
const ws = new WebsocketClient(wsConfig);
|
|
147
168
|
|
|
169
|
+
/**
|
|
170
|
+
* Subscribing to data:
|
|
171
|
+
**/
|
|
172
|
+
|
|
173
|
+
const userOrders = {
|
|
174
|
+
topic: 'spot.orders',
|
|
175
|
+
payload: ['BTC_USDT', 'ETH_USDT', 'MATIC_USDT'],
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
const userTrades = {
|
|
179
|
+
topic: 'spot.usertrades',
|
|
180
|
+
payload: ['BTC_USDT', 'ETH_USDT', 'MATIC_USDT'],
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
const userPriceOrders = {
|
|
184
|
+
topic: 'spot.priceorders',
|
|
185
|
+
payload: ['!all'],
|
|
186
|
+
};
|
|
187
|
+
|
|
148
188
|
// subscribe to multiple topics at once
|
|
149
|
-
ws.subscribe([
|
|
189
|
+
ws.subscribe([userOrders, userTrades, userPriceOrders], 'spotV4');
|
|
150
190
|
|
|
151
191
|
// and/or subscribe to individual topics on demand
|
|
152
|
-
ws.subscribe(
|
|
192
|
+
ws.subscribe(
|
|
193
|
+
{
|
|
194
|
+
topic: 'spot.priceorders',
|
|
195
|
+
payload: ['!all'],
|
|
196
|
+
},
|
|
197
|
+
'spotV4',
|
|
198
|
+
);
|
|
199
|
+
|
|
200
|
+
// Some topics don't need params, for those you can just subscribe with a string (or use a topic + payload object as above)
|
|
201
|
+
ws.subscribe('spot.balances', 'spotV4');
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Handling events:
|
|
205
|
+
**/
|
|
153
206
|
|
|
154
207
|
// Listen to events coming from websockets. This is the primary data source
|
|
155
|
-
ws.on('update', data => {
|
|
156
|
-
console.log('
|
|
208
|
+
ws.on('update', (data) => {
|
|
209
|
+
console.log('data', data);
|
|
157
210
|
});
|
|
158
211
|
|
|
159
212
|
// Optional: Listen to websocket connection open event (automatic after subscribing to one or more topics)
|
|
@@ -161,8 +214,8 @@ ws.on('open', ({ wsKey, event }) => {
|
|
|
161
214
|
console.log('connection open for websocket with ID: ' + wsKey);
|
|
162
215
|
});
|
|
163
216
|
|
|
164
|
-
// Optional: Listen to responses to websocket queries (e.g. the
|
|
165
|
-
ws.on('response', response => {
|
|
217
|
+
// Optional: Listen to responses to websocket queries (e.g. the reply after subscribing to a topic)
|
|
218
|
+
ws.on('response', (response) => {
|
|
166
219
|
console.log('response', response);
|
|
167
220
|
});
|
|
168
221
|
|
|
@@ -171,21 +224,126 @@ ws.on('close', () => {
|
|
|
171
224
|
console.log('connection closed');
|
|
172
225
|
});
|
|
173
226
|
|
|
227
|
+
// Optional: listen to internal exceptions. Useful for debugging if something weird happens
|
|
228
|
+
ws.on('exception', (data) => {
|
|
229
|
+
console.error('exception: ', data);
|
|
230
|
+
});
|
|
231
|
+
|
|
174
232
|
// Optional: Listen to raw error events.
|
|
175
|
-
|
|
176
|
-
ws.on('error', err => {
|
|
233
|
+
ws.on('error', (err) => {
|
|
177
234
|
console.error('ERR', err);
|
|
178
235
|
});
|
|
179
236
|
```
|
|
180
237
|
|
|
238
|
+
See [WebsocketClient](./src/WebsocketClient.ts) for further information and make sure to check the [examples](./examples/) folder for much more detail.
|
|
181
239
|
|
|
182
|
-
|
|
240
|
+
### Websocket API
|
|
183
241
|
|
|
184
|
-
|
|
242
|
+
The [WebsocketClient](./src/WebsocketClient.ts) supports this exchange's Websocket API. There are two ways to use the WS API, depending on individual preference:
|
|
243
|
+
|
|
244
|
+
- event-driven:
|
|
245
|
+
- send requests via `client.sendWSAPIRequest(wsKey, channel, params)`, fire and forget, don't use await
|
|
246
|
+
- handle async replies via event handlers on `client.on('exception', cb)` and `client.on('response', cb)`
|
|
247
|
+
- promise-driven:
|
|
248
|
+
- send requests via `const result = await client.sendWSAPIRequest(wsKey, channel, params)`, which returns a promise
|
|
249
|
+
- await each call
|
|
250
|
+
- use try/catch blocks to handle promise rejections
|
|
251
|
+
|
|
252
|
+
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).
|
|
253
|
+
|
|
254
|
+
```javascript
|
|
255
|
+
const { WebsocketClient } = require('gateio-api');
|
|
256
|
+
|
|
257
|
+
const API_KEY = 'xxx';
|
|
258
|
+
const PRIVATE_KEY = 'yyy';
|
|
259
|
+
|
|
260
|
+
async function start() {
|
|
261
|
+
const client = new WebsocketClient({
|
|
262
|
+
apiKey: API_KEY,
|
|
263
|
+
apiSecret: PRIVATE_KEY,
|
|
264
|
+
// Automatically re-auth WS API, if we were auth'd before and get reconnected
|
|
265
|
+
reauthWSAPIOnReconnect: true,
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Setup basic event handlers for core connectivity events.
|
|
270
|
+
* Note for this approach, the `response` and `update` events are not needed (but you can use them too/instead if you prefer).
|
|
271
|
+
**/
|
|
272
|
+
|
|
273
|
+
// Successfully connected
|
|
274
|
+
client.on('open', (data) => {
|
|
275
|
+
console.log(new Date(), 'ws connected ', data?.wsKey);
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
// Something happened, attempting to reconnect
|
|
279
|
+
client.on('reconnect', (data) => {
|
|
280
|
+
console.log(new Date(), 'ws reconnect: ', data);
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
// Reconnect successful
|
|
284
|
+
client.on('reconnected', (data) => {
|
|
285
|
+
console.log(new Date(), 'ws reconnected: ', data);
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
// Connection closed. If unexpected, expect reconnect -> reconnected.
|
|
289
|
+
client.on('close', (data) => {
|
|
290
|
+
console.error(new Date(), 'ws close: ', data);
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
client.on('exception', (data) => {
|
|
294
|
+
console.error(new Date(), 'ws exception: ', data);
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
client.on('authenticated', (data) => {
|
|
298
|
+
console.error(new Date(), 'ws authenticated: ', data);
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
try {
|
|
302
|
+
/**
|
|
303
|
+
* All WebSocket API (WS API) messaging should be done via the sendWSAPIRequest method.
|
|
304
|
+
*/
|
|
305
|
+
|
|
306
|
+
// The WSKey identifies which connection this request is for.
|
|
307
|
+
// (e.g. "spotV4" | "perpFuturesUSDTV4" | "perpFuturesBTCV4" | "deliveryFuturesUSDTV4" | "deliveryFuturesBTCV4" | "optionsV4")
|
|
308
|
+
const wsKey = 'spotV4';
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* To authenticate, send an empty request to "spot.login". The SDK will handle all the parameters.
|
|
312
|
+
*
|
|
313
|
+
* 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.
|
|
314
|
+
*/
|
|
315
|
+
console.log(new Date(), 'try authenticate');
|
|
316
|
+
const loginResult = await client.sendWSAPIRequest(wsKey, 'spot.login');
|
|
317
|
+
console.log(new Date(), 'authenticated!', loginResult);
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* For other channels, you should include any parameters for the request (the payload) in your call.
|
|
321
|
+
*
|
|
322
|
+
* Note that internal parameters such as "signature" etc are all handled automatically by the SDK. Only the core request parameters are needed.
|
|
323
|
+
*/
|
|
324
|
+
console.log(new Date(), 'try get order status');
|
|
325
|
+
const orderStatus = await client.sendWSAPIRequest(
|
|
326
|
+
wsKey,
|
|
327
|
+
'spot.order_status',
|
|
328
|
+
{
|
|
329
|
+
order_id: '600995435390',
|
|
330
|
+
currency_pair: 'BTC_USDT',
|
|
331
|
+
},
|
|
332
|
+
);
|
|
333
|
+
|
|
334
|
+
console.log(new Date(), 'orderStatus result!', orderStatus);
|
|
335
|
+
} catch (e) {
|
|
336
|
+
console.error(`WS API Error: `, e);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
start();
|
|
341
|
+
```
|
|
185
342
|
|
|
186
343
|
---
|
|
187
344
|
|
|
188
345
|
## Customise Logging
|
|
346
|
+
|
|
189
347
|
Pass a custom logger which supports the log methods `silly`, `debug`, `notice`, `info`, `warning` and `error`, or override methods from the default logger as desired.
|
|
190
348
|
|
|
191
349
|
```javascript
|
|
@@ -194,34 +352,21 @@ const { WebsocketClient, DefaultLogger } = require('gateio-api');
|
|
|
194
352
|
// Disable all logging on the silly level
|
|
195
353
|
DefaultLogger.silly = () => {};
|
|
196
354
|
|
|
197
|
-
const ws = new WebsocketClient(
|
|
198
|
-
{ key: 'xxx', secret: 'yyy' },
|
|
199
|
-
DefaultLogger
|
|
200
|
-
);
|
|
355
|
+
const ws = new WebsocketClient({ key: 'xxx', secret: 'yyy' }, DefaultLogger);
|
|
201
356
|
```
|
|
202
357
|
|
|
203
|
-
## Browser Usage
|
|
204
|
-
Build a bundle using webpack:
|
|
205
|
-
- `npm install`
|
|
206
|
-
- `npm build`
|
|
207
|
-
- `npm pack`
|
|
208
|
-
|
|
209
|
-
The bundle can be found in `dist/`. Altough usage should be largely consistent, smaller differences will exist. Documentation is still TODO.
|
|
210
|
-
|
|
211
358
|
---
|
|
212
359
|
|
|
213
360
|
## Contributions & Thanks
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
-
|
|
218
|
-
-
|
|
219
|
-
-
|
|
220
|
-
-
|
|
221
|
-
|
|
222
|
-
Or buy me a coffee using any of these:
|
|
223
|
-
- BTC: `1C6GWZL1XW3jrjpPTS863XtZiXL1aTK7Jk`
|
|
224
|
-
- ETH (ERC20): `0xd773d8e6a50758e1ada699bb6c4f98bb4abf82da`
|
|
361
|
+
|
|
362
|
+
Have my projects helped you? Share the love, there are many ways you can show your thanks:
|
|
363
|
+
|
|
364
|
+
- Star & share my projects.
|
|
365
|
+
- Are my projects useful? Sponsor me on Github and support my effort to maintain & improve them: https://github.com/sponsors/tiagosiebler
|
|
366
|
+
- Have an interesting project? Get in touch & invite me to it.
|
|
367
|
+
- Or buy me all the coffee:
|
|
368
|
+
- ETH(ERC20): `0xA3Bda8BecaB4DCdA539Dc16F9C54a592553Be06C` <!-- metamask -->
|
|
225
369
|
|
|
226
370
|
### Contributions & Pull Requests
|
|
371
|
+
|
|
227
372
|
Contributions are encouraged, I will review any incoming pull requests. See the issues tab for todo items.
|