kucoin-api 0.0.3 → 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.
Files changed (199) hide show
  1. package/README.md +219 -828
  2. package/dist/cjs/FuturesClient.d.ts +246 -0
  3. package/dist/cjs/FuturesClient.js +261 -0
  4. package/dist/cjs/FuturesClient.js.map +1 -0
  5. package/dist/cjs/SpotClient.d.ts +692 -0
  6. package/dist/cjs/SpotClient.js +745 -0
  7. package/dist/cjs/SpotClient.js.map +1 -0
  8. package/dist/cjs/WebsocketClient.d.ts +77 -0
  9. package/dist/cjs/WebsocketClient.js +337 -0
  10. package/dist/cjs/WebsocketClient.js.map +1 -0
  11. package/dist/cjs/index.d.ts +22 -0
  12. package/dist/cjs/index.js +39 -0
  13. package/dist/cjs/index.js.map +1 -0
  14. package/dist/cjs/lib/BaseRestClient.d.ts +42 -0
  15. package/dist/cjs/lib/BaseRestClient.js +268 -0
  16. package/dist/cjs/lib/BaseRestClient.js.map +1 -0
  17. package/dist/cjs/lib/BaseWSClient.d.ts +168 -0
  18. package/dist/cjs/lib/BaseWSClient.js +622 -0
  19. package/dist/cjs/lib/BaseWSClient.js.map +1 -0
  20. package/dist/cjs/lib/misc-util.d.ts +1 -0
  21. package/dist/cjs/lib/misc-util.js +8 -0
  22. package/dist/cjs/lib/misc-util.js.map +1 -0
  23. package/dist/cjs/lib/requestUtils.d.ts +35 -0
  24. package/dist/cjs/lib/requestUtils.js +54 -0
  25. package/dist/cjs/lib/requestUtils.js.map +1 -0
  26. package/dist/cjs/lib/webCryptoAPI.d.ts +10 -0
  27. package/dist/cjs/lib/webCryptoAPI.js +57 -0
  28. package/dist/cjs/lib/webCryptoAPI.js.map +1 -0
  29. package/dist/cjs/lib/websocket/WsStore.d.ts +63 -0
  30. package/dist/cjs/lib/websocket/WsStore.js +254 -0
  31. package/dist/cjs/lib/websocket/WsStore.js.map +1 -0
  32. package/dist/cjs/lib/websocket/WsStore.types.d.ts +50 -0
  33. package/dist/cjs/lib/websocket/WsStore.types.js +14 -0
  34. package/dist/cjs/lib/websocket/WsStore.types.js.map +1 -0
  35. package/dist/cjs/lib/websocket/logger.d.ts +6 -0
  36. package/dist/cjs/lib/websocket/logger.js +16 -0
  37. package/dist/cjs/lib/websocket/logger.js.map +1 -0
  38. package/dist/cjs/lib/websocket/websocket-util.d.ts +30 -0
  39. package/dist/cjs/lib/websocket/websocket-util.js +19 -0
  40. package/dist/cjs/lib/websocket/websocket-util.js.map +1 -0
  41. package/dist/cjs/package.json +3 -0
  42. package/dist/cjs/types/request/futures.types.d.ts +183 -0
  43. package/dist/cjs/types/request/futures.types.js +7 -0
  44. package/dist/cjs/types/request/futures.types.js.map +1 -0
  45. package/dist/cjs/types/request/spot-account.d.ts +56 -0
  46. package/dist/cjs/types/request/spot-account.js +3 -0
  47. package/dist/cjs/types/request/spot-account.js.map +1 -0
  48. package/dist/cjs/types/request/spot-earn.d.ts +27 -0
  49. package/dist/cjs/types/request/spot-earn.js +8 -0
  50. package/dist/cjs/types/request/spot-earn.js.map +1 -0
  51. package/dist/cjs/types/request/spot-funding.d.ts +88 -0
  52. package/dist/cjs/types/request/spot-funding.js +10 -0
  53. package/dist/cjs/types/request/spot-funding.js.map +1 -0
  54. package/dist/cjs/types/request/spot-margin-trading.d.ts +169 -0
  55. package/dist/cjs/types/request/spot-margin-trading.js +10 -0
  56. package/dist/cjs/types/request/spot-margin-trading.js.map +1 -0
  57. package/dist/cjs/types/request/spot-trading.d.ts +214 -0
  58. package/dist/cjs/types/request/spot-trading.js +10 -0
  59. package/dist/cjs/types/request/spot-trading.js.map +1 -0
  60. package/dist/cjs/types/response/futures.types.d.ts +501 -0
  61. package/dist/cjs/types/response/futures.types.js +7 -0
  62. package/dist/cjs/types/response/futures.types.js.map +1 -0
  63. package/dist/cjs/types/response/shared.types.d.ts +9 -0
  64. package/dist/cjs/types/response/shared.types.js +3 -0
  65. package/dist/cjs/types/response/shared.types.js.map +1 -0
  66. package/dist/cjs/types/response/spot-account.d.ts +140 -0
  67. package/dist/cjs/types/response/spot-account.js +3 -0
  68. package/dist/cjs/types/response/spot-account.js.map +1 -0
  69. package/dist/cjs/types/response/spot-earn.d.ts +74 -0
  70. package/dist/cjs/types/response/spot-earn.js +8 -0
  71. package/dist/cjs/types/response/spot-earn.js.map +1 -0
  72. package/dist/cjs/types/response/spot-funding.d.ts +176 -0
  73. package/dist/cjs/types/response/spot-funding.js +10 -0
  74. package/dist/cjs/types/response/spot-funding.js.map +1 -0
  75. package/dist/cjs/types/response/spot-margin-trading.d.ts +257 -0
  76. package/dist/cjs/types/response/spot-margin-trading.js +10 -0
  77. package/dist/cjs/types/response/spot-margin-trading.js.map +1 -0
  78. package/dist/cjs/types/response/spot-trading.d.ts +388 -0
  79. package/dist/cjs/types/response/spot-trading.js +10 -0
  80. package/dist/cjs/types/response/spot-trading.js.map +1 -0
  81. package/dist/cjs/types/response/spot-vip.d.ts +38 -0
  82. package/dist/cjs/types/response/spot-vip.js +10 -0
  83. package/dist/cjs/types/response/spot-vip.js.map +1 -0
  84. package/dist/cjs/types/response/ws.d.ts +11 -0
  85. package/dist/cjs/types/response/ws.js +3 -0
  86. package/dist/cjs/types/response/ws.js.map +1 -0
  87. package/dist/cjs/types/websockets/client.d.ts +46 -0
  88. package/dist/cjs/types/websockets/client.js +3 -0
  89. package/dist/cjs/types/websockets/client.js.map +1 -0
  90. package/dist/cjs/types/websockets/events.d.ts +5 -0
  91. package/dist/cjs/types/websockets/events.js +3 -0
  92. package/dist/cjs/types/websockets/events.js.map +1 -0
  93. package/dist/cjs/types/websockets/requests.d.ts +8 -0
  94. package/dist/cjs/types/websockets/requests.js +3 -0
  95. package/dist/cjs/types/websockets/requests.js.map +1 -0
  96. package/dist/cjs/types/websockets/wsAPI.d.ts +9 -0
  97. package/dist/cjs/types/websockets/wsAPI.js +3 -0
  98. package/dist/cjs/types/websockets/wsAPI.js.map +1 -0
  99. package/dist/mjs/FuturesClient.d.ts +246 -0
  100. package/dist/mjs/FuturesClient.js +257 -0
  101. package/dist/mjs/FuturesClient.js.map +1 -0
  102. package/dist/mjs/SpotClient.d.ts +692 -0
  103. package/dist/mjs/SpotClient.js +741 -0
  104. package/dist/mjs/SpotClient.js.map +1 -0
  105. package/dist/mjs/WebsocketClient.d.ts +77 -0
  106. package/dist/mjs/WebsocketClient.js +333 -0
  107. package/dist/mjs/WebsocketClient.js.map +1 -0
  108. package/dist/mjs/index.d.ts +22 -0
  109. package/dist/mjs/index.js +23 -0
  110. package/dist/mjs/index.js.map +1 -0
  111. package/dist/mjs/lib/BaseRestClient.d.ts +42 -0
  112. package/dist/mjs/lib/BaseRestClient.js +261 -0
  113. package/dist/mjs/lib/BaseRestClient.js.map +1 -0
  114. package/dist/mjs/lib/BaseWSClient.d.ts +168 -0
  115. package/dist/mjs/lib/BaseWSClient.js +615 -0
  116. package/dist/mjs/lib/BaseWSClient.js.map +1 -0
  117. package/dist/mjs/lib/misc-util.d.ts +1 -0
  118. package/dist/mjs/lib/misc-util.js +4 -0
  119. package/dist/mjs/lib/misc-util.js.map +1 -0
  120. package/dist/mjs/lib/requestUtils.d.ts +35 -0
  121. package/dist/mjs/lib/requestUtils.js +49 -0
  122. package/dist/mjs/lib/requestUtils.js.map +1 -0
  123. package/dist/mjs/lib/webCryptoAPI.d.ts +10 -0
  124. package/dist/mjs/lib/webCryptoAPI.js +52 -0
  125. package/dist/mjs/lib/webCryptoAPI.js.map +1 -0
  126. package/dist/mjs/lib/websocket/WsStore.d.ts +63 -0
  127. package/dist/mjs/lib/websocket/WsStore.js +249 -0
  128. package/dist/mjs/lib/websocket/WsStore.js.map +1 -0
  129. package/dist/mjs/lib/websocket/WsStore.types.d.ts +50 -0
  130. package/dist/mjs/lib/websocket/WsStore.types.js +11 -0
  131. package/dist/mjs/lib/websocket/WsStore.types.js.map +1 -0
  132. package/dist/mjs/lib/websocket/logger.d.ts +6 -0
  133. package/dist/mjs/lib/websocket/logger.js +13 -0
  134. package/dist/mjs/lib/websocket/logger.js.map +1 -0
  135. package/dist/mjs/lib/websocket/websocket-util.d.ts +30 -0
  136. package/dist/mjs/lib/websocket/websocket-util.js +15 -0
  137. package/dist/mjs/lib/websocket/websocket-util.js.map +1 -0
  138. package/dist/mjs/package.json +3 -0
  139. package/dist/mjs/types/request/futures.types.d.ts +183 -0
  140. package/dist/mjs/types/request/futures.types.js +6 -0
  141. package/dist/mjs/types/request/futures.types.js.map +1 -0
  142. package/dist/mjs/types/request/spot-account.d.ts +56 -0
  143. package/dist/mjs/types/request/spot-account.js +2 -0
  144. package/dist/mjs/types/request/spot-account.js.map +1 -0
  145. package/dist/mjs/types/request/spot-earn.d.ts +27 -0
  146. package/dist/mjs/types/request/spot-earn.js +7 -0
  147. package/dist/mjs/types/request/spot-earn.js.map +1 -0
  148. package/dist/mjs/types/request/spot-funding.d.ts +88 -0
  149. package/dist/mjs/types/request/spot-funding.js +9 -0
  150. package/dist/mjs/types/request/spot-funding.js.map +1 -0
  151. package/dist/mjs/types/request/spot-margin-trading.d.ts +169 -0
  152. package/dist/mjs/types/request/spot-margin-trading.js +9 -0
  153. package/dist/mjs/types/request/spot-margin-trading.js.map +1 -0
  154. package/dist/mjs/types/request/spot-trading.d.ts +214 -0
  155. package/dist/mjs/types/request/spot-trading.js +9 -0
  156. package/dist/mjs/types/request/spot-trading.js.map +1 -0
  157. package/dist/mjs/types/response/futures.types.d.ts +501 -0
  158. package/dist/mjs/types/response/futures.types.js +6 -0
  159. package/dist/mjs/types/response/futures.types.js.map +1 -0
  160. package/dist/mjs/types/response/shared.types.d.ts +9 -0
  161. package/dist/mjs/types/response/shared.types.js +2 -0
  162. package/dist/mjs/types/response/shared.types.js.map +1 -0
  163. package/dist/mjs/types/response/spot-account.d.ts +140 -0
  164. package/dist/mjs/types/response/spot-account.js +2 -0
  165. package/dist/mjs/types/response/spot-account.js.map +1 -0
  166. package/dist/mjs/types/response/spot-earn.d.ts +74 -0
  167. package/dist/mjs/types/response/spot-earn.js +7 -0
  168. package/dist/mjs/types/response/spot-earn.js.map +1 -0
  169. package/dist/mjs/types/response/spot-funding.d.ts +176 -0
  170. package/dist/mjs/types/response/spot-funding.js +9 -0
  171. package/dist/mjs/types/response/spot-funding.js.map +1 -0
  172. package/dist/mjs/types/response/spot-margin-trading.d.ts +257 -0
  173. package/dist/mjs/types/response/spot-margin-trading.js +9 -0
  174. package/dist/mjs/types/response/spot-margin-trading.js.map +1 -0
  175. package/dist/mjs/types/response/spot-trading.d.ts +388 -0
  176. package/dist/mjs/types/response/spot-trading.js +9 -0
  177. package/dist/mjs/types/response/spot-trading.js.map +1 -0
  178. package/dist/mjs/types/response/spot-vip.d.ts +38 -0
  179. package/dist/mjs/types/response/spot-vip.js +9 -0
  180. package/dist/mjs/types/response/spot-vip.js.map +1 -0
  181. package/dist/mjs/types/response/ws.d.ts +11 -0
  182. package/dist/mjs/types/response/ws.js +2 -0
  183. package/dist/mjs/types/response/ws.js.map +1 -0
  184. package/dist/mjs/types/websockets/client.d.ts +46 -0
  185. package/dist/mjs/types/websockets/client.js +2 -0
  186. package/dist/mjs/types/websockets/client.js.map +1 -0
  187. package/dist/mjs/types/websockets/events.d.ts +5 -0
  188. package/dist/mjs/types/websockets/events.js +2 -0
  189. package/dist/mjs/types/websockets/events.js.map +1 -0
  190. package/dist/mjs/types/websockets/requests.d.ts +8 -0
  191. package/dist/mjs/types/websockets/requests.js +2 -0
  192. package/dist/mjs/types/websockets/requests.js.map +1 -0
  193. package/dist/mjs/types/websockets/wsAPI.d.ts +9 -0
  194. package/dist/mjs/types/websockets/wsAPI.js +2 -0
  195. package/dist/mjs/types/websockets/wsAPI.js.map +1 -0
  196. package/package.json +70 -14
  197. package/LICENSE +0 -21
  198. package/index.js +0 -854
  199. package/test.js +0 -133
package/README.md CHANGED
@@ -1,886 +1,277 @@
1
- <p align="center">
2
- <img
3
- src="https://user-images.githubusercontent.com/30309816/31295829-c8d25310-ab2b-11e7-8885-fb335d0c3baf.png"
4
- width="125px;">
5
- </p>
6
-
7
- <h1 align="center">KuCoin API Client</h1>
1
+ # Node.js & JavaScript SDK for Kucoin REST APIs, WebSockets & WebSocket API
8
2
 
9
3
  <p align="center">
10
- A Node.js client for the [KuCoin](https://www.kucoin.com/) API.
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>
11
10
  </p>
12
11
 
13
- ## Overview
14
-
15
- ### What does it currently do
16
-
17
- The [KuCoin API documentation](http://docs.kucoinapidocs.apiary.io/) is not too bad, though some holes and inconsistencies. This Node.js client attempts to make up for some of those. 25 of the 29 endpoints are supported, the missing ones are mainly relating to Kline data.
18
-
19
- ### Get help or give help
20
-
21
- - Open a new [issue](https://github.com/Satoshinaire/kucoin-api/issues/new) if you encounter a problem.
22
- - Or ping **@satoshinaire** on **Twitter**.
23
- - Pull requests welcome.
24
-
25
- ## Getting started
26
-
27
- ### Installation
28
-
29
- npm install --save kucoin-api
30
-
31
- ### Usage
32
-
33
- 'use strict'
34
-
35
- require('dotenv').config()
36
- const Kucoin = require('kucoin-api')
37
-
38
- let kc = new Kucoin(process.env.KUCOIN_API_KEY, process.env.KUCOIN_API_SECRET)
12
+ [![npm version](https://img.shields.io/npm/v/kucoin-api)][1]
13
+ [![npm size](https://img.shields.io/bundlephobia/min/kucoin-api/latest)][1]
14
+ [![npm downloads](https://img.shields.io/npm/dt/kucoin-api)][1]
15
+ [![Build & Test](https://github.com/tiagosiebler/kucoin-api/actions/workflows/e2etest.yml/badge.svg?branch=master)](https://github.com/tiagosiebler/kucoin-api/actions/workflows/e2etest.yml)
16
+ [![last commit](https://img.shields.io/github/last-commit/tiagosiebler/kucoin-api)][1]
17
+ [![Telegram](https://img.shields.io/badge/chat-on%20telegram-blue.svg)](https://t.me/nodetraders)
39
18
 
40
- kc.getBalance({
41
- symbol: 'GAS'
42
- })
43
- .then((result) => {
44
- console.log(result)
45
- })
46
- .catch((err) => {
47
- console.log(err)
48
- })
19
+ [1]: https://www.npmjs.com/package/kucoin-api
49
20
 
50
- ## API
21
+ Updated & performant JavaScript & Node.js SDK for the Kucoin REST APIs and WebSockets:
51
22
 
52
- <!-- Generated by documentation.js. Update this documentation by updating the source code. -->
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).
53
30
 
54
- ### Kucoin
31
+ ## Installation
55
32
 
56
- A Node.js client for the KuCoin API.
33
+ `npm install --save kucoin-api`
57
34
 
58
- **Parameters**
35
+ ## Issues & Discussion
59
36
 
60
- - `apiKey` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Your KuCoin API Key.
61
- - `apiSecret` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Your KuCoin API Secret.
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.
62
39
 
63
- **Examples**
40
+ <!-- template_related_projects -->
64
41
 
65
- ```javascript
66
- let kc = new Kucoin();
67
- ```
42
+ ## Related projects
68
43
 
69
- **Meta**
44
+ Check out my related JavaScript/TypeScript/Node.js projects:
70
45
 
71
- - **version**: 0.0.2
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 -->
72
59
 
73
- #### getExchangeRates
60
+ ## Documentation
74
61
 
75
- Retrieve exchange rates for coins.
62
+ Most methods accept JS objects. These can be populated using parameters specified by Kucoin's API documentation.
76
63
 
77
- **Parameters**
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) -->
78
70
 
79
- - `params` **{symbols: [Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)>}?** An Array of symbols, or if blank BTC will be returned. (optional, default `{}`)
71
+ ## Structure
80
72
 
81
- **Examples**
73
+ This project uses typescript. Resources are stored in 2 key structures:
82
74
 
83
- _Specify one or more symbols:_
84
-
85
- ```javascript
86
- kc.getExchangeRates({
87
- symbols: ['NEO','GAS']
88
- }).then(console.log).catch(console.error)
89
-
90
- // Returns:
91
-
92
- {
93
- "success": true,
94
- "code": "OK",
95
- "msg": "Operation succeeded.",
96
- "timestamp": 1509589905631,
97
- "data": {
98
- "currencies": [["USD", "$"], ["EUR", "€"], ["AUD", "$"], ["CAD", "$"], ["CHF", "CHF"], ["CNY", "¥"], ["GBP", "£"], ["JPY", "¥"], ["NZD", "$"], ["BGN", "лв."], ["BRL", "R$"], ["CZK", "Kč"], ["DKK", "kr"], ["HKD", "$"], ["HRK", "kn"], ["HUF", "Ft"], ["IDR", "Rp"], ["ILS", "₪"], ["INR", "₹"], ["KRW", "₩"], ["MXN", "$"], ["MYR", "RM"], ["NOK", "kr"], ["PHP", "₱"], ["PLN", "zł"], ["RON", "lei"], ["RUB", "₽"], ["SEK", "kr"], ["SGD", "$"], ["THB", "฿"], ["TRY", "₺"], ["ZAR", "R"]],
99
- "rates": {
100
- "GAS": { "CHF": 14.57, "HRK": 94.19, "MXN": 279.02, "ZAR": 205.31, "INR": 939.59, "CNY": 96.15, "THB": 482.3, "AUD": 18.95, "ILS": 51.16, "KRW": 16176.81, "JPY": 1660.88, "PLN": 53.03, "GBP": 10.94, "IDR": 197577.69, "HUF": 3904.86, "PHP": 751.63, "TRY": 55.6, "RUB": 845.61, "HKD": 113.47, "EUR": 12.52, "DKK": 93.21, "USD": 14.54, "CAD": 18.77, "MYR": 61.54, "BGN": 24.49, "NOK": 118.5, "RON": 57.66, "SGD": 19.8, "CZK": 320.11, "SEK": 122.16, "NZD": 21.12, "BRL": 47.78
101
- },
102
- "NEO": {
103
- "CHF": 25.33, "HRK": 163.66, "MXN": 484.81, "ZAR": 356.73, "INR": 1632.55, "CNY": 167.07, "THB": 838.01, "AUD": 32.94, "ILS": 88.89, "KRW": 28107.31, "JPY": 2885.78, "PLN": 92.14, "GBP": 19.01, "IDR": 343292.4, "HUF": 6784.72, "PHP": 1305.97, "TRY": 96.61, "RUB": 1469.25, "HKD": 197.16, "EUR": 21.76, "DKK": 161.95, "USD": 25.27, "CAD": 32.61, "MYR": 106.93, "BGN": 42.56, "NOK": 205.9, "RON": 100.18, "SGD": 34.4, "CZK": 556.2, "SEK": 212.27, "NZD": 36.7, "BRL": 83.02
104
- }
105
- }
106
- }
107
- }
108
- ```
75
+ - [src](./src) - the whole connector written in typescript
76
+ - [examples](./examples) - some implementation examples & demonstrations. Contributions are welcome!
109
77
 
110
- _Retrieve data for BTC by default:_
78
+ ---
111
79
 
112
- ```javascript
113
- kc.getExchangeRates().then(console.log).catch(console.error)
114
-
115
- // Returns:
116
-
117
- {
118
- "success": true,
119
- "code": "OK",
120
- "msg": "Operation succeeded.",
121
- "timestamp": 1509590207497,
122
- "data": {
123
- "rates": {
124
- "BTC": { "CHF": 6817.62, "HRK": 44045.89, "MXN": 130476.13, "ZAR": 96007.15, "INR": 439363.98, "CNY": 44963.39, "THB": 225531.1, "AUD": 8865.49, "ILS": 23923.57, "KRW": 7564405.86, "JPY": 776640.44, "PLN": 24798.21, "GBP": 5118.25, "IDR": 92388859.2, "HUF": 1825945.01, "PHP": 351470.78, "TRY": 26002.05, "RUB": 395413.97, "HKD": 53061.7, "EUR": 5857.14, "DKK": 43586.13, "USD": 6801.3, "CAD": 8777.75, "MYR": 28779.7, "BGN": 11455.42, "NOK": 55414.27, "RON": 26962.39, "SGD": 9259.28, "CZK": 149689.81, "SEK": 57127.51, "NZD": 9878.88, "BRL": 22344.99
125
- }
126
- },
127
- "currencies": [["USD", "$"], ["EUR", "€"], ["AUD", "$"], ["CAD", "$"], ["CHF", "CHF"], ["CNY", "¥"], ["GBP", "£"], ["JPY", "¥"], ["NZD", "$"], ["BGN", "лв."], ["BRL", "R$"], ["CZK", "Kč"], ["DKK", "kr"], ["HKD", "$"], ["HRK", "kn"], ["HUF", "Ft"], ["IDR", "Rp"], ["ILS", "₪"], ["INR", "₹"], ["KRW", "₩"], ["MXN", "$"], ["MYR", "RM"], ["NOK", "kr"], ["PHP", "₱"], ["PLN", "zł"], ["RON", "lei"], ["RUB", "₽"], ["SEK", "kr"], ["SGD", "$"], ["THB", "฿"], ["TRY", "₺"], ["ZAR", "R"]]
128
- }
129
- }
130
- ```
80
+ # Usage
131
81
 
132
- Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** An object containing the API response.
82
+ Create API credentials
133
83
 
134
- #### getLanguages
84
+ - [Kucoin API Key Management](https://www.kucoin.com/account/api)
135
85
 
136
- Retrieve a list of supported languages.
86
+ ### REST API
137
87
 
138
- **Examples**
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):
139
89
 
140
90
  ```javascript
141
- kc.getLanguages().then(console.log).catch(console.error)
142
-
143
- // Returns:
144
-
145
- {
146
- "success": true,
147
- "code": "OK",
148
- "msg": "Operation succeeded.",
149
- "timestamp": 1509590811348,
150
- "data": [["zh_CN", "中文简体", true], ["zh_HK", "中文繁体", true], ["en_US", "English", true], ["ja_JP", "日本語", true], ["ru_RU", "русский", true], ["pt_PT", "Portugues", true], ["de_DE", "Deutsch", true], ["nl_NL", "Nederlands", true], ["ko_KR", "한국어", true], ["fr_FR", "Français", true], ["es_ES", "Español", false]]
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);
151
119
  }
152
120
  ```
153
121
 
154
- Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** An object containing the API response.
155
-
156
- #### changeLanguage
122
+ See [SpotClient](./src/SpotClient.ts) and [FuturesClient](./src/FuturesClient.ts) for further information, or the [examples](./examples/) for lots of usage examples.
157
123
 
158
- Change the language for your account.
124
+ ## WebSockets
159
125
 
160
- **Parameters**
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).
161
127
 
162
- - `params` **{lang: [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)}** The specific language locale to change to from the list provided by getLanguages. (optional, default `{}`)
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.
163
129
 
164
- **Examples**
130
+ Data events are emitted from the WebsocketClient via the `update` event, see example below:
165
131
 
166
132
  ```javascript
167
- kc.changeLanguage({
168
- lang: 'en_US'
169
- }).then(console.log).catch(console.error)
170
-
171
- // Returns:
172
-
173
- {
174
- "success": true,
175
- "code": "OK",
176
- "msg": "Operation succeeded.",
177
- "timestamp": 1509590866149,
178
- "data": null
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);
179
203
  }
180
204
  ```
181
205
 
182
- Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** An object containing the API response.
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.
183
207
 
184
- #### getUserInfo
208
+ ---
185
209
 
186
- Get account information for the authenticated user.
210
+ ## Customise Logging
187
211
 
188
- **Examples**
212
+ Pass a custom logger which supports the log methods `trace`, `info` and `error`, or override methods from the default logger as desired.
189
213
 
190
214
  ```javascript
191
- kc.getUserInfo().then(console.log).catch(console.error)
192
-
193
- // Returns:
194
-
195
- {
196
- "success": true,
197
- "code": "OK",
198
- "msg": "Operation succeeded.",
199
- "timestamp": 1509590943414,
200
- "data": {
201
- "referrer_code": "XXXXXX",
202
- "photoCredentialValidated": false,
203
- "videoValidated": false,
204
- "language": "en_US",
205
- "csrf": "XXXXXXXXXXXXXXXXXXXXXXX=",
206
- "oid": "xxxxxxxxxxxxxxxxxxxxxxxx",
207
- "baseFeeRate": 1,
208
- "hasCredential": false,
209
- "phoneValidated": true,
210
- "phone": "",
211
- "credentialValidated": false,
212
- "googleTwoFaBinding": true,
213
- "nickname": null,
214
- "name": "",
215
- "hasTradePassword": false,
216
- "currency": null,
217
- "emailValidated": true,
218
- "email": "hello@example.com"
219
- }
220
- }
221
- ```
222
-
223
- Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** An object containing the API response.
224
-
225
- #### getInviteCount
226
-
227
- Get the number of invitees from the authenticated user's referral code.
228
-
229
- **Examples**
230
-
231
- ```javascript
232
- kc.getInviteCount().then(console.log).catch(console.error)
233
-
234
- // Returns:
235
-
236
- {
237
- "success": true,
238
- "code": "OK",
239
- "msg": "Operation succeeded.",
240
- "timestamp": 1509591130780,
241
- "data": {
242
- "countThree": 0,
243
- "count": 0,
244
- "countTwo": 0
245
- }
246
- }
247
- ```
248
-
249
- Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** An object containing the API response.
250
-
251
- #### getPromotionRewardInfo
252
-
253
- Get promotion reward info.
254
-
255
- **Parameters**
256
-
257
- - `params` **{symbol: [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)}?** The coin's symbol to retrieve reward info for. (optional, default `{}`)
258
-
259
- **Examples**
260
-
261
- _Specify a symbol:_
262
-
263
- ```javascript
264
- kc.getPromotionRewardInfo({
265
- symbol: 'NEO'
266
- }).then(console.log).catch(console.error)
267
- ```
268
-
269
- _Retrieve data for all symbols:_
270
-
271
- ```javascript
272
- kc.getPromotionRewardInfo().then(console.log).catch(console.error)
273
-
274
- // Returns:
275
-
276
- {
277
- "success": true,
278
- "code": "OK",
279
- "msg": "Operation succeeded.",
280
- "timestamp": 1509591205512,
281
- "data": {
282
- "grantCountDownSeconds": 219994,
283
- "drawingCount": 0,
284
- "assignedCount": 0
285
- }
286
- }
287
- ```
288
-
289
- Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** An object containing the API response.
290
-
291
- #### getPromotionRewardSummary
292
-
293
- Get promotion reward summary.
294
-
295
- **Parameters**
296
-
297
- - `params` **{symbol: [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)}?** The coin's symbol to retrieve reward summary for. (optional, default `{}`)
298
-
299
- **Examples**
300
-
301
- _Specify a symbol:_
302
-
303
- ```javascript
304
- kc.getPromotionRewardSummary({
305
- symbol: 'NEO'
306
- }).then(console.log).catch(console.error)
307
- ```
308
-
309
- _Retrieve data for all symbols:_
310
-
311
- ```javascript
312
- kc.getPromotionRewardSummary().then(console.log).catch(console.error)
313
-
314
- // Returns:
315
-
316
- {
317
- "success": true,
318
- "code": "OK",
319
- "msg": "Operation succeeded.",
320
- "timestamp": 1509591324280,
321
- "data": []
322
- }
323
- ```
324
-
325
- Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** An object containing the API response.
326
-
327
- #### getDepositAddress
328
-
329
- Retrieve the deposit address for a particular coin.
330
-
331
- **Parameters**
332
-
333
- - `params` **{symbol: [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)}** The coin's symbol to retrieve an address for. (optional, default `{}`)
334
-
335
- **Examples**
336
-
337
- ```javascript
338
- kc.getDepositAddress({
339
- symbol: 'NEO'
340
- }).then(console.log).catch(console.error)
341
-
342
- // Returns:
343
-
344
- {
345
- "success": true,
346
- "code": "OK",
347
- "msg": "Operation succeeded.",
348
- "timestamp": 1509591494043,
349
- "data": {
350
- "oid": "xxxxxxxxxxxxxxxxxxxxxxxx",
351
- "address": "Axxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
352
- "context": null,
353
- "userOid": "xxxxxxxxxxxxxxxxxxxxxxxx",
354
- "coinType": "GAS",
355
- "createdAt": 1509354932000,
356
- "deletedAt": null,
357
- "updatedAt": 1509354932000,
358
- "lastReceivedAt": 1509541029000
359
- }
360
- }
361
- ```
362
-
363
- Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** An object containing the API response.
364
-
365
- #### createWithdrawal
366
-
367
- Create a withdrawal request for the specified coin.
368
-
369
- **Parameters**
370
-
371
- - `params` **{symbol: [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String), amount: [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number), address: [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)}** Withdrawal details including the coin's symbol, amount, and address to withdraw to. (optional, default `{}`)
372
-
373
- **Examples**
374
-
375
- ```javascript
376
- kc.createWithdrawal({
377
- symbol: 'NEO',
378
- amount: 5,
379
- address: 'AWcAwoXK6gbMUTojHMHEx8FgEfaVK9Hz5s'
380
- }).then(console.log).catch(console.error)
381
- ```
382
-
383
- Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** An object containing the API response.
384
-
385
- #### cancelWithdrawal
386
-
387
- Cancel a withdrawal request for the specified coin.
388
-
389
- **Parameters**
390
-
391
- - `params` **{symbol: [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String), txOid: [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)}** Withdrawal details including the coin's symbol and transaction ID for the withdrawal. (optional, default `{}`)
392
-
393
- **Examples**
394
-
395
- ```javascript
396
- kc.cancelWithdrawal({
397
- symbol: 'NEO',
398
- txOid: '59fa71673b7468701cd714a1'
399
- }).then(console.log).catch(console.error)
400
- ```
401
-
402
- Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** An object containing the API response.
403
-
404
- #### getDepositAndWithdrawalRecords
405
-
406
- Retrieve deposit and withdrawal record history.
407
-
408
- **Parameters**
409
-
410
- - `params` **{symbol: [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String), type: [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String), status: [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String), limit: [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number), page: [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)}** Record details including the coin's symbol, type, status, limit, and page number for the records. (optional, default `{}`)
411
-
412
- **Examples**
413
-
414
- ```javascript
415
- kc.getDepositAndWithdrawalRecords({
416
- symbol: 'GAS'
417
- }).then(console.log).catch(console.error)
418
-
419
- // Returns:
420
-
421
- {
422
- "success": true,
423
- "code": "OK",
424
- "msg": "Operation succeeded.",
425
- "timestamp": 1509591779228,
426
- "data": {
427
- "total": 2,
428
- "firstPage": true,
429
- "lastPage": false,
430
- "datas": [{
431
- "coinType": "GAS",
432
- "createdAt": 1509540909000,
433
- "amount": 0.1117,
434
- "address": "Axxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
435
- "fee": 0,
436
- "outerWalletTxid": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx@Axxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx@gas",
437
- "remark": null,
438
- "oid": "xxxxxxxxxxxxxxxxxxxxxxxx",
439
- "confirmation": 7,
440
- "type": "DEPOSIT",
441
- "status": "SUCCESS",
442
- "updatedAt": 1509541029000
443
- }, {
444
- "coinType": "GAS",
445
- "createdAt": 1509358609000,
446
- "amount": 1.1249,
447
- "address": "Axxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
448
- "fee": 0,
449
- "outerWalletTxid": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx@Axxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx@gas",
450
- "remark": null,
451
- "oid": "xxxxxxxxxxxxxxxxxxxxxxxx",
452
- "confirmation": 6,
453
- "type": "DEPOSIT",
454
- "status": "SUCCESS",
455
- "updatedAt": 1509358729000
456
- }],
457
- "currPageNo": 1,
458
- "limit": 12,
459
- "pageNos": 1
460
- }
461
- }
462
- ```
463
-
464
- Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** An object containing the API response.
465
-
466
- #### getBalance
467
-
468
- Retrieve balance for a particular coin.
469
-
470
- **Parameters**
471
-
472
- - `params` **{symbol: [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)}?** The coin's symbol for the balance you want to retrieve. (optional, default `{}`)
473
-
474
- **Examples**
475
-
476
- _Retrieve the balance for NEO:_
477
-
478
- ```javascript
479
- kc.getBalance({
480
- symbol: 'NEO'
481
- }).then(console.log).catch(console.error)
482
-
483
- // Returns:
484
-
485
- {
486
- "success": true,
487
- "code": "OK",
488
- "msg": "Operation succeeded.",
489
- "timestamp": 1509592077557,
490
- "data": {
491
- "coinType": "NEO",
492
- "balanceStr": "10.72040467",
493
- "freezeBalance": 0,
494
- "balance": 10.72040467,
495
- "freezeBalanceStr": "0.0"
496
- }
497
- }
498
- ```
499
-
500
- _Retrieve the balance for all coins (including zero balances):_
501
-
502
- ```javascript
503
- kc.getBalance().then(console.log).catch(console.error)
504
- ```
505
-
506
- Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** An object containing the API response.
507
-
508
- #### createOrder
509
-
510
- Create an order for the specified trading pair.
511
-
512
- **Parameters**
513
-
514
- - `params` **{pair: [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String), amount: [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number), price: [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number), type: [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)}** Order details including the trading pair, amount, price, and type of order. (optional, default `{}`)
515
-
516
- **Examples**
517
-
518
- _Create an order to sell 5 GAS for NEO at the specified price:_
519
-
520
- ```javascript
521
- kc.createWithdrawal({
522
- pair: 'GAS-NEO',
523
- amount: 5,
524
- price: 0.608004
525
- type: 'SELL'
526
- }).then(console.log).catch(console.error)
527
-
528
- // Returns:
529
-
530
- {
531
- success: true,
532
- code: 'OK',
533
- msg: 'OK',
534
- timestamp: 1509592202904,
535
- data: {
536
- orderOid: 'xxxxxxxxxxxxxxxxxxxxxxxx'
537
- }
538
- }
539
- ```
540
-
541
- Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** An object containing the API response.
542
-
543
- #### getActiveOrders
544
-
545
- View a list of active orders for the specified trading pair
546
-
547
- **Parameters**
548
-
549
- - `params` **{pair: [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)}** The trading pair to retrieve orders for. (optional, default `{}`)
550
-
551
- **Examples**
552
-
553
- ```javascript
554
- kc.getActiveOrders({
555
- pair: 'GAS-NEO'
556
- }).then(console.log).catch(console.error)
557
-
558
- // Returns:
559
-
560
- {
561
- "success": true,
562
- "code": "OK",
563
- "msg": "Operation succeeded.",
564
- "timestamp": 1509592278263,
565
- "data": {
566
- "SELL": [[1509592203000, "SELL", 1, 0.11206064, 0, "xxxxxxxxxxxxxxxxxxxxxxxx"]],
567
- "BUY": []
568
- }
569
- }
570
- ```
571
-
572
- Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** An object containing the API response.
573
-
574
- #### cancelOrder
575
-
576
- Cancel an order for the specified trading pair.
577
-
578
- **Parameters**
579
-
580
- - `params` **{pair: [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String), txOid: [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)}** Order details including the trading pair and transaction ID for the order. (optional, default `{}`)
581
-
582
- **Examples**
583
-
584
- ```javascript
585
- kc.cancelOrder({
586
- pair: 'GAS-NEO',
587
- txOid: '59fa71673b7468701cd714a1'
588
- }).then(console.log).catch(console.error)
589
-
590
- // Returns:
591
-
592
- {
593
- success: true,
594
- code: 'OK',
595
- msg: 'Operation succeeded.',
596
- timestamp: 1509592278426,
597
- data: null
598
- }
599
- ```
600
-
601
- Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** An object containing the API response.
602
-
603
- #### getDealtOrders
604
-
605
- Retrieve a list of completed orders for the specified trading pair.
606
-
607
- **Parameters**
608
-
609
- - `params` **{pair: [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String), type: [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String), limit: [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number), page: [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)}** Order details including the trading pair, type, limit, and page number for the orders. (optional, default `{}`)
610
-
611
- **Examples**
612
-
613
- ```javascript
614
- kc.getDealtOrders({
615
- pair: 'GAS-NEO'
616
- }).then(console.log).catch(console.error)
617
-
618
- // Returns:
619
-
620
- {
621
- "success": true,
622
- "code": "OK",
623
- "msg": "Operation succeeded.",
624
- "timestamp": 1509592427203,
625
- "data": {
626
- "total": 1,
627
- "firstPage": true,
628
- "lastPage": false,
629
- "datas": [{
630
- "coinType": "GAS",
631
- "createdAt": 1509455416000,
632
- "amount": 0.14494322,
633
- "dealValue": 0.0929086,
634
- "fee": 0.00009291,
635
- "dealDirection": "SELL",
636
- "coinTypePair": "NEO",
637
- "oid": "xxxxxxxxxxxxxxxxxxxxxxxx",
638
- "dealPrice": 0.641,
639
- "orderOid": "xxxxxxxxxxxxxxxxxxxxxxxx",
640
- "feeRate": 0.001,
641
- "direction": "SELL"
642
- }],
643
- "currPageNo": 1,
644
- "limit": 12,
645
- "pageNos": 1
646
- }
647
- }
648
- ```
649
-
650
- Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** An object containing the API response.
651
-
652
- #### getTicker
653
-
654
- Retrieve current price ticker data for the specified trading pair.
655
-
656
- **Parameters**
657
-
658
- - `params` **{pair: [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)}** The trading pair to retrieve price ticker for. (optional, default `{}`)
659
-
660
- **Examples**
661
-
662
- ```javascript
663
- kc.getTicker({
664
- pair: 'GAS-NEO'
665
- }).then(console.log).catch(console.error)
666
-
667
- // Returns:
668
-
669
- {
670
- "success": true,
671
- "code": "OK",
672
- "msg": "Operation succeeded.",
673
- "timestamp": 1509592566746,
674
- "data": {
675
- "coinType": "GAS",
676
- "trading": true,
677
- "symbol": "GAS-NEO",
678
- "lastDealPrice": 0.627999,
679
- "buy": 0.608004,
680
- "sell": 0.628,
681
- "change": 0.019994,
682
- "coinTypePair": "NEO",
683
- "sort": 0,
684
- "feeRate": 0.001,
685
- "volValue": 5246.36133161,
686
- "high": 0.635,
687
- "datetime": 1509592566000,
688
- "vol": 8499.38951847,
689
- "low": 0.601101,
690
- "changeRate": 0.0329
691
- }
692
- }
693
- ```
694
-
695
- Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** An object containing the API response.
696
-
697
- #### getOrderBooks
698
-
699
- Retrieve a list of orders for the specified trading pair.
700
-
701
- **Parameters**
702
-
703
- - `params` **{pair: [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String), type: [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String), group: [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number), limit: [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)}** Order book details including the trading pair, type, group, and limit for the orders. (optional, default `{}`)
704
-
705
- **Examples**
706
-
707
- _Retrieve all orders currently on the books for the GAS-NEO trading pair:_
708
-
709
- ```javascript
710
- kc.getOrderBooks({
711
- pair: 'GAS-NEO'
712
- }).then(console.log).catch(console.error)
713
-
714
- // Returns:
715
-
716
- {
717
- "success": true,
718
- "code": "OK",
719
- "msg": "Operation succeeded.",
720
- "timestamp": 1509592645132,
721
- "data": {
722
- "SELL": [[0.628, 227.1374, 142.6422872], [0.632999, 10, 6.32999], [0.633, 4.20740806, 2.6632893], [0.65, 0.6346, 0.41249], [0.6611, 6.7998, 4.49534778], [0.665699, 0.1875, 0.12481856]],
723
- "BUY": [[0.608004, 9.8481, 5.98768419], [0.608003, 21.9264, 13.33131698], [0.608001, 43.8442, 26.65731744], [0.604001, 25.5521, 15.43349395], [0.603, 1.0561, 0.6368283], [0.602006, 25, 15.05015]]
724
- }
725
- }
726
- ```
727
-
728
- _Retrieve only SELL orders currently on the books for the GAS-NEO trading pair:_
729
-
730
- ```javascript
731
- kc.getOrderBooks({
732
- pair: 'GAS-NEO',
733
- type: 'SELL'
734
- }).then(console.log).catch(console.error)
735
-
736
- // Returns:
737
-
738
- {
739
- "success": true,
740
- "code": "OK",
741
- "msg": "Operation succeeded.",
742
- "timestamp": 1509592734633,
743
- "data": [[0.628, 227.1374, 142.6422872], [0.632999, 10, 6.32999], [0.633, 4.20740806, 2.6632893], [0.65, 0.6346, 0.41249], [0.6611, 6.7998, 4.49534778], [0.665699, 0.1875, 0.12481856]]
744
- }
745
- ```
746
-
747
- Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** An object containing the API response.
748
-
749
- #### getRecentlyDealtOrders
750
-
751
- Retrieve a list of recently completed orders for the specified trading pair.
752
-
753
- **Parameters**
754
-
755
- - `params` **{pair: [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String), limit: [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number), since: [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)}** Order book details including the trading pair, limit, and since for the orders. (optional, default `{}`)
756
-
757
- **Examples**
758
-
759
- ```javascript
760
- kc.getRecentlyDealtOrders({
761
- pair: 'GAS-NEO'
762
- }).then(console.log).catch(console.error)
763
-
764
- // Returns:
765
-
766
- {
767
- "success": true,
768
- "code": "OK",
769
- "msg": "Operation succeeded.",
770
- "timestamp": 1509592783348,
771
- "data": [[1509591191000, "SELL", 0.608005, 10.771, 6.54882186], [1509591198000, "SELL", 0.608005, 10.7648, 6.54505222], [1509591512000, "SELL", 0.608005, 13.0292, 7.92181875], [1509591714000, "BUY", 0.627999, 19.9774, 12.54578722], [1509591951000, "SELL", 0.608005, 15.6217, 9.49807171], [1509592026000, "SELL", 0.608005, 15.2009, 9.2422232], [1509592105000, "SELL", 0.608005, 13.4969, 8.20618268], [1509592219000, "BUY", 0.627999, 20.9506, 13.15695585], [1509592311000, "BUY", 0.627999, 23.5278, 14.77543487], [1509592724000, "SELL", 0.608005, 8.6837, 5.27973302]]
772
- }
773
- ```
774
-
775
- Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** An object containing the API response.
776
-
777
- #### getTradingSymbols
778
-
779
- Retrieve a list of available trading pairs.
780
-
781
- **Examples**
782
-
783
- ```javascript
784
- kc.getTradingSymbols().then(console.log).catch(console.error)
785
-
786
- // Returns:
787
-
788
- {
789
- "success": true,
790
- "code": "OK",
791
- "msg": "Operation succeeded.",
792
- "timestamp": 1509592839027,
793
- "data": [{
794
- "coinType": "KCS",
795
- "trading": true,
796
- "symbol": "KCS-BTC",
797
- "lastDealPrice": 0.00009277,
798
- "buy": 0.00009003,
799
- "sell": 0.0000927,
800
- "change": -0.00000322,
801
- "coinTypePair": "BTC",
802
- "sort": 0,
803
- "feeRate": 0.001,
804
- "volValue": 139.78123495,
805
- "high": 0.00012281,
806
- "datetime": 1509592836000,
807
- "vol": 1347022.79127505,
808
- "low": 0.0000835,
809
- "changeRate": -0.0335
810
- }, {
811
- ...
812
- }]
813
- }
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
+ );
814
244
  ```
815
245
 
816
- Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** An object containing the API response.
817
-
818
- #### getTrending
246
+ ---
819
247
 
820
- Retrieve a list of trending trading pairs.
248
+ <!-- template_contributions -->
821
249
 
822
- **Examples**
250
+ Have my projects helped you? Share the love, there are many ways you can show your thanks:
823
251
 
824
- ```javascript
825
- kc.getTrending().then(console.log).catch(console.error)
826
-
827
- // Returns:
828
-
829
- {
830
- "success": true,
831
- "code": "OK",
832
- "msg": "Operation succeeded.",
833
- "timestamp": 1509593321973,
834
- "data": [{
835
- "coinPair": "KCS-BTC",
836
- "deals": [[1509591600000, 0.0000928], [1509588000000, 0.00009421], [1509584400000, 0.00009134], [1509580800000, 0.000096], [1509577200000, 0.00010014], [1509573600000, 0.00010293], [1509570000000, 0.00010368], [1509566400000, 0.000107], [1509562800000, 0.00010496], [1509559200000, 0.0001057], [1509555600000, 0.000108], [1509552000000, 0.0001117], [1509548400000, 0.0001142], [1509544800000, 0.000114], [1509541200000, 0.000114], [1509537600000, 0.0001135], [1509534000000, 0.0001135], [1509530400000, 0.0001011], [1509526800000, 0.00010799], [1509523200000, 0.00011405], [1509519600000, 0.0001164], [1509516000000, 0.00012099], [1509512400000, 0.00012107], [1509508800000, 0.00012244], [1509505200000, 0.00012281], [1509501600000, 0.00012295], [1509498000000, 0.00012348], [1509494400000, 0.0001242], [1509490800000, 0.00012895], [1509487200000, 0.00012897], [1509483600000, 0.00012899], [1509480000000, 0.00012849], [1509476400000, 0.00012987], [1509472800000, 0.00013], [1509469200000, 0.00013188], [1509465600000, 0.00012978], [1509462000000, 0.00012978], [1509458400000, 0.000126], [1509454800000, 0.00012978], [1509451200000, 0.00012562], [1509447600000, 0.00012999], [1509444000000, 0.00013009], [1509440400000, 0.0001346], [1509436800000, 0.00013465], [1509433200000, 0.00013465], [1509429600000, 0.00013376], [1509426000000, 0.00013465], [1509422400000, 0.00013457], [1509418800000, 0.00013489], [1509415200000, 0.00013693], [1509411600000, 0.0001329], [1509408000000, 0.00013499], [1509404400000, 0.00013711], [1509400800000, 0.00013723], [1509397200000, 0.00013999], [1509393600000, 0.00013992], [1509390000000, 0.00014195], [1509386400000, 0.00014284], [1509382800000, 0.0001425], [1509379200000, 0.00014286], [1509375600000, 0.00014406], [1509372000000, 0.00014591], [1509368400000, 0.00014647], [1509364800000, 0.0001457], [1509361200000, 0.00014575], [1509357600000, 0.00014659], [1509354000000, 0.00014998], [1509350400000, 0.0001517], [1509346800000, 0.0001488], [1509343200000, 0.0001488], [1509339600000, 0.00014999], [1509336000000, 0.0001521]]
837
- }, {
838
- ...
839
- }]
840
- }
841
- ```
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 -->
842
257
 
843
- Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** An object containing the API response.
258
+ <!---
259
+ old ones:
260
+ - BTC: `1C6GWZL1XW3jrjpPTS863XtZiXL1aTK7Jk`
261
+ - BTC(SegWit): `bc1ql64wr9z3khp2gy7dqlmqw7cp6h0lcusz0zjtls`
262
+ - ETH(ERC20): `0xe0bbbc805e0e83341fadc210d6202f4022e50992`
263
+ - USDT(TRC20): `TA18VUywcNEM9ahh3TTWF3sFpt9rkLnnQa
264
+ -->
265
+ <!-- template_contributions_end -->
844
266
 
845
- #### getCoins
846
-
847
- Retrieve a list of available coins.
848
-
849
- **Examples**
850
-
851
- ```javascript
852
- kc.getCoins().then(console.log).catch(console.error)
853
-
854
- // Returns:
855
-
856
- {
857
- "success": true,
858
- "code": "OK",
859
- "msg": "Operation succeeded.",
860
- "timestamp": 1509593539250,
861
- "data": [{
862
- "withdrawMinFee": 2,
863
- "withdrawMinAmount": 50,
864
- "withdrawFeeRate": 0.001,
865
- "confirmationCount": 12,
866
- "name": "Kucoin Shares",
867
- "tradePrecision": 4,
868
- "enableWithdraw": true,
869
- "enableDeposit": true,
870
- "coin": "KCS"
871
- }, {
872
- ...
873
- }]
874
- }
875
- ```
267
+ ### Contributions & Pull Requests
876
268
 
877
- Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** An object containing the API response.
269
+ Contributions are encouraged, I will review any incoming pull requests. See the issues tab for todo items.
878
270
 
879
- ## License
271
+ <!-- template_star_history -->
880
272
 
881
- - Open-source [MIT](https://github.com/Satoshinaire/kucoin-api/blob/master/LICENSE).
882
- - Main author is [@satoshinaire](https://github.com/satoshinaire).
273
+ ## Star History
883
274
 
884
- ## Donations
275
+ [![Star History Chart](https://api.star-history.com/svg?repos=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&type=Date)](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)
885
276
 
886
- NEO / GAS accepted at **AWcAwoXK6gbMUTojHMHEx8FgEfaVK9Hz5s**
277
+ <!-- template_star_history_end -->