@siebly/kraken-api 0.0.9

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 (204) hide show
  1. package/LICENSE.md +7 -0
  2. package/README.md +624 -0
  3. package/dist/cjs/DerivativesClient.d.ts +657 -0
  4. package/dist/cjs/DerivativesClient.js +726 -0
  5. package/dist/cjs/DerivativesClient.js.map +1 -0
  6. package/dist/cjs/InstitutionalClient.d.ts +183 -0
  7. package/dist/cjs/InstitutionalClient.js +266 -0
  8. package/dist/cjs/InstitutionalClient.js.map +1 -0
  9. package/dist/cjs/PartnerClient.d.ts +257 -0
  10. package/dist/cjs/PartnerClient.js +344 -0
  11. package/dist/cjs/PartnerClient.js.map +1 -0
  12. package/dist/cjs/SpotClient.d.ts +547 -0
  13. package/dist/cjs/SpotClient.js +607 -0
  14. package/dist/cjs/SpotClient.js.map +1 -0
  15. package/dist/cjs/WebsocketAPIClient.d.ts +95 -0
  16. package/dist/cjs/WebsocketAPIClient.js +136 -0
  17. package/dist/cjs/WebsocketAPIClient.js.map +1 -0
  18. package/dist/cjs/WebsocketClient.d.ts +120 -0
  19. package/dist/cjs/WebsocketClient.js +669 -0
  20. package/dist/cjs/WebsocketClient.js.map +1 -0
  21. package/dist/cjs/index.d.ts +24 -0
  22. package/dist/cjs/index.js +41 -0
  23. package/dist/cjs/index.js.map +1 -0
  24. package/dist/cjs/lib/BaseRestClient.d.ts +66 -0
  25. package/dist/cjs/lib/BaseRestClient.js +548 -0
  26. package/dist/cjs/lib/BaseRestClient.js.map +1 -0
  27. package/dist/cjs/lib/BaseWSClient.d.ts +230 -0
  28. package/dist/cjs/lib/BaseWSClient.js +935 -0
  29. package/dist/cjs/lib/BaseWSClient.js.map +1 -0
  30. package/dist/cjs/lib/misc-util.d.ts +1 -0
  31. package/dist/cjs/lib/misc-util.js +7 -0
  32. package/dist/cjs/lib/misc-util.js.map +1 -0
  33. package/dist/cjs/lib/requestUtils.d.ts +68 -0
  34. package/dist/cjs/lib/requestUtils.js +82 -0
  35. package/dist/cjs/lib/requestUtils.js.map +1 -0
  36. package/dist/cjs/lib/webCryptoAPI.d.ts +15 -0
  37. package/dist/cjs/lib/webCryptoAPI.js +85 -0
  38. package/dist/cjs/lib/webCryptoAPI.js.map +1 -0
  39. package/dist/cjs/lib/websocket/WsStore.d.ts +75 -0
  40. package/dist/cjs/lib/websocket/WsStore.js +303 -0
  41. package/dist/cjs/lib/websocket/WsStore.js.map +1 -0
  42. package/dist/cjs/lib/websocket/WsStore.types.d.ts +51 -0
  43. package/dist/cjs/lib/websocket/WsStore.types.js +14 -0
  44. package/dist/cjs/lib/websocket/WsStore.types.js.map +1 -0
  45. package/dist/cjs/lib/websocket/logger.d.ts +7 -0
  46. package/dist/cjs/lib/websocket/logger.js +16 -0
  47. package/dist/cjs/lib/websocket/logger.js.map +1 -0
  48. package/dist/cjs/lib/websocket/rest-client-cache.d.ts +22 -0
  49. package/dist/cjs/lib/websocket/rest-client-cache.js +66 -0
  50. package/dist/cjs/lib/websocket/rest-client-cache.js.map +1 -0
  51. package/dist/cjs/lib/websocket/websocket-util.d.ts +76 -0
  52. package/dist/cjs/lib/websocket/websocket-util.js +59 -0
  53. package/dist/cjs/lib/websocket/websocket-util.js.map +1 -0
  54. package/dist/cjs/package.json +3 -0
  55. package/dist/cjs/types/request/derivatives.types.d.ts +186 -0
  56. package/dist/cjs/types/request/derivatives.types.js +6 -0
  57. package/dist/cjs/types/request/derivatives.types.js.map +1 -0
  58. package/dist/cjs/types/request/institutional.types.d.ts +313 -0
  59. package/dist/cjs/types/request/institutional.types.js +4 -0
  60. package/dist/cjs/types/request/institutional.types.js.map +1 -0
  61. package/dist/cjs/types/request/partner.types.d.ts +291 -0
  62. package/dist/cjs/types/request/partner.types.js +4 -0
  63. package/dist/cjs/types/request/partner.types.js.map +1 -0
  64. package/dist/cjs/types/request/spot.types.d.ts +324 -0
  65. package/dist/cjs/types/request/spot.types.js +6 -0
  66. package/dist/cjs/types/request/spot.types.js.map +1 -0
  67. package/dist/cjs/types/request/wsapi.types.d.ts +90 -0
  68. package/dist/cjs/types/request/wsapi.types.js +6 -0
  69. package/dist/cjs/types/request/wsapi.types.js.map +1 -0
  70. package/dist/cjs/types/response/derivatives.types.d.ts +712 -0
  71. package/dist/cjs/types/response/derivatives.types.js +6 -0
  72. package/dist/cjs/types/response/derivatives.types.js.map +1 -0
  73. package/dist/cjs/types/response/institutional.types.d.ts +318 -0
  74. package/dist/cjs/types/response/institutional.types.js +4 -0
  75. package/dist/cjs/types/response/institutional.types.js.map +1 -0
  76. package/dist/cjs/types/response/partner.types.d.ts +332 -0
  77. package/dist/cjs/types/response/partner.types.js +4 -0
  78. package/dist/cjs/types/response/partner.types.js.map +1 -0
  79. package/dist/cjs/types/response/shared.types.d.ts +27 -0
  80. package/dist/cjs/types/response/shared.types.js +3 -0
  81. package/dist/cjs/types/response/shared.types.js.map +1 -0
  82. package/dist/cjs/types/response/spot.types.d.ts +590 -0
  83. package/dist/cjs/types/response/spot.types.js +6 -0
  84. package/dist/cjs/types/response/spot.types.js.map +1 -0
  85. package/dist/cjs/types/response/ws.d.ts +11 -0
  86. package/dist/cjs/types/response/ws.js +3 -0
  87. package/dist/cjs/types/response/ws.js.map +1 -0
  88. package/dist/cjs/types/response/wsapi.types.d.ts +44 -0
  89. package/dist/cjs/types/response/wsapi.types.js +6 -0
  90. package/dist/cjs/types/response/wsapi.types.js.map +1 -0
  91. package/dist/cjs/types/websockets/ws-api.d.ts +71 -0
  92. package/dist/cjs/types/websockets/ws-api.js +18 -0
  93. package/dist/cjs/types/websockets/ws-api.js.map +1 -0
  94. package/dist/cjs/types/websockets/ws-events.d.ts +11 -0
  95. package/dist/cjs/types/websockets/ws-events.js +11 -0
  96. package/dist/cjs/types/websockets/ws-events.js.map +1 -0
  97. package/dist/cjs/types/websockets/ws-general.d.ts +67 -0
  98. package/dist/cjs/types/websockets/ws-general.js +3 -0
  99. package/dist/cjs/types/websockets/ws-general.js.map +1 -0
  100. package/dist/cjs/types/websockets/ws-subscriptions.d.ts +11 -0
  101. package/dist/cjs/types/websockets/ws-subscriptions.js +31 -0
  102. package/dist/cjs/types/websockets/ws-subscriptions.js.map +1 -0
  103. package/dist/mjs/DerivativesClient.d.ts +657 -0
  104. package/dist/mjs/DerivativesClient.js +722 -0
  105. package/dist/mjs/DerivativesClient.js.map +1 -0
  106. package/dist/mjs/InstitutionalClient.d.ts +183 -0
  107. package/dist/mjs/InstitutionalClient.js +262 -0
  108. package/dist/mjs/InstitutionalClient.js.map +1 -0
  109. package/dist/mjs/PartnerClient.d.ts +257 -0
  110. package/dist/mjs/PartnerClient.js +340 -0
  111. package/dist/mjs/PartnerClient.js.map +1 -0
  112. package/dist/mjs/SpotClient.d.ts +547 -0
  113. package/dist/mjs/SpotClient.js +603 -0
  114. package/dist/mjs/SpotClient.js.map +1 -0
  115. package/dist/mjs/WebsocketAPIClient.d.ts +95 -0
  116. package/dist/mjs/WebsocketAPIClient.js +132 -0
  117. package/dist/mjs/WebsocketAPIClient.js.map +1 -0
  118. package/dist/mjs/WebsocketClient.d.ts +120 -0
  119. package/dist/mjs/WebsocketClient.js +665 -0
  120. package/dist/mjs/WebsocketClient.js.map +1 -0
  121. package/dist/mjs/index.d.ts +24 -0
  122. package/dist/mjs/index.js +25 -0
  123. package/dist/mjs/index.js.map +1 -0
  124. package/dist/mjs/lib/BaseRestClient.d.ts +66 -0
  125. package/dist/mjs/lib/BaseRestClient.js +541 -0
  126. package/dist/mjs/lib/BaseRestClient.js.map +1 -0
  127. package/dist/mjs/lib/BaseWSClient.d.ts +230 -0
  128. package/dist/mjs/lib/BaseWSClient.js +928 -0
  129. package/dist/mjs/lib/BaseWSClient.js.map +1 -0
  130. package/dist/mjs/lib/misc-util.d.ts +1 -0
  131. package/dist/mjs/lib/misc-util.js +4 -0
  132. package/dist/mjs/lib/misc-util.js.map +1 -0
  133. package/dist/mjs/lib/requestUtils.d.ts +68 -0
  134. package/dist/mjs/lib/requestUtils.js +76 -0
  135. package/dist/mjs/lib/requestUtils.js.map +1 -0
  136. package/dist/mjs/lib/webCryptoAPI.d.ts +15 -0
  137. package/dist/mjs/lib/webCryptoAPI.js +80 -0
  138. package/dist/mjs/lib/webCryptoAPI.js.map +1 -0
  139. package/dist/mjs/lib/websocket/WsStore.d.ts +75 -0
  140. package/dist/mjs/lib/websocket/WsStore.js +298 -0
  141. package/dist/mjs/lib/websocket/WsStore.js.map +1 -0
  142. package/dist/mjs/lib/websocket/WsStore.types.d.ts +51 -0
  143. package/dist/mjs/lib/websocket/WsStore.types.js +11 -0
  144. package/dist/mjs/lib/websocket/WsStore.types.js.map +1 -0
  145. package/dist/mjs/lib/websocket/logger.d.ts +7 -0
  146. package/dist/mjs/lib/websocket/logger.js +13 -0
  147. package/dist/mjs/lib/websocket/logger.js.map +1 -0
  148. package/dist/mjs/lib/websocket/rest-client-cache.d.ts +22 -0
  149. package/dist/mjs/lib/websocket/rest-client-cache.js +62 -0
  150. package/dist/mjs/lib/websocket/rest-client-cache.js.map +1 -0
  151. package/dist/mjs/lib/websocket/websocket-util.d.ts +76 -0
  152. package/dist/mjs/lib/websocket/websocket-util.js +54 -0
  153. package/dist/mjs/lib/websocket/websocket-util.js.map +1 -0
  154. package/dist/mjs/package.json +3 -0
  155. package/dist/mjs/types/request/derivatives.types.d.ts +186 -0
  156. package/dist/mjs/types/request/derivatives.types.js +5 -0
  157. package/dist/mjs/types/request/derivatives.types.js.map +1 -0
  158. package/dist/mjs/types/request/institutional.types.d.ts +313 -0
  159. package/dist/mjs/types/request/institutional.types.js +3 -0
  160. package/dist/mjs/types/request/institutional.types.js.map +1 -0
  161. package/dist/mjs/types/request/partner.types.d.ts +291 -0
  162. package/dist/mjs/types/request/partner.types.js +3 -0
  163. package/dist/mjs/types/request/partner.types.js.map +1 -0
  164. package/dist/mjs/types/request/spot.types.d.ts +324 -0
  165. package/dist/mjs/types/request/spot.types.js +5 -0
  166. package/dist/mjs/types/request/spot.types.js.map +1 -0
  167. package/dist/mjs/types/request/wsapi.types.d.ts +90 -0
  168. package/dist/mjs/types/request/wsapi.types.js +5 -0
  169. package/dist/mjs/types/request/wsapi.types.js.map +1 -0
  170. package/dist/mjs/types/response/derivatives.types.d.ts +712 -0
  171. package/dist/mjs/types/response/derivatives.types.js +5 -0
  172. package/dist/mjs/types/response/derivatives.types.js.map +1 -0
  173. package/dist/mjs/types/response/institutional.types.d.ts +318 -0
  174. package/dist/mjs/types/response/institutional.types.js +3 -0
  175. package/dist/mjs/types/response/institutional.types.js.map +1 -0
  176. package/dist/mjs/types/response/partner.types.d.ts +332 -0
  177. package/dist/mjs/types/response/partner.types.js +3 -0
  178. package/dist/mjs/types/response/partner.types.js.map +1 -0
  179. package/dist/mjs/types/response/shared.types.d.ts +27 -0
  180. package/dist/mjs/types/response/shared.types.js +2 -0
  181. package/dist/mjs/types/response/shared.types.js.map +1 -0
  182. package/dist/mjs/types/response/spot.types.d.ts +590 -0
  183. package/dist/mjs/types/response/spot.types.js +5 -0
  184. package/dist/mjs/types/response/spot.types.js.map +1 -0
  185. package/dist/mjs/types/response/ws.d.ts +11 -0
  186. package/dist/mjs/types/response/ws.js +2 -0
  187. package/dist/mjs/types/response/ws.js.map +1 -0
  188. package/dist/mjs/types/response/wsapi.types.d.ts +44 -0
  189. package/dist/mjs/types/response/wsapi.types.js +5 -0
  190. package/dist/mjs/types/response/wsapi.types.js.map +1 -0
  191. package/dist/mjs/types/websockets/ws-api.d.ts +71 -0
  192. package/dist/mjs/types/websockets/ws-api.js +15 -0
  193. package/dist/mjs/types/websockets/ws-api.js.map +1 -0
  194. package/dist/mjs/types/websockets/ws-events.d.ts +11 -0
  195. package/dist/mjs/types/websockets/ws-events.js +8 -0
  196. package/dist/mjs/types/websockets/ws-events.js.map +1 -0
  197. package/dist/mjs/types/websockets/ws-general.d.ts +67 -0
  198. package/dist/mjs/types/websockets/ws-general.js +2 -0
  199. package/dist/mjs/types/websockets/ws-general.js.map +1 -0
  200. package/dist/mjs/types/websockets/ws-subscriptions.d.ts +11 -0
  201. package/dist/mjs/types/websockets/ws-subscriptions.js +28 -0
  202. package/dist/mjs/types/websockets/ws-subscriptions.js.map +1 -0
  203. package/llms.txt +10925 -0
  204. package/package.json +89 -0
package/LICENSE.md ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2025 Tiago Siebler
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,624 @@
1
+ # Node.js & JavaScript SDK for Kraken REST APIs & WebSockets
2
+
3
+ [![Build & Test](https://github.com/sieblyio/kraken-api/actions/workflows/e2etest.yml/badge.svg?branch=main)](https://github.com/sieblyio/kraken-api/actions/workflows/e2etest.yml)
4
+ [![npm version](https://img.shields.io/npm/v/@siebly/kraken-api)][1]
5
+ [![npm size](https://img.shields.io/bundlephobia/min/@siebly/kraken-api/latest)][1]
6
+ [![npm downloads](https://img.shields.io/npm/dt/@siebly/kraken-api)][1]
7
+ [![last commit](https://img.shields.io/github/last-commit/sieblyio/kraken-api)][1]
8
+ [![Telegram](https://img.shields.io/badge/chat-on%20telegram-blue.svg)](https://t.me/nodetraders)
9
+
10
+ <p align="center">
11
+ <a href="https://www.npmjs.com/package/@siebly/kraken-api">
12
+ <picture>
13
+ <source media="(prefers-color-scheme: dark)" srcset="https://github.com/sieblyio/kraken-api/blob/main/docs/images/logoDarkMode2.svg?raw=true#gh-dark-mode-only">
14
+ <img alt="SDK Logo" src="https://github.com/sieblyio/kraken-api/blob/main/docs/images/logoBrightMode2.svg?raw=true#gh-light-mode-only">
15
+ </picture>
16
+ </a>
17
+ </p>
18
+
19
+ [1]: https://www.npmjs.com/package/@siebly/kraken-api
20
+
21
+ Complete & robust JavaScript & Node.js SDK for the Kraken REST APIs and WebSockets:
22
+
23
+ - Professional, robust & performant Kraken SDK with extensive production use in live trading environments.
24
+ - Complete integration with all Kraken REST APIs and WebSockets.
25
+ - Dedicated REST clients for Spot, Derivatives (Futures), Institutional, and Partner operations
26
+ - Unified WebSocket client for all markets
27
+ - Complete TypeScript support (with type declarations for most API requests & responses).
28
+ - Strongly typed requests and responses.
29
+ - Automated end-to-end tests ensuring reliability.
30
+ - Actively maintained with a modern, promise-driven interface.
31
+ - Robust WebSocket integration with configurable connection heartbeats & automatic reconnect then resubscribe workflows.
32
+ - Event driven messaging.
33
+ - Smart WebSocket persistence with automatic reconnection handling.
34
+ - Emit `reconnected` event when dropped connection is restored.
35
+ - Support for both public and private WebSocket streams.
36
+ - Browser-friendly HMAC signature mechanism.
37
+ - Automatically supports both ESM and CJS projects.
38
+ - Heavy automated end-to-end testing with real API calls.
39
+ - Proxy support via axios integration.
40
+ - Active community support & collaboration in telegram: [Node.js Algo Traders](https://t.me/nodetraders).
41
+
42
+ ## Table of Contents
43
+
44
+ - [Installation](#installation)
45
+ - [Examples](#examples)
46
+ - [Issues & Discussion](#issues--discussion)
47
+ - [Related Projects](#related-projects)
48
+ - [Documentation](#documentation)
49
+ - [Structure](#structure)
50
+ - [Usage](#usage)
51
+ - [REST API Clients](#rest-api)
52
+ - [Spot Trading](#spot-trading)
53
+ - [Derivatives (Futures) Trading](#derivatives-futures-trading)
54
+ - [WebSockets](#websockets)
55
+ - [Public WebSocket Streams](#public-websocket-streams)
56
+ - [Private WebSocket Streams](#private-websocket-streams)
57
+ - [WebSocket API (WebsocketAPIClient)](#websocket-api-websocketapiclient)
58
+ - [Customise Logging](#customise-logging)
59
+ - [LLMs & AI](#use-with-llms--ai)
60
+ - [Used By](#used-by)
61
+ - [Contributions & Thanks](#contributions--thanks)
62
+
63
+ ## Installation
64
+
65
+ `npm install --save @siebly/kraken-api`
66
+
67
+ ## Examples
68
+
69
+ Refer to the [examples](./examples) folder for implementation demos, including:
70
+
71
+ - **Spot Trading Examples**: market data, account management, order placement
72
+ - **Derivatives Trading Examples**: futures market data, account management, order placement
73
+ - **WebSocket Examples**: public market data streams, private account data
74
+
75
+ ## Issues & Discussion
76
+
77
+ - Issues? Check the [issues tab](https://github.com/sieblyio/kraken-api/issues).
78
+ - Discuss & collaborate with other node devs? Join our [Node.js Algo Traders](https://t.me/nodetraders) engineering community on telegram.
79
+ - Follow our announcement channel for real-time updates on [X/Twitter](https://x.com/sieblyio)
80
+
81
+ <!-- template_related_projects -->
82
+
83
+ ## Related projects
84
+
85
+ Check out my related JavaScript/TypeScript/Node.js projects:
86
+
87
+ - Try my REST API & WebSocket SDKs:
88
+ - [Bybit-api Node.js SDK](https://www.npmjs.com/package/bybit-api)
89
+ - [Okx-api Node.js SDK](https://www.npmjs.com/package/okx-api)
90
+ - [Binance Node.js SDK](https://www.npmjs.com/package/binance)
91
+ - [Gateio-api Node.js SDK](https://www.npmjs.com/package/gateio-api)
92
+ - [Bitget-api Node.js SDK](https://www.npmjs.com/package/bitget-api)
93
+ - [Kucoin-api Node.js SDK](https://www.npmjs.com/package/kucoin-api)
94
+ - [Coinbase-api Node.js SDK](https://www.npmjs.com/package/coinbase-api)
95
+ - [Bitmart-api Node.js SDK](https://www.npmjs.com/package/bitmart-api)
96
+ - Try my misc utilities:
97
+ - [OrderBooks Node.js](https://www.npmjs.com/package/orderbooks)
98
+ - [Crypto Exchange Account State Cache](https://www.npmjs.com/package/accountstate)
99
+ - Check out my examples:
100
+ - [awesome-crypto-examples Node.js](https://github.com/tiagosiebler/awesome-crypto-examples)
101
+ <!-- template_related_projects_end -->
102
+
103
+ ## Documentation
104
+
105
+ Most methods accept JS objects. These can be populated using parameters specified by Kraken's API documentation, or check the type definition in each class within this repository.
106
+
107
+ ### API Documentation Links
108
+
109
+ - [Kraken API Documentation](https://docs.kraken.com/api/)
110
+ - [Spot Trading API](https://docs.kraken.com/api/docs/rest-api/get-server-time)
111
+ - [Futures Trading API](https://docs.futures.kraken.com/)
112
+
113
+ ## Structure
114
+
115
+ This project uses typescript. Resources are stored in 2 key structures:
116
+
117
+ - [src](./src) - the whole connector written in typescript
118
+ - [examples](./examples) - some implementation examples & demonstrations. Contributions are welcome!
119
+
120
+ ---
121
+
122
+ # Usage
123
+
124
+ Create API credentials on Kraken's website:
125
+
126
+ - [Kraken API Key Management](https://www.kraken.com/u/security/api)
127
+ - [Kraken Futures API Key Management](https://futures.kraken.com/settings/api)
128
+
129
+ ## REST API
130
+
131
+ The SDK provides dedicated REST clients for different trading products:
132
+
133
+ - **SpotClient** - for spot trading, staking, and account operations
134
+ - **DerivativesClient** - for futures trading operations
135
+ - **InstitutionalClient** - for institutional trading and custody
136
+ - **PartnerClient** - for partner and affiliate operations
137
+
138
+ ### Spot Trading
139
+
140
+ To use Kraken's Spot APIs, import (or require) the `SpotClient`:
141
+
142
+ ```javascript
143
+ import { SpotClient } from '@siebly/kraken-api';
144
+ // or if you prefer require:
145
+ // const { SpotClient } = require('@siebly/kraken-api');
146
+
147
+ // For public endpoints, API credentials are optional
148
+ const publicClient = new SpotClient();
149
+
150
+ // For private endpoints, provide API credentials
151
+ const client = new SpotClient({
152
+ apiKey: 'your-api-key',
153
+ apiSecret: 'your-base64-encoded-private-key',
154
+ });
155
+
156
+ // Public API Examples
157
+
158
+ // Get ticker information
159
+ const ticker = await publicClient.getTicker({
160
+ pair: 'XBTUSD',
161
+ });
162
+ console.log('Ticker: ', ticker);
163
+
164
+ // Get order book
165
+ const orderBook = await publicClient.getOrderBook({
166
+ pair: 'XBTUSD',
167
+ count: 10,
168
+ });
169
+ console.log('Order Book: ', orderBook);
170
+
171
+ // Private API Examples (requires authentication)
172
+
173
+ // Submit a market order
174
+ client
175
+ .submitOrder({
176
+ ordertype: 'market',
177
+ type: 'buy',
178
+ volume: '0.01',
179
+ pair: 'XBTUSD',
180
+ cl_ord_id: client.generateNewOrderID(),
181
+ })
182
+ .then((result) => {
183
+ console.log('Market Order Result: ', result);
184
+ })
185
+ .catch((err) => {
186
+ console.error('Error: ', err);
187
+ });
188
+
189
+ // Submit a limit order
190
+ client
191
+ .submitOrder({
192
+ ordertype: 'limit',
193
+ type: 'buy',
194
+ volume: '0.0001',
195
+ pair: 'XBTUSD',
196
+ price: '10000',
197
+ cl_ord_id: client.generateNewOrderID(),
198
+ })
199
+ .then((result) => {
200
+ console.log('Limit Order Result: ', result);
201
+ })
202
+ .catch((err) => {
203
+ console.error('Error: ', err);
204
+ });
205
+
206
+ // Submit batch of orders (minimum 2, maximum 15)
207
+ client
208
+ .submitBatchOrders({
209
+ pair: 'XBTUSD',
210
+ orders: [
211
+ {
212
+ ordertype: 'limit',
213
+ type: 'buy',
214
+ volume: '0.0001',
215
+ price: '10000.00',
216
+ timeinforce: 'GTC',
217
+ cl_ord_id: client.generateNewOrderID(),
218
+ },
219
+ {
220
+ ordertype: 'limit',
221
+ type: 'buy',
222
+ volume: '0.0001',
223
+ price: '11111.00',
224
+ timeinforce: 'GTC',
225
+ cl_ord_id: client.generateNewOrderID(),
226
+ },
227
+ {
228
+ ordertype: 'limit',
229
+ type: 'sell',
230
+ volume: '0.0001',
231
+ price: '13000.00',
232
+ timeinforce: 'GTC',
233
+ cl_ord_id: client.generateNewOrderID(),
234
+ },
235
+ ],
236
+ })
237
+ .then((result) => {
238
+ console.log('Batch Order Result: ', JSON.stringify(result, null, 2));
239
+ })
240
+ .catch((err) => {
241
+ console.error('Error: ', err);
242
+ });
243
+
244
+ // Get account balances
245
+ client
246
+ .getAccountBalance()
247
+ .then((balance) => {
248
+ console.log('Account Balance: ', balance);
249
+ })
250
+ .catch((err) => {
251
+ console.error('Error: ', err);
252
+ });
253
+ ```
254
+
255
+ See [SpotClient](./src/SpotClient.ts) for further information, or the [examples](./examples/) for lots of usage examples.
256
+
257
+ ### Derivatives (Futures) Trading
258
+
259
+ Use the `DerivativesClient` for futures trading operations:
260
+
261
+ ```javascript
262
+ import { DerivativesClient } from '@siebly/kraken-api';
263
+ // or if you prefer require:
264
+ // const { DerivativesClient } = require('@siebly/kraken-api');
265
+
266
+ // For public endpoints, API credentials are optional
267
+ const publicClient = new DerivativesClient();
268
+
269
+ // For private endpoints, provide API credentials
270
+ const client = new DerivativesClient({
271
+ apiKey: 'your-api-key',
272
+ apiSecret: 'your-api-secret',
273
+ });
274
+
275
+ // Public API Examples
276
+
277
+ // Get order book for a specific instrument
278
+ const orderBook = await publicClient.getOrderBook({
279
+ symbol: 'PF_XBTUSD',
280
+ });
281
+ console.log('Futures Order Book: ', orderBook);
282
+
283
+ // Get ticker information
284
+ const ticker = await publicClient.getTickers({
285
+ symbol: 'PF_XBTUSD',
286
+ });
287
+ console.log('Futures Ticker: ', ticker);
288
+
289
+ // Private API Examples (requires authentication)
290
+
291
+ // Get account balances
292
+ client
293
+ .getAccountsDetails()
294
+ .then((accounts) => {
295
+ console.log('Accounts Details: ', accounts);
296
+ })
297
+ .catch((err) => {
298
+ console.error('Error: ', err);
299
+ });
300
+
301
+ // Submit a limit order
302
+ client
303
+ .submitOrder({
304
+ orderType: 'lmt',
305
+ symbol: 'PF_ETHUSD', // Perpetual ETH/USD
306
+ side: 'buy',
307
+ size: 0.01, // Contract size
308
+ limitPrice: 1000,
309
+ cliOrdId: client.generateNewOrderID(),
310
+ })
311
+ .then((result) => {
312
+ console.log('Limit Order Result: ', JSON.stringify(result, null, 2));
313
+ })
314
+ .catch((err) => {
315
+ console.error('Error: ', err);
316
+ });
317
+ ```
318
+
319
+ See [DerivativesClient](./src/DerivativesClient.ts) for further information.
320
+
321
+ ## WebSockets
322
+
323
+ Kraken supports two types of WebSocket connections:
324
+
325
+ 1. **WebSocket Subscriptions** - Real-time market data and account updates via the `WebsocketClient`
326
+ 2. **WebSocket API** - REST-like request/response trading via the `WebsocketAPIClient`
327
+
328
+ ### WebSocket Subscriptions (WebsocketClient)
329
+
330
+ The unified `WebsocketClient` handles all Kraken WebSocket streams with automatic connection management and reconnection.
331
+
332
+ Key WebSocket features:
333
+
334
+ - Event driven messaging
335
+ - Smart WebSocket persistence with automatic reconnection
336
+ - Heartbeat mechanisms to detect disconnections
337
+ - Automatic resubscription after reconnection
338
+ - Support for both Spot and Futures markets
339
+ - Support for both public and private WebSocket streams
340
+
341
+ ### Public WebSocket Streams
342
+
343
+ For public market data, API credentials are not required:
344
+
345
+ ```javascript
346
+ import { WebsocketClient } from '@siebly/kraken-api';
347
+ // or if you prefer require:
348
+ // const { WebsocketClient } = require('@siebly/kraken-api');
349
+ // Create WebSocket client for public streams
350
+ const wsClient = new WebsocketClient();
351
+
352
+ // Set up event handlers
353
+ wsClient.on('open', (data) => {
354
+ console.log('WebSocket connected: ', data?.wsKey);
355
+ });
356
+
357
+ wsClient.on('message', (data) => {
358
+ console.log('Data received: ', JSON.stringify(data, null, 2));
359
+ });
360
+
361
+ wsClient.on('reconnected', (data) => {
362
+ console.log('WebSocket reconnected: ', data);
363
+ });
364
+
365
+ wsClient.on('exception', (data) => {
366
+ console.error('WebSocket error: ', data);
367
+ });
368
+
369
+ // Spot - Subscribe to public data streams
370
+ wsClient.subscribe(
371
+ {
372
+ topic: 'ticker',
373
+ payload: {
374
+ symbol: ['BTC/USD', 'ETH/USD'],
375
+ },
376
+ },
377
+ 'spotPublicV2',
378
+ );
379
+
380
+ wsClient.subscribe(
381
+ {
382
+ topic: 'book',
383
+ payload: {
384
+ symbol: ['BTC/USD'],
385
+ depth: 10,
386
+ },
387
+ },
388
+ 'spotPublicV2',
389
+ );
390
+
391
+ // Derivatives - Subscribe to public data streams
392
+ wsClient.subscribe(
393
+ {
394
+ topic: 'ticker',
395
+ payload: {
396
+ product_ids: ['PI_XBTUSD', 'PI_ETHUSD'],
397
+ },
398
+ },
399
+ 'derivativesPublicV1',
400
+ );
401
+
402
+ wsClient.subscribe(
403
+ {
404
+ topic: 'book',
405
+ payload: {
406
+ product_ids: ['PI_XBTUSD'],
407
+ },
408
+ },
409
+ 'derivativesPublicV1',
410
+ );
411
+ ```
412
+
413
+ ### Private WebSocket Streams
414
+
415
+ For private account data streams, API credentials are required:
416
+
417
+ ```javascript
418
+ import { WebsocketClient } from '@siebly/kraken-api';
419
+
420
+ // Create WebSocket client with API credentials for private streams
421
+ const wsClient = new WebsocketClient({
422
+ apiKey: 'your-api-key',
423
+ apiSecret: 'your-api-secret',
424
+ });
425
+
426
+ // Set up event handlers
427
+ wsClient.on('open', (data) => {
428
+ console.log('Private WebSocket connected: ', data?.wsKey);
429
+ });
430
+
431
+ wsClient.on('message', (data) => {
432
+ console.log('Private data received: ', JSON.stringify(data, null, 2));
433
+ });
434
+
435
+ wsClient.on('authenticated', (data) => {
436
+ console.log('WebSocket authenticated: ', data);
437
+ });
438
+
439
+ wsClient.on('response', (data) => {
440
+ console.log('WebSocket response: ', data);
441
+ });
442
+
443
+ wsClient.on('exception', (data) => {
444
+ console.error('WebSocket error: ', data);
445
+ });
446
+
447
+ // Spot - Subscribe to private data streams
448
+ wsClient.subscribe(
449
+ {
450
+ topic: 'executions',
451
+ payload: {
452
+ snap_trades: true,
453
+ snap_orders: true,
454
+ order_status: true,
455
+ },
456
+ },
457
+ 'spotPrivateV2',
458
+ );
459
+
460
+ wsClient.subscribe(
461
+ {
462
+ topic: 'balances',
463
+ payload: {
464
+ snapshot: true,
465
+ },
466
+ },
467
+ 'spotPrivateV2',
468
+ );
469
+
470
+ // Derivatives - Subscribe to private data streams
471
+ // Note: SDK automatically handles authentication and challenge tokens
472
+ wsClient.subscribe('open_orders', 'derivativesPrivateV1');
473
+
474
+ wsClient.subscribe(
475
+ {
476
+ topic: 'fills',
477
+ payload: {
478
+ product_ids: ['PF_XBTUSD'],
479
+ },
480
+ },
481
+ 'derivativesPrivateV1',
482
+ );
483
+
484
+ wsClient.subscribe('balances', 'derivativesPrivateV1');
485
+
486
+ wsClient.subscribe('open_positions', 'derivativesPrivateV1');
487
+ ```
488
+
489
+ For more comprehensive examples, including custom logging and error handling, check the [examples](./examples/WebSockets) folder.
490
+
491
+ ### WebSocket API (WebsocketAPIClient)
492
+
493
+ The `WebsocketAPIClient` provides a REST-like interface for trading operations over WebSocket, offering lower latency than REST APIs. Currently, only Spot trading is supported.
494
+
495
+ ```javascript
496
+ import { WebsocketAPIClient } from '@siebly/kraken-api';
497
+
498
+ // Create WebSocket API client with credentials
499
+ const wsApiClient = new WebsocketAPIClient({
500
+ apiKey: 'your-api-key',
501
+ apiSecret: 'your-api-secret',
502
+ });
503
+
504
+ // The client handles event listeners automatically, but you can customize them
505
+ wsApiClient
506
+ .getWSClient()
507
+ .on('open', (data) => {
508
+ console.log('WebSocket API connected:', data.wsKey);
509
+ })
510
+ .on('response', (data) => {
511
+ console.log('Response:', data);
512
+ })
513
+ .on('exception', (data) => {
514
+ console.error('Error:', data);
515
+ });
516
+
517
+ // Trading operations return promises
518
+
519
+ // Submit a spot order
520
+ const orderResponse = await wsApiClient.submitSpotOrder({
521
+ order_type: 'limit',
522
+ side: 'buy',
523
+ limit_price: 26500.4,
524
+ order_qty: 1.2,
525
+ symbol: 'BTC/USD',
526
+ });
527
+ console.log('Order placed:', orderResponse);
528
+
529
+ // Amend an existing order
530
+ const amendResponse = await wsApiClient.amendSpotOrder({
531
+ order_id: 'OAIYAU-LGI3M-PFM5VW',
532
+ order_qty: 1.5,
533
+ limit_price: 27000,
534
+ });
535
+
536
+ // Cancel specific orders
537
+ const cancelResponse = await wsApiClient.cancelSpotOrder({
538
+ order_id: ['OM5CRX-N2HAL-GFGWE9', 'OLUMT4-UTEGU-ZYM7E9'],
539
+ });
540
+
541
+ // Cancel all open orders
542
+ const cancelAllResponse = await wsApiClient.cancelAllSpotOrders();
543
+ ```
544
+
545
+ The WebSocket API provides several advantages:
546
+
547
+ - **Lower Latency** - Faster than REST API for high-frequency trading
548
+ - **Connection Reuse** - Single persistent connection for multiple requests
549
+ - **Better Performance** - Batch operations for submitting/canceling multiple orders
550
+ - **Type Safety** - Full TypeScript support with typed requests and responses
551
+
552
+ See the [WebSocket API examples](./examples/WebSockets/Spot/wsAPI.ts) for more detailed usage.
553
+
554
+ ---
555
+
556
+ ## Customise Logging
557
+
558
+ Pass a custom logger which supports the log methods `trace`, `info` and `error`, or override methods from the default logger as desired.
559
+
560
+ ```javascript
561
+ import { WebsocketClient, DefaultLogger } from '@siebly/kraken-api';
562
+
563
+ // E.g. customise logging for only the trace level:
564
+ const customLogger: DefaultLogger = {
565
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
566
+ trace: (...params: LogParams): void => {
567
+ // console.log('trace', ...params);
568
+ },
569
+ info: (...params: LogParams): void => {
570
+ console.log('info', ...params);
571
+ },
572
+ error: (...params: LogParams): void => {
573
+ console.error('error', ...params);
574
+ },
575
+ };
576
+
577
+ const ws = new WebsocketClient(
578
+ {
579
+ apiKey: 'apiKeyHere',
580
+ apiSecret: 'apiSecretHere',
581
+ },
582
+ customLogger,
583
+ );
584
+ ```
585
+
586
+ ## Use with LLMs & AI
587
+
588
+ This SDK includes a bundled `llms.txt` file in the root of the repository. If you're developing with LLMs, use the included `llms.txt` with your LLM - it will significantly improve the LLMs understanding of how to correctly use this SDK.
589
+
590
+ This file contains AI optimised structure of all the functions in this package, and their parameters for easier use with any learning models or artificial intelligence.
591
+
592
+ ---
593
+
594
+ ## Used By
595
+
596
+ [![Repository Users Preview Image](https://dependents.info/sieblyio/kraken-api/image)](https://github.com/sieblyio/kraken-api/network/dependents)
597
+
598
+ ---
599
+
600
+ <!-- template_contributions -->
601
+
602
+ ### Contributions & Thanks
603
+
604
+ Have my projects helped you? Share the love, there are many ways you can show your thanks:
605
+
606
+ - Star & share my projects.
607
+ - Are my projects useful? Sponsor me on Github and support my effort to maintain & improve them: https://github.com/sponsors/tiagosiebler
608
+ - Have an interesting project? Get in touch & invite me to it.
609
+ - Or buy me all the coffee:
610
+ - ETH(ERC20): `0xA3Bda8BecaB4DCdA539Dc16F9C54a592553Be06C` <!-- metamask -->
611
+
612
+ <!-- template_contributions_end -->
613
+
614
+ ### Contributions & Pull Requests
615
+
616
+ Contributions are encouraged, I will review any incoming pull requests. See the issues tab for todo items.
617
+
618
+ <!-- template_star_history -->
619
+
620
+ ## Star History
621
+
622
+ [![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/coinbase-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/coinbase-api&tiagosiebler/orderbooks&tiagosiebler/accountstate&tiagosiebler/awesome-crypto-examples&Date)
623
+
624
+ <!-- template_star_history_end -->