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