kucoin-api 0.0.2 → 1.0.0
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 +256 -40
- package/dist/cjs/FuturesClient.d.ts +246 -0
- package/dist/cjs/FuturesClient.js +261 -0
- package/dist/cjs/FuturesClient.js.map +1 -0
- package/dist/cjs/SpotClient.d.ts +692 -0
- package/dist/cjs/SpotClient.js +745 -0
- package/dist/cjs/SpotClient.js.map +1 -0
- package/dist/cjs/WebsocketClient.d.ts +77 -0
- package/dist/cjs/WebsocketClient.js +337 -0
- package/dist/cjs/WebsocketClient.js.map +1 -0
- package/dist/cjs/index.d.ts +22 -0
- package/dist/cjs/index.js +39 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/lib/BaseRestClient.d.ts +42 -0
- package/dist/cjs/lib/BaseRestClient.js +268 -0
- package/dist/cjs/lib/BaseRestClient.js.map +1 -0
- package/dist/cjs/lib/BaseWSClient.d.ts +168 -0
- package/dist/cjs/lib/BaseWSClient.js +622 -0
- package/dist/cjs/lib/BaseWSClient.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 +35 -0
- package/dist/cjs/lib/requestUtils.js +54 -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 +63 -0
- package/dist/cjs/lib/websocket/WsStore.js +254 -0
- package/dist/cjs/lib/websocket/WsStore.js.map +1 -0
- package/dist/cjs/lib/websocket/WsStore.types.d.ts +50 -0
- package/dist/cjs/lib/websocket/WsStore.types.js +14 -0
- package/dist/cjs/lib/websocket/WsStore.types.js.map +1 -0
- package/dist/cjs/lib/websocket/logger.d.ts +6 -0
- package/dist/cjs/lib/websocket/logger.js +16 -0
- package/dist/cjs/lib/websocket/logger.js.map +1 -0
- package/dist/cjs/lib/websocket/websocket-util.d.ts +30 -0
- package/dist/cjs/lib/websocket/websocket-util.js +19 -0
- package/dist/cjs/lib/websocket/websocket-util.js.map +1 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/types/request/futures.types.d.ts +183 -0
- package/dist/cjs/types/request/futures.types.js +7 -0
- package/dist/cjs/types/request/futures.types.js.map +1 -0
- package/dist/cjs/types/request/spot-account.d.ts +56 -0
- package/dist/cjs/types/request/spot-account.js +3 -0
- package/dist/cjs/types/request/spot-account.js.map +1 -0
- package/dist/cjs/types/request/spot-earn.d.ts +27 -0
- package/dist/cjs/types/request/spot-earn.js +8 -0
- package/dist/cjs/types/request/spot-earn.js.map +1 -0
- package/dist/cjs/types/request/spot-funding.d.ts +88 -0
- package/dist/cjs/types/request/spot-funding.js +10 -0
- package/dist/cjs/types/request/spot-funding.js.map +1 -0
- package/dist/cjs/types/request/spot-margin-trading.d.ts +169 -0
- package/dist/cjs/types/request/spot-margin-trading.js +10 -0
- package/dist/cjs/types/request/spot-margin-trading.js.map +1 -0
- package/dist/cjs/types/request/spot-trading.d.ts +214 -0
- package/dist/cjs/types/request/spot-trading.js +10 -0
- package/dist/cjs/types/request/spot-trading.js.map +1 -0
- package/dist/cjs/types/response/futures.types.d.ts +501 -0
- package/dist/cjs/types/response/futures.types.js +7 -0
- package/dist/cjs/types/response/futures.types.js.map +1 -0
- package/dist/cjs/types/response/shared.types.d.ts +9 -0
- package/dist/cjs/types/response/shared.types.js +3 -0
- package/dist/cjs/types/response/shared.types.js.map +1 -0
- package/dist/cjs/types/response/spot-account.d.ts +140 -0
- package/dist/cjs/types/response/spot-account.js +3 -0
- package/dist/cjs/types/response/spot-account.js.map +1 -0
- package/dist/cjs/types/response/spot-earn.d.ts +74 -0
- package/dist/cjs/types/response/spot-earn.js +8 -0
- package/dist/cjs/types/response/spot-earn.js.map +1 -0
- package/dist/cjs/types/response/spot-funding.d.ts +176 -0
- package/dist/cjs/types/response/spot-funding.js +10 -0
- package/dist/cjs/types/response/spot-funding.js.map +1 -0
- package/dist/cjs/types/response/spot-margin-trading.d.ts +257 -0
- package/dist/cjs/types/response/spot-margin-trading.js +10 -0
- package/dist/cjs/types/response/spot-margin-trading.js.map +1 -0
- package/dist/cjs/types/response/spot-trading.d.ts +388 -0
- package/dist/cjs/types/response/spot-trading.js +10 -0
- package/dist/cjs/types/response/spot-trading.js.map +1 -0
- package/dist/cjs/types/response/spot-vip.d.ts +38 -0
- package/dist/cjs/types/response/spot-vip.js +10 -0
- package/dist/cjs/types/response/spot-vip.js.map +1 -0
- package/dist/cjs/types/response/ws.d.ts +11 -0
- package/dist/cjs/types/response/ws.js +3 -0
- package/dist/cjs/types/response/ws.js.map +1 -0
- package/dist/cjs/types/websockets/client.d.ts +46 -0
- package/dist/cjs/types/websockets/client.js +3 -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 +8 -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 +9 -0
- package/dist/cjs/types/websockets/wsAPI.js +3 -0
- package/dist/cjs/types/websockets/wsAPI.js.map +1 -0
- package/dist/mjs/FuturesClient.d.ts +246 -0
- package/dist/mjs/FuturesClient.js +257 -0
- package/dist/mjs/FuturesClient.js.map +1 -0
- package/dist/mjs/SpotClient.d.ts +692 -0
- package/dist/mjs/SpotClient.js +741 -0
- package/dist/mjs/SpotClient.js.map +1 -0
- package/dist/mjs/WebsocketClient.d.ts +77 -0
- package/dist/mjs/WebsocketClient.js +333 -0
- package/dist/mjs/WebsocketClient.js.map +1 -0
- package/dist/mjs/index.d.ts +22 -0
- package/dist/mjs/index.js +23 -0
- package/dist/mjs/index.js.map +1 -0
- package/dist/mjs/lib/BaseRestClient.d.ts +42 -0
- package/dist/mjs/lib/BaseRestClient.js +261 -0
- package/dist/mjs/lib/BaseRestClient.js.map +1 -0
- package/dist/mjs/lib/BaseWSClient.d.ts +168 -0
- package/dist/mjs/lib/BaseWSClient.js +615 -0
- package/dist/mjs/lib/BaseWSClient.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 +35 -0
- package/dist/mjs/lib/requestUtils.js +49 -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 +63 -0
- package/dist/mjs/lib/websocket/WsStore.js +249 -0
- package/dist/mjs/lib/websocket/WsStore.js.map +1 -0
- package/dist/mjs/lib/websocket/WsStore.types.d.ts +50 -0
- package/dist/mjs/lib/websocket/WsStore.types.js +11 -0
- package/dist/mjs/lib/websocket/WsStore.types.js.map +1 -0
- package/dist/mjs/lib/websocket/logger.d.ts +6 -0
- package/dist/mjs/lib/websocket/logger.js +13 -0
- package/dist/mjs/lib/websocket/logger.js.map +1 -0
- package/dist/mjs/lib/websocket/websocket-util.d.ts +30 -0
- package/dist/mjs/lib/websocket/websocket-util.js +15 -0
- package/dist/mjs/lib/websocket/websocket-util.js.map +1 -0
- package/dist/mjs/package.json +3 -0
- package/dist/mjs/types/request/futures.types.d.ts +183 -0
- package/dist/mjs/types/request/futures.types.js +6 -0
- package/dist/mjs/types/request/futures.types.js.map +1 -0
- package/dist/mjs/types/request/spot-account.d.ts +56 -0
- package/dist/mjs/types/request/spot-account.js +2 -0
- package/dist/mjs/types/request/spot-account.js.map +1 -0
- package/dist/mjs/types/request/spot-earn.d.ts +27 -0
- package/dist/mjs/types/request/spot-earn.js +7 -0
- package/dist/mjs/types/request/spot-earn.js.map +1 -0
- package/dist/mjs/types/request/spot-funding.d.ts +88 -0
- package/dist/mjs/types/request/spot-funding.js +9 -0
- package/dist/mjs/types/request/spot-funding.js.map +1 -0
- package/dist/mjs/types/request/spot-margin-trading.d.ts +169 -0
- package/dist/mjs/types/request/spot-margin-trading.js +9 -0
- package/dist/mjs/types/request/spot-margin-trading.js.map +1 -0
- package/dist/mjs/types/request/spot-trading.d.ts +214 -0
- package/dist/mjs/types/request/spot-trading.js +9 -0
- package/dist/mjs/types/request/spot-trading.js.map +1 -0
- package/dist/mjs/types/response/futures.types.d.ts +501 -0
- package/dist/mjs/types/response/futures.types.js +6 -0
- package/dist/mjs/types/response/futures.types.js.map +1 -0
- package/dist/mjs/types/response/shared.types.d.ts +9 -0
- package/dist/mjs/types/response/shared.types.js +2 -0
- package/dist/mjs/types/response/shared.types.js.map +1 -0
- package/dist/mjs/types/response/spot-account.d.ts +140 -0
- package/dist/mjs/types/response/spot-account.js +2 -0
- package/dist/mjs/types/response/spot-account.js.map +1 -0
- package/dist/mjs/types/response/spot-earn.d.ts +74 -0
- package/dist/mjs/types/response/spot-earn.js +7 -0
- package/dist/mjs/types/response/spot-earn.js.map +1 -0
- package/dist/mjs/types/response/spot-funding.d.ts +176 -0
- package/dist/mjs/types/response/spot-funding.js +9 -0
- package/dist/mjs/types/response/spot-funding.js.map +1 -0
- package/dist/mjs/types/response/spot-margin-trading.d.ts +257 -0
- package/dist/mjs/types/response/spot-margin-trading.js +9 -0
- package/dist/mjs/types/response/spot-margin-trading.js.map +1 -0
- package/dist/mjs/types/response/spot-trading.d.ts +388 -0
- package/dist/mjs/types/response/spot-trading.js +9 -0
- package/dist/mjs/types/response/spot-trading.js.map +1 -0
- package/dist/mjs/types/response/spot-vip.d.ts +38 -0
- package/dist/mjs/types/response/spot-vip.js +9 -0
- package/dist/mjs/types/response/spot-vip.js.map +1 -0
- package/dist/mjs/types/response/ws.d.ts +11 -0
- package/dist/mjs/types/response/ws.js +2 -0
- package/dist/mjs/types/response/ws.js.map +1 -0
- package/dist/mjs/types/websockets/client.d.ts +46 -0
- package/dist/mjs/types/websockets/client.js +2 -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 +8 -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 +9 -0
- package/dist/mjs/types/websockets/wsAPI.js +2 -0
- package/dist/mjs/types/websockets/wsAPI.js.map +1 -0
- package/package.json +70 -14
- package/LICENSE +0 -21
- package/index.js +0 -192
- package/test.js +0 -122
package/README.md
CHANGED
|
@@ -1,61 +1,277 @@
|
|
|
1
|
+
# Node.js & JavaScript SDK for Kucoin REST APIs, WebSockets & WebSocket API
|
|
2
|
+
|
|
1
3
|
<p align="center">
|
|
2
|
-
<
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
<a href="https://www.npmjs.com/package/kucoin-api">
|
|
5
|
+
<picture>
|
|
6
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://github.com/tiagosiebler/kucoin-api/blob/master/docs/images/logoDarkMode2.svg?raw=true#gh-dark-mode-only">
|
|
7
|
+
<img alt="SDK Logo" src="https://github.com/tiagosiebler/kucoin-api/blob/master/docs/images/logoBrightMode2.svg?raw=true#gh-light-mode-only">
|
|
8
|
+
</picture>
|
|
9
|
+
</a>
|
|
5
10
|
</p>
|
|
6
11
|
|
|
7
|
-
|
|
12
|
+
[][1]
|
|
13
|
+
[][1]
|
|
14
|
+
[][1]
|
|
15
|
+
[](https://github.com/tiagosiebler/kucoin-api/actions/workflows/e2etest.yml)
|
|
16
|
+
[][1]
|
|
17
|
+
[](https://t.me/nodetraders)
|
|
8
18
|
|
|
9
|
-
|
|
10
|
-
A Node.js client for the [KuCoin](https://www.kucoin.com/) API.
|
|
11
|
-
</p>
|
|
19
|
+
[1]: https://www.npmjs.com/package/kucoin-api
|
|
12
20
|
|
|
13
|
-
|
|
21
|
+
Updated & performant JavaScript & Node.js SDK for the Kucoin REST APIs and WebSockets:
|
|
14
22
|
|
|
15
|
-
|
|
23
|
+
- Complete integration with all Kucoin REST APIs and WebSockets.
|
|
24
|
+
- TypeScript support (with type declarations for most API requests & responses)
|
|
25
|
+
- Robust WebSocket integration with configurable connection heartbeats & automatic reconnect then resubscribe workflows.
|
|
26
|
+
- Browser-friendly HMAC signature mechanism.
|
|
27
|
+
- Automatically supports both ESM and CJS projects.
|
|
28
|
+
- Proxy support via axios integration.
|
|
29
|
+
- Active community support & collaboration in telegram: [Node.js Algo Traders](https://t.me/nodetraders).
|
|
16
30
|
|
|
17
|
-
|
|
31
|
+
## Installation
|
|
18
32
|
|
|
19
|
-
|
|
33
|
+
`npm install --save kucoin-api`
|
|
20
34
|
|
|
21
|
-
|
|
22
|
-
- Or ping **@satoshinaire** on **Twitter**.
|
|
23
|
-
- Pull requests welcome.
|
|
35
|
+
## Issues & Discussion
|
|
24
36
|
|
|
25
|
-
|
|
37
|
+
- Issues? Check the [issues tab](https://github.com/tiagosiebler/kucoin-api/issues).
|
|
38
|
+
- Discuss & collaborate with other node devs? Join our [Node.js Algo Traders](https://t.me/nodetraders) engineering community on telegram.
|
|
26
39
|
|
|
27
|
-
|
|
40
|
+
<!-- template_related_projects -->
|
|
28
41
|
|
|
42
|
+
## Related projects
|
|
43
|
+
|
|
44
|
+
Check out my related JavaScript/TypeScript/Node.js projects:
|
|
45
|
+
|
|
46
|
+
- Try my REST API & WebSocket SDKs:
|
|
47
|
+
- [Bybit-api Node.js SDK](https://www.npmjs.com/package/bybit-api)
|
|
48
|
+
- [Okx-api Node.js SDK](https://www.npmjs.com/package/okx-api)
|
|
49
|
+
- [Binance Node.js SDK](https://www.npmjs.com/package/binance)
|
|
50
|
+
- [Gateio-api Node.js SDK](https://www.npmjs.com/package/gateio-api)
|
|
51
|
+
- [Bitget-api Node.js SDK](https://www.npmjs.com/package/bitget-api)
|
|
52
|
+
- [Bitmart-api Node.js SDK](https://www.npmjs.com/package/bitmart-api)
|
|
53
|
+
- Try my misc utilities:
|
|
54
|
+
- [OrderBooks Node.js](https://www.npmjs.com/package/orderbooks)
|
|
55
|
+
- [Crypto Exchange Account State Cache](https://www.npmjs.com/package/accountstate)
|
|
56
|
+
- Check out my examples:
|
|
57
|
+
- [awesome-crypto-examples Node.js](https://github.com/tiagosiebler/awesome-crypto-examples)
|
|
58
|
+
<!-- template_related_projects_end -->
|
|
59
|
+
|
|
60
|
+
## Documentation
|
|
61
|
+
|
|
62
|
+
Most methods accept JS objects. These can be populated using parameters specified by Kucoin's API documentation.
|
|
63
|
+
|
|
64
|
+
- [Kucoin API Documentation](https://www.kucoin.com/docs/beginners/introduction)
|
|
65
|
+
- Node.js Quick Start Guides
|
|
66
|
+
- [Spot Node.js Kucoin Quick Start Guide](./examples/kucoin-SPOT-examples-nodejs.md)
|
|
67
|
+
- [Futures Node.js Kucoin Quick Start Guide](./examples/kucoin-FUTURES-examples-nodejs.md)
|
|
68
|
+
- [Futures Node.js Kucoin Order Placement Guide](./examples/rest-futures-orders-guide.ts)
|
|
69
|
+
<!-- - [TSDoc Documentation (autogenerated using typedoc)](https://tsdocs.dev/docs/kucoin-api) -->
|
|
70
|
+
|
|
71
|
+
## Structure
|
|
72
|
+
|
|
73
|
+
This project uses typescript. Resources are stored in 2 key structures:
|
|
74
|
+
|
|
75
|
+
- [src](./src) - the whole connector written in typescript
|
|
76
|
+
- [examples](./examples) - some implementation examples & demonstrations. Contributions are welcome!
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
# Usage
|
|
81
|
+
|
|
82
|
+
Create API credentials
|
|
83
|
+
|
|
84
|
+
- [Kucoin API Key Management](https://www.kucoin.com/account/api)
|
|
85
|
+
|
|
86
|
+
### REST API
|
|
87
|
+
|
|
88
|
+
To use any of Kucoin's REST APIs in JavaScript/TypeScript/Node.js, import (or require) the `SpotClient` (for spot and margin APIs) or `FuturesClient` (for futures APIs):
|
|
89
|
+
|
|
90
|
+
```javascript
|
|
91
|
+
const { SpotClient, FuturesClient } = require('kucoin-api');
|
|
92
|
+
|
|
93
|
+
const client = new SpotClient({
|
|
94
|
+
apiKey: 'apiKeyHere',
|
|
95
|
+
apiSecret: 'apiSecretHere',
|
|
96
|
+
apiPassphrase: 'apiPassPhraseHere',
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
try {
|
|
100
|
+
const spotBuyResult = await client.submitOrder({
|
|
101
|
+
clientOid: client.generateNewOrderID(),
|
|
102
|
+
side: 'buy',
|
|
103
|
+
type: 'market',
|
|
104
|
+
symbol: 'BTC-USDT',
|
|
105
|
+
size: '0.00001',
|
|
106
|
+
});
|
|
107
|
+
console.log('spotBuy ', JSON.stringify(spotBuyResult, null, 2));
|
|
108
|
+
|
|
109
|
+
const spotSellResult = await client.submitOrder({
|
|
110
|
+
clientOid: client.generateNewOrderID(),
|
|
111
|
+
side: 'sell',
|
|
112
|
+
type: 'market',
|
|
113
|
+
symbol: 'BTC-USDT',
|
|
114
|
+
size: '0.00001',
|
|
115
|
+
});
|
|
116
|
+
console.log('spotSellResult ', JSON.stringify(spotSellResult, null, 2));
|
|
117
|
+
} catch (e) {
|
|
118
|
+
console.error(`Req error: `, e);
|
|
119
|
+
}
|
|
29
120
|
```
|
|
30
|
-
npm install --save kucoin-api
|
|
31
|
-
```
|
|
32
121
|
|
|
33
|
-
|
|
122
|
+
See [SpotClient](./src/SpotClient.ts) and [FuturesClient](./src/FuturesClient.ts) for further information, or the [examples](./examples/) for lots of usage examples.
|
|
123
|
+
|
|
124
|
+
## WebSockets
|
|
125
|
+
|
|
126
|
+
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).
|
|
127
|
+
|
|
128
|
+
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.
|
|
34
129
|
|
|
130
|
+
Data events are emitted from the WebsocketClient via the `update` event, see example below:
|
|
131
|
+
|
|
132
|
+
```javascript
|
|
133
|
+
const { WebsocketClient } = require('kucoin-api');
|
|
134
|
+
|
|
135
|
+
const client = new WebsocketClient();
|
|
136
|
+
|
|
137
|
+
client.on('open', (data) => {
|
|
138
|
+
console.log('open: ', data?.wsKey);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
// Data received
|
|
142
|
+
client.on('update', (data) => {
|
|
143
|
+
console.info('data received: ', JSON.stringify(data));
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
// Something happened, attempting to reconenct
|
|
147
|
+
client.on('reconnect', (data) => {
|
|
148
|
+
console.log('reconnect: ', data);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
// Reconnect successful
|
|
152
|
+
client.on('reconnected', (data) => {
|
|
153
|
+
console.log('reconnected: ', data);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
// Connection closed. If unexpected, expect reconnect -> reconnected.
|
|
157
|
+
client.on('close', (data) => {
|
|
158
|
+
console.error('close: ', data);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
// Reply to a request, e.g. "subscribe"/"unsubscribe"/"authenticate"
|
|
162
|
+
client.on('response', (data) => {
|
|
163
|
+
console.info('response: ', data);
|
|
164
|
+
// throw new Error('res?');
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
client.on('exception', (data) => {
|
|
168
|
+
console.error('exception: ', {
|
|
169
|
+
msg: data.msg,
|
|
170
|
+
errno: data.errno,
|
|
171
|
+
code: data.code,
|
|
172
|
+
syscall: data.syscall,
|
|
173
|
+
hostname: data.hostname,
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
try {
|
|
178
|
+
// Optional: await a connection to be ready before subscribing (this is not necessary)
|
|
179
|
+
// await client.connect('futuresPublicV1');
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Examples for public futures websocket topics (that don't require authentication).
|
|
183
|
+
*
|
|
184
|
+
* These should all subscribe via the "futuresPublicV1" wsKey. For detailed usage, refer to the ws-spot-public.ts example.
|
|
185
|
+
*/
|
|
186
|
+
client.subscribe(
|
|
187
|
+
[
|
|
188
|
+
'/contractMarket/tickerV2:XBTUSDM',
|
|
189
|
+
'/contractMarket/ticker:XBTUSDM',
|
|
190
|
+
'/contractMarket/level2:XBTUSDM',
|
|
191
|
+
'/contractMarket/execution:XBTUSDM',
|
|
192
|
+
'/contractMarket/level2Depth5:XBTUSDM',
|
|
193
|
+
'/contractMarket/level2Depth50:XBTUSDM',
|
|
194
|
+
'/contractMarket/limitCandle:XBTUSDTM_1hour',
|
|
195
|
+
'/contract/instrument:XBTUSDM',
|
|
196
|
+
'/contract/announcement',
|
|
197
|
+
'/contractMarket/snapshot:XBTUSDM',
|
|
198
|
+
],
|
|
199
|
+
'futuresPublicV1',
|
|
200
|
+
);
|
|
201
|
+
} catch (e) {
|
|
202
|
+
console.error(`Subscribe exception: `, e);
|
|
203
|
+
}
|
|
35
204
|
```
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
205
|
+
|
|
206
|
+
See [WebsocketClient](./src/WebsocketClient.ts) for further information and make sure to check the [examples](./examples/) folder for much more detail, especially [ws-spot-public.ts](./examples/ws-spot-public.ts), which explains a lot of detail.
|
|
207
|
+
|
|
208
|
+
---
|
|
209
|
+
|
|
210
|
+
## Customise Logging
|
|
211
|
+
|
|
212
|
+
Pass a custom logger which supports the log methods `trace`, `info` and `error`, or override methods from the default logger as desired.
|
|
213
|
+
|
|
214
|
+
```javascript
|
|
215
|
+
const { WebsocketClient, DefaultLogger } = require('kucoin-api');
|
|
216
|
+
|
|
217
|
+
// E.g. customise logging for only the trace level:
|
|
218
|
+
const logger = {
|
|
219
|
+
// Inherit existing logger methods, using an object spread
|
|
220
|
+
...DefaultLogger,
|
|
221
|
+
// Define a custom trace function to override only that function
|
|
222
|
+
trace: (...params) => {
|
|
223
|
+
if (
|
|
224
|
+
[
|
|
225
|
+
'Sending ping',
|
|
226
|
+
// 'Sending upstream ws message: ',
|
|
227
|
+
'Received pong',
|
|
228
|
+
].includes(params[0])
|
|
229
|
+
) {
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
console.log('trace', JSON.stringify(params, null, 2));
|
|
233
|
+
},
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
const ws = new WebsocketClient(
|
|
237
|
+
{
|
|
238
|
+
apiKey: 'apiKeyHere',
|
|
239
|
+
apiSecret: 'apiSecretHere',
|
|
240
|
+
apiPassphrase: 'apiPassPhraseHere',
|
|
241
|
+
},
|
|
242
|
+
logger,
|
|
243
|
+
);
|
|
52
244
|
```
|
|
53
245
|
|
|
54
|
-
|
|
246
|
+
---
|
|
247
|
+
|
|
248
|
+
<!-- template_contributions -->
|
|
249
|
+
|
|
250
|
+
Have my projects helped you? Share the love, there are many ways you can show your thanks:
|
|
251
|
+
|
|
252
|
+
- Star & share my projects.
|
|
253
|
+
- Are my projects useful? Sponsor me on Github and support my effort to maintain & improve them: https://github.com/sponsors/tiagosiebler
|
|
254
|
+
- Have an interesting project? Get in touch & invite me to it.
|
|
255
|
+
- Or buy me all the coffee:
|
|
256
|
+
- ETH(ERC20): `0xA3Bda8BecaB4DCdA539Dc16F9C54a592553Be06C` <!-- metamask -->
|
|
257
|
+
|
|
258
|
+
<!---
|
|
259
|
+
old ones:
|
|
260
|
+
- BTC: `1C6GWZL1XW3jrjpPTS863XtZiXL1aTK7Jk`
|
|
261
|
+
- BTC(SegWit): `bc1ql64wr9z3khp2gy7dqlmqw7cp6h0lcusz0zjtls`
|
|
262
|
+
- ETH(ERC20): `0xe0bbbc805e0e83341fadc210d6202f4022e50992`
|
|
263
|
+
- USDT(TRC20): `TA18VUywcNEM9ahh3TTWF3sFpt9rkLnnQa
|
|
264
|
+
-->
|
|
265
|
+
<!-- template_contributions_end -->
|
|
266
|
+
|
|
267
|
+
### Contributions & Pull Requests
|
|
268
|
+
|
|
269
|
+
Contributions are encouraged, I will review any incoming pull requests. See the issues tab for todo items.
|
|
270
|
+
|
|
271
|
+
<!-- template_star_history -->
|
|
55
272
|
|
|
56
|
-
|
|
57
|
-
- Main author is [@satoshinaire](https://github.com/satoshinaire).
|
|
273
|
+
## Star History
|
|
58
274
|
|
|
59
|
-
|
|
275
|
+
[](https://star-history.com/#tiagosiebler/bybit-api&tiagosiebler/okx-api&tiagosiebler/binance&tiagosiebler/bitget-api&tiagosiebler/bitmart-api&tiagosiebler/gateio-api&tiagosiebler/kucoin-api&tiagosiebler/orderbooks&tiagosiebler/accountstate&tiagosiebler/awesome-crypto-examples&Date)
|
|
60
276
|
|
|
61
|
-
|
|
277
|
+
<!-- template_star_history_end -->
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { AxiosRequestConfig } from 'axios';
|
|
2
|
+
import { BaseRestClient } from './lib/BaseRestClient.js';
|
|
3
|
+
import { RestClientOptions, RestClientType } from './lib/requestUtils.js';
|
|
4
|
+
import { AccountFillsRequest, CreateSubAPIRequest, DeleteSubAPIRequest, GetFundingHistoryRequest, GetFundingRatesRequest, GetInterestRatesRequest, GetKlinesRequest, GetOrdersRequest, GetStopOrdersRequest, GetSubAPIsRequest, GetTransactionsRequest, GetTransfersRequest, MaxOpenSizeRequest, Order, SubmitTransfer, UpdateSubAPIRequest } from './types/request/futures.types.js';
|
|
5
|
+
import { AccountBalance, AccountSummary, AddMargin, CreateSubAccountAPI, FullOrderBookDetail, FuturesAccountFundingRateHistory, FuturesAccountTransaction, FuturesActiveOrder, FuturesClosedPositions, FuturesCurrentFundingRate, FuturesFill, FuturesFills, FuturesHistoricFundingRate, FuturesKline, FuturesMarkPrice, FuturesOrder, FuturesOrders, FuturesPosition, FuturesRiskLimit, FuturesSymbolInfo, FuturesTransferRecords, IndexListItem, InterestRateItem, MarketTradeDetail, MaxOpenSize, PremiumIndexItem, SubAccountAPI, SubBalance, SubmitMultipleOrdersFuturesResponse, TickerDetail, TransferDetail, UpdateSubAccountAPI } from './types/response/futures.types.js';
|
|
6
|
+
import { APISuccessResponse } from './types/response/shared.types.js';
|
|
7
|
+
import { WsConnectionInfo } from './types/response/ws.js';
|
|
8
|
+
/**
|
|
9
|
+
*
|
|
10
|
+
*/
|
|
11
|
+
export declare class FuturesClient extends BaseRestClient {
|
|
12
|
+
constructor(restClientOptions?: RestClientOptions, requestOptions?: AxiosRequestConfig);
|
|
13
|
+
getClientType(): RestClientType;
|
|
14
|
+
/**
|
|
15
|
+
*
|
|
16
|
+
* Misc Utility Methods
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
generateNewOrderID(): string;
|
|
20
|
+
getServerTime(): Promise<any>;
|
|
21
|
+
getServiceStatus(): Promise<any>;
|
|
22
|
+
/**
|
|
23
|
+
* REST - ACCOUNT - BASIC INFO
|
|
24
|
+
* Get Account Ledgers - Futures
|
|
25
|
+
*/
|
|
26
|
+
getTransactions(params: GetTransactionsRequest): Promise<APISuccessResponse<{
|
|
27
|
+
hasMore: boolean;
|
|
28
|
+
dataList: FuturesAccountTransaction[];
|
|
29
|
+
}>>;
|
|
30
|
+
/**
|
|
31
|
+
* REST - ACCOUNT - SUBACCOUNT API
|
|
32
|
+
*/
|
|
33
|
+
getSubAPIs(params: GetSubAPIsRequest): Promise<APISuccessResponse<SubAccountAPI[]>>;
|
|
34
|
+
createSubAPI(params: CreateSubAPIRequest): Promise<APISuccessResponse<CreateSubAccountAPI>>;
|
|
35
|
+
updateSubAPI(params: UpdateSubAPIRequest): Promise<APISuccessResponse<UpdateSubAccountAPI>>;
|
|
36
|
+
deleteSubAPI(params: DeleteSubAPIRequest): Promise<APISuccessResponse<{
|
|
37
|
+
subName: string;
|
|
38
|
+
apiKey: string;
|
|
39
|
+
}>>;
|
|
40
|
+
/**
|
|
41
|
+
* REST - FUNDING - FUNDING OVERVIEW
|
|
42
|
+
*/
|
|
43
|
+
getBalance(params?: {
|
|
44
|
+
currency?: string;
|
|
45
|
+
}): Promise<APISuccessResponse<AccountBalance>>;
|
|
46
|
+
getSubBalances(params?: {
|
|
47
|
+
currency?: string;
|
|
48
|
+
}): Promise<APISuccessResponse<{
|
|
49
|
+
summary: AccountSummary;
|
|
50
|
+
accounts: SubBalance[];
|
|
51
|
+
}>>;
|
|
52
|
+
/**
|
|
53
|
+
* REST - FUNDING - TRANSFER
|
|
54
|
+
*/
|
|
55
|
+
submitTransferOut(params: SubmitTransfer): Promise<Promise<APISuccessResponse<TransferDetail>>>;
|
|
56
|
+
submitTransferIn(params: SubmitTransfer): Promise<any>;
|
|
57
|
+
getTransfers(params: GetTransfersRequest): Promise<APISuccessResponse<FuturesTransferRecords>>;
|
|
58
|
+
/**
|
|
59
|
+
* REST - FUNDING - TRADE FEE
|
|
60
|
+
*/
|
|
61
|
+
getTradingPairFee(params: {
|
|
62
|
+
symbols: string;
|
|
63
|
+
}): Promise<APISuccessResponse<{
|
|
64
|
+
symbol: string;
|
|
65
|
+
takerFeeRate: string;
|
|
66
|
+
makerFeeRate: string;
|
|
67
|
+
}>>;
|
|
68
|
+
/**
|
|
69
|
+
*
|
|
70
|
+
* REST - FUTURES TRADING - Market Data
|
|
71
|
+
*
|
|
72
|
+
*/
|
|
73
|
+
getSymbols(): Promise<APISuccessResponse<FuturesSymbolInfo[]>>;
|
|
74
|
+
getSymbol(params: {
|
|
75
|
+
symbol: string;
|
|
76
|
+
}): Promise<APISuccessResponse<FuturesSymbolInfo>>;
|
|
77
|
+
getTicker(params: {
|
|
78
|
+
symbol: string;
|
|
79
|
+
}): Promise<APISuccessResponse<TickerDetail>>;
|
|
80
|
+
getTickers(): Promise<APISuccessResponse<TickerDetail[]>>;
|
|
81
|
+
getFullOrderBookLevel2(params: {
|
|
82
|
+
symbol: string;
|
|
83
|
+
}): Promise<APISuccessResponse<FullOrderBookDetail>>;
|
|
84
|
+
getPartOrderBookLevel2Depth20(params: {
|
|
85
|
+
symbol: string;
|
|
86
|
+
}): Promise<APISuccessResponse<FullOrderBookDetail>>;
|
|
87
|
+
getPartOrderBookLevel2Depth100(params: {
|
|
88
|
+
symbol: string;
|
|
89
|
+
}): Promise<APISuccessResponse<FullOrderBookDetail>>;
|
|
90
|
+
getMarketTrades(params: {
|
|
91
|
+
symbol: string;
|
|
92
|
+
}): Promise<APISuccessResponse<MarketTradeDetail>>;
|
|
93
|
+
getKlines(params: GetKlinesRequest): Promise<APISuccessResponse<FuturesKline[]>>;
|
|
94
|
+
getInterestRates(params: GetInterestRatesRequest): Promise<APISuccessResponse<{
|
|
95
|
+
dataList: InterestRateItem[];
|
|
96
|
+
hasMore: boolean;
|
|
97
|
+
}>>;
|
|
98
|
+
getIndex(params: GetInterestRatesRequest): Promise<APISuccessResponse<{
|
|
99
|
+
dataList: IndexListItem[];
|
|
100
|
+
hasMore: boolean;
|
|
101
|
+
}>>;
|
|
102
|
+
getMarkPrice(params: {
|
|
103
|
+
symbol: string;
|
|
104
|
+
}): Promise<APISuccessResponse<FuturesMarkPrice>>;
|
|
105
|
+
getPremiumIndex(params: GetInterestRatesRequest): Promise<APISuccessResponse<{
|
|
106
|
+
dataList: PremiumIndexItem[];
|
|
107
|
+
hasMore: boolean;
|
|
108
|
+
}>>;
|
|
109
|
+
get24HourTransactionVolume(): Promise<APISuccessResponse<{
|
|
110
|
+
turnoverOf24h: number;
|
|
111
|
+
}>>;
|
|
112
|
+
/**
|
|
113
|
+
*
|
|
114
|
+
* REST - FUTURES TRADING - Orders
|
|
115
|
+
*
|
|
116
|
+
*/
|
|
117
|
+
submitOrder(params: Order): Promise<APISuccessResponse<{
|
|
118
|
+
orderId: string;
|
|
119
|
+
}>>;
|
|
120
|
+
submitNewOrderTest(): Promise<any>;
|
|
121
|
+
cancelOrderById(params: {
|
|
122
|
+
orderId: string;
|
|
123
|
+
}): Promise<APISuccessResponse<{
|
|
124
|
+
cancelledOrderIds: string[];
|
|
125
|
+
}>>;
|
|
126
|
+
cancelOrderByClientOid(params: {
|
|
127
|
+
clientOid: string;
|
|
128
|
+
}): Promise<APISuccessResponse<{
|
|
129
|
+
clientOid: string;
|
|
130
|
+
}>>;
|
|
131
|
+
submitMultipleOrders(params: Order[]): Promise<APISuccessResponse<SubmitMultipleOrdersFuturesResponse[]>>;
|
|
132
|
+
cancelAllOrders(params?: {
|
|
133
|
+
symbol?: string;
|
|
134
|
+
}): Promise<APISuccessResponse<{
|
|
135
|
+
cancelledOrderIds: string[];
|
|
136
|
+
}>>;
|
|
137
|
+
cancelAllStopOrders(params?: {
|
|
138
|
+
symbol?: string;
|
|
139
|
+
}): Promise<APISuccessResponse<{
|
|
140
|
+
cancelledOrderIds: string[];
|
|
141
|
+
}>>;
|
|
142
|
+
getOrders(params?: GetOrdersRequest): Promise<APISuccessResponse<FuturesOrders>>;
|
|
143
|
+
getStopOrders(params?: GetStopOrdersRequest): Promise<APISuccessResponse<FuturesOrders>>;
|
|
144
|
+
getRecentOrders(params?: {
|
|
145
|
+
symbol?: string;
|
|
146
|
+
}): Promise<APISuccessResponse<FuturesOrder[]>>;
|
|
147
|
+
getOrderByOrderId(params: {
|
|
148
|
+
orderId: string;
|
|
149
|
+
}): Promise<APISuccessResponse<FuturesOrder>>;
|
|
150
|
+
getOrderByClientOrderId(params: {
|
|
151
|
+
clientOid: string;
|
|
152
|
+
}): Promise<APISuccessResponse<FuturesOrder>>;
|
|
153
|
+
/**
|
|
154
|
+
*
|
|
155
|
+
* REST - FUTURES TRADING - Fills
|
|
156
|
+
*
|
|
157
|
+
*/
|
|
158
|
+
/**
|
|
159
|
+
* Get a list of recent fills.
|
|
160
|
+
*
|
|
161
|
+
* If you need to get your recent trade history with low latency, please query endpoint Get List of Orders Completed in 24h.
|
|
162
|
+
* The requested data is not real-time.
|
|
163
|
+
*/
|
|
164
|
+
getFills(params?: AccountFillsRequest): Promise<APISuccessResponse<FuturesFills>>;
|
|
165
|
+
/**
|
|
166
|
+
* Get a list of recent 1000 fills in the last 24 hours.
|
|
167
|
+
*
|
|
168
|
+
* If you need to get your recent traded order history with low latency, you may query this endpoint.
|
|
169
|
+
*/
|
|
170
|
+
getRecentFills(params?: {
|
|
171
|
+
symbol?: string;
|
|
172
|
+
}): Promise<APISuccessResponse<FuturesFill[]>>;
|
|
173
|
+
getOpenOrderStatistics(params: {
|
|
174
|
+
symbol: string;
|
|
175
|
+
}): Promise<APISuccessResponse<FuturesActiveOrder>>;
|
|
176
|
+
/**
|
|
177
|
+
*
|
|
178
|
+
* REST - FUTURES TRADING - Positions
|
|
179
|
+
*
|
|
180
|
+
*/
|
|
181
|
+
getMaxOpenSize(params: MaxOpenSizeRequest): Promise<APISuccessResponse<MaxOpenSize>>;
|
|
182
|
+
getPosition(params: {
|
|
183
|
+
symbol: string;
|
|
184
|
+
}): Promise<APISuccessResponse<FuturesPosition>>;
|
|
185
|
+
getPositions(params?: {
|
|
186
|
+
currency?: string;
|
|
187
|
+
}): Promise<APISuccessResponse<FuturesPosition[]>>;
|
|
188
|
+
getHistoryPositions(params?: {
|
|
189
|
+
symbol?: string;
|
|
190
|
+
from?: number;
|
|
191
|
+
to?: number;
|
|
192
|
+
limit?: number;
|
|
193
|
+
pageId?: number;
|
|
194
|
+
}): Promise<APISuccessResponse<FuturesClosedPositions>>;
|
|
195
|
+
updateAutoDepositStatus(params: {
|
|
196
|
+
symbol: string;
|
|
197
|
+
status: boolean;
|
|
198
|
+
}): Promise<APISuccessResponse<boolean>>;
|
|
199
|
+
getMaxWithdrawMargin(params: {
|
|
200
|
+
symbol: string;
|
|
201
|
+
}): Promise<APISuccessResponse<number>>;
|
|
202
|
+
withdrawMargin(params: {
|
|
203
|
+
symbol: string;
|
|
204
|
+
withdrawAmount: string;
|
|
205
|
+
}): Promise<APISuccessResponse<{
|
|
206
|
+
sybmol: string;
|
|
207
|
+
withdrawAmount: number;
|
|
208
|
+
}>>;
|
|
209
|
+
depositMargin(params: {
|
|
210
|
+
symbol: string;
|
|
211
|
+
margin: number;
|
|
212
|
+
bizNo: string;
|
|
213
|
+
}): Promise<APISuccessResponse<AddMargin>>;
|
|
214
|
+
/**
|
|
215
|
+
*
|
|
216
|
+
* REST - FUTURES TRADING - Risk limit
|
|
217
|
+
*
|
|
218
|
+
*/
|
|
219
|
+
getRiskLimitLevel(params: {
|
|
220
|
+
symbol: string;
|
|
221
|
+
}): Promise<APISuccessResponse<FuturesRiskLimit[]>>;
|
|
222
|
+
updateRiskLimitLevel(params: {
|
|
223
|
+
symbol: string;
|
|
224
|
+
level: number;
|
|
225
|
+
}): Promise<any>;
|
|
226
|
+
/**
|
|
227
|
+
*
|
|
228
|
+
* REST - FUTURES TRADING - Funding fees
|
|
229
|
+
*
|
|
230
|
+
*/
|
|
231
|
+
getFundingRate(params: {
|
|
232
|
+
symbol: string;
|
|
233
|
+
}): Promise<APISuccessResponse<FuturesCurrentFundingRate>>;
|
|
234
|
+
getFundingRates(params: GetFundingRatesRequest): Promise<APISuccessResponse<FuturesHistoricFundingRate[]>>;
|
|
235
|
+
getFundingHistory(params: GetFundingHistoryRequest): Promise<APISuccessResponse<{
|
|
236
|
+
dataList: FuturesAccountFundingRateHistory[];
|
|
237
|
+
hasMore: boolean;
|
|
238
|
+
}>>;
|
|
239
|
+
/**
|
|
240
|
+
*
|
|
241
|
+
* WebSockets
|
|
242
|
+
*
|
|
243
|
+
*/
|
|
244
|
+
getPublicWSConnectionToken(): Promise<APISuccessResponse<WsConnectionInfo>>;
|
|
245
|
+
getPrivateWSConnectionToken(): Promise<APISuccessResponse<WsConnectionInfo>>;
|
|
246
|
+
}
|