-
-
Notifications
You must be signed in to change notification settings - Fork 280
/
kraken-websocket-request-reply-multiple-channels-asyncapi.yml
394 lines (375 loc) · 12.3 KB
/
kraken-websocket-request-reply-multiple-channels-asyncapi.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
asyncapi: 3.0.0
info:
title: Kraken Websockets API
version: '1.8.0'
description: |
WebSockets API offers real-time market data updates. WebSockets is a bidirectional protocol offering fastest real-time data, helping you build real-time applications. The public message types presented below do not require authentication. Private-data messages can be subscribed on a separate authenticated endpoint.
### General Considerations
- TLS with SNI (Server Name Indication) is required in order to establish a Kraken WebSockets API connection. See Cloudflare's [What is SNI?](https://www.cloudflare.com/learning/ssl/what-is-sni/) guide for more details.
- All messages sent and received via WebSockets are encoded in JSON format
- All decimal fields (including timestamps) are quoted to preserve precision.
- Timestamps should not be considered unique and not be considered as aliases for transaction IDs. Also, the granularity of timestamps is not representative of transaction rates.
- At least one private message should be subscribed to keep the authenticated client connection open.
- Please use REST API endpoint [AssetPairs](https://www.kraken.com/features/api#get-tradable-pairs) to fetch the list of pairs which can be subscribed via WebSockets API. For example, field 'wsname' gives the supported pairs name which can be used to subscribe.
- Cloudflare imposes a connection/re-connection rate limit (per IP address) of approximately 150 attempts per rolling 10 minutes. If this is exceeded, the IP is banned for 10 minutes.
- Recommended reconnection behaviour is to (1) attempt reconnection instantly up to a handful of times if the websocket is dropped randomly during normal operation but (2) after maintenance or extended downtime, attempt to reconnect no more quickly than once every 5 seconds. There is no advantage to reconnecting more rapidly after maintenance during cancel_only mode.
channels:
ping:
address: /
messages:
ping:
$ref: '#/components/messages/ping'
pong:
address: /
messages:
pong:
$ref: '#/components/messages/pong'
heartbeat:
address: /
messages:
heartbeat:
$ref: '#/components/messages/heartbeat'
systemStatus:
address: /
messages:
systemStatus:
$ref: '#/components/messages/systemStatus'
currencyInfo:
address: /
messages:
subscriptionStatus:
$ref: '#/components/messages/subscriptionStatus'
dummyCurrencyInfo:
$ref: '#/components/messages/dummyCurrencyInfo'
subscribe:
address: /
messages:
subscribe:
$ref: '#/components/messages/subscribe'
unsubscribe:
address: /
messages:
unsubscribe:
$ref: '#/components/messages/unsubscribe'
operations:
receivePing:
action: receive
channel:
$ref: '#/channels/ping'
reply:
channel:
$ref: '#/channels/pong'
heartbeat:
action: send
channel:
$ref: '#/channels/heartbeat'
systemStatus:
action: send
channel:
$ref: '#/channels/systemStatus'
subscribe:
action: receive
channel:
$ref: '#/channels/subscribe'
reply:
channel:
$ref: '#/channels/currencyInfo'
unsubscribe:
action: receive
channel:
$ref: '#/channels/unsubscribe'
reply:
channel:
$ref: '#/channels/currencyInfo'
messages:
- $ref: '#/channels/currencyInfo/messages/subscriptionStatus'
components:
messages:
dummyCurrencyInfo:
summary: Dummy message with no real life details
description: It is here in this example to showcase that there is an additional message that normally is of a complex structure. It represents actually currency exchange value to show a reply to operation receiveSubscribeRequest with more than one possible message.
payload:
type: object
properties:
event:
type: string
const: currencyInfo
reqid:
$ref: '#/components/schemas/reqid'
data:
type: object
required:
- event
correlationId:
location: '$message.payload#/reqid'
ping:
summary: Ping server to determine whether connection is alive
description: Client can ping server to determine whether connection is alive, server responds with pong. This is an application level ping as opposed to default ping in websockets standard which is server initiated
payload:
$ref: '#/components/schemas/ping'
correlationId:
location: $message.payload#/reqid
pong:
summary: Pong is a response to ping message
description: Server pong response to a ping to determine whether connection is alive. This is an application level pong as opposed to default pong in websockets standard which is sent by client in response to a ping
payload:
$ref: '#/components/schemas/pong'
correlationId:
location: $message.payload#/reqid
subscribe:
description: Subscribe to a topic on a single or multiple currency pairs.
payload:
$ref: '#/components/schemas/subscribe'
correlationId:
location: $message.payload#/reqid
unsubscribe:
description: Unsubscribe, can specify a channelID or multiple currency pairs.
payload:
$ref: '#/components/schemas/unsubscribe'
correlationId:
location: $message.payload#/reqid
subscriptionStatus:
description: Subscription status response to subscribe, unsubscribe or exchange initiated unsubscribe.
payload:
$ref: '#/components/schemas/subscriptionStatus'
examples:
- payload:
channelID: 10001
channelName: ohlc-5
event: subscriptionStatus
pair: XBT/EUR
reqid: 42
status: unsubscribed
subscription:
interval: 5
name: ohlc
- payload:
errorMessage: Subscription depth not supported
event: subscriptionStatus
pair: XBT/USD
status: error
subscription:
depth: 42
name: book
systemStatus:
description: Status sent on connection or system status changes.
payload:
$ref: '#/components/schemas/systemStatus'
heartbeat:
description: Server heartbeat sent if no subscription traffic within 1 second (approximately)
payload:
$ref: '#/components/schemas/heartbeat'
schemas:
ping:
type: object
properties:
event:
type: string
const: ping
reqid:
$ref: '#/components/schemas/reqid'
required:
- event
heartbeat:
type: object
properties:
event:
type: string
const: heartbeat
pong:
type: object
properties:
event:
type: string
const: pong
reqid:
$ref: '#/components/schemas/reqid'
systemStatus:
type: object
properties:
event:
type: string
const: systemStatus
connectionID:
type: integer
description: The ID of the connection
status:
$ref: '#/components/schemas/status'
version:
type: string
status:
type: string
enum:
- online
- maintenance
- cancel_only
- limit_only
- post_only
subscribe:
type: object
properties:
event:
type: string
const: subscribe
reqid:
$ref: '#/components/schemas/reqid'
pair:
$ref: '#/components/schemas/pair'
subscription:
type: object
properties:
depth:
$ref: '#/components/schemas/depth'
interval:
$ref: '#/components/schemas/interval'
name:
$ref: '#/components/schemas/name'
ratecounter:
$ref: '#/components/schemas/ratecounter'
snapshot:
$ref: '#/components/schemas/snapshot'
token:
$ref: '#/components/schemas/token'
required:
- name
required:
- event
unsubscribe:
type: object
properties:
event:
type: string
const: unsubscribe
reqid:
$ref: '#/components/schemas/reqid'
pair:
$ref: '#/components/schemas/pair'
subscription:
type: object
properties:
depth:
$ref: '#/components/schemas/depth'
interval:
$ref: '#/components/schemas/interval'
name:
$ref: '#/components/schemas/name'
token:
$ref: '#/components/schemas/token'
required:
- name
required:
- event
subscriptionStatus:
type: object
oneOf:
- $ref: '#/components/schemas/subscriptionStatusError'
- $ref: '#/components/schemas/subscriptionStatusSuccess'
subscriptionStatusError:
allOf:
- properties:
errorMessage:
type: string
required:
- errorMessage
- $ref: '#/components/schemas/subscriptionStatusCommon'
subscriptionStatusSuccess:
allOf:
- properties:
channelID:
type: integer
description: ChannelID on successful subscription, applicable to public messages only.
channelName:
type: string
description: Channel Name on successful subscription. For payloads 'ohlc' and 'book', respective interval or depth will be added as suffix.
required:
- channelID
- channelName
- $ref: '#/components/schemas/subscriptionStatusCommon'
subscriptionStatusCommon:
type: object
required:
- event
properties:
event:
type: string
const: subscriptionStatus
reqid:
$ref: '#/components/schemas/reqid'
pair:
$ref: '#/components/schemas/pair'
status:
$ref: '#/components/schemas/status'
subscription:
required:
- name
type: object
properties:
depth:
$ref: '#/components/schemas/depth'
interval:
$ref: '#/components/schemas/interval'
maxratecount:
$ref: '#/components/schemas/maxratecount'
name:
$ref: '#/components/schemas/name'
token:
$ref: '#/components/schemas/token'
interval:
type: integer
description: Time interval associated with ohlc subscription in minutes.
default: 1
enum:
- 1
- 5
- 15
- 30
- 60
- 240
- 1440
- 10080
- 21600
name:
type: string
description: The name of the channel you subscribe too.
enum:
- book
- ohlc
- openOrders
- ownTrades
- spread
- ticker
- trade
token:
type: string
description: base64-encoded authentication token for private-data endpoints.
depth:
type: integer
default: 10
enum:
- 10
- 25
- 100
- 500
- 1000
description: Depth associated with book subscription in number of levels each side.
maxratecount:
type: integer
description: Max rate-limit budget. Compare to the ratecounter field in the openOrders updates to check whether you are approaching the rate limit.
ratecounter:
type: boolean
default: false
description: Whether to send rate-limit counter in updates (supported only for openOrders subscriptions)
snapshot:
type: boolean
default: true
description: Whether to send historical feed data snapshot upon subscription (supported only for ownTrades subscriptions)
reqid:
type: integer
description: client originated ID reflected in response message.
pair:
type: array
description: Array of currency pairs.
items:
type: string
description: Format of each pair is "A/B", where A and B are ISO 4217-A3 for standardized assets and popular unique symbol if not standardized.
pattern: '[A-Z\s]+\/[A-Z\s]+'