-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathasyncapi.yaml
More file actions
485 lines (460 loc) · 16.9 KB
/
asyncapi.yaml
File metadata and controls
485 lines (460 loc) · 16.9 KB
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
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
asyncapi: 2.6.0
info:
title: WebSocket API платформы Crypto Auction
version: 2.0.0
description: |
Real-time WebSocket события для платформы крипто-аукционов.
Возможности:
- Обновления ставок с изменениями лидерборда
- Уведомления о продлении anti-sniping
- Алерты об изменении баланса
- Уведомления о перебитии ставки
- Переходы статуса раунда
- Turbo Mode для ставок с минимальной латентностью
Производительность: 30,000+ сообщений/секунда с латентностью <5ms.
servers:
development:
url: ws://localhost:4005/ws
protocol: ws
description: Локальный сервер разработки
production:
url: wss://api.crypto-auction.example.com/ws
protocol: wss
description: Продакшен WebSocket сервер
defaultContentType: application/json
channels:
# ============ Каналы аукциона ============
auction/{auctionId}/bids:
description: Обновления ставок в реальном времени для конкретного аукциона
parameters:
auctionId:
description: MongoDB ObjectId аукциона
schema:
type: string
format: objectid
subscribe:
operationId: onBidUpdate
summary: Получение уведомлений о размещении ставок
message:
$ref: '#/components/messages/BidPlaced'
auction/{auctionId}/leaderboard:
description: Топ-N участников с обновлением рейтинга в реальном времени
parameters:
auctionId:
description: Идентификатор аукциона
schema:
type: string
subscribe:
operationId: onLeaderboardUpdate
summary: Получение изменений лидерборда
message:
$ref: '#/components/messages/LeaderboardUpdate'
auction/{auctionId}/anti-sniping:
description: Уведомления о продлении anti-sniping
parameters:
auctionId:
description: Идентификатор аукциона
schema:
type: string
subscribe:
operationId: onAntiSnipingExtension
summary: Получение уведомлений о продлении раунда при срабатывании anti-sniping
message:
$ref: '#/components/messages/AntiSnipingExtension'
auction/{auctionId}/round-status:
description: События изменения статуса раунда
parameters:
auctionId:
description: Идентификатор аукциона
schema:
type: string
subscribe:
operationId: onRoundStatusChange
summary: Получение уведомлений при изменении статуса раунда (scheduled → live → closed)
message:
$ref: '#/components/messages/RoundStatusChange'
# ============ Пользовательские каналы ============
user/{userId}/balance:
description: Уведомления об изменении баланса пользователя
parameters:
userId:
description: Идентификатор пользователя
schema:
type: string
subscribe:
operationId: onBalanceUpdate
summary: Получение уведомлений об изменении баланса (депозиты, холды, списания, освобождения)
message:
$ref: '#/components/messages/BalanceUpdate'
user/{userId}/outbid:
description: Алерты о перебитии, когда пользователь теряет топовую позицию
parameters:
userId:
description: Идентификатор пользователя
schema:
type: string
subscribe:
operationId: onOutbid
summary: Получение алертов при перебитии другим пользователем
message:
$ref: '#/components/messages/OutbidAlert'
user/{userId}/notifications:
description: Общие уведомления пользователя
parameters:
userId:
description: Идентификатор пользователя
schema:
type: string
subscribe:
operationId: onUserNotification
summary: Получение общих уведомлений (результаты раунда, победы и т.д.)
message:
$ref: '#/components/messages/UserNotification'
# ============ Каналы ставок (Turbo Mode) ============
turbo/bid:
description: Прямой путь ставок через WebSocket для минимальной латентности
publish:
operationId: placeTurboBid
summary: Размещение ставки через WebSocket (минуя HTTP для снижения латентности)
message:
$ref: '#/components/messages/TurboBidRequest'
subscribe:
operationId: onTurboBidResult
summary: Получение результата ставки
message:
$ref: '#/components/messages/TurboBidResponse'
components:
messages:
BidPlaced:
name: BidPlaced
title: Событие размещения ставки
summary: Генерируется при размещении новой ставки на аукционе
contentType: application/json
payload:
type: object
required:
- type
- auctionId
- userId
- amount
- rank
- timestamp
properties:
type:
type: string
const: bid_placed
description: Тип события
auctionId:
type: string
format: objectid
description: Идентификатор аукциона
userId:
type: string
description: Пользователь, разместивший ставку
amount:
type: number
format: double
description: Сумма ставки
maxAmount:
type: number
format: double
description: Максимальная сумма авто-ставки (при прокси-ставках)
rank:
type: integer
minimum: 1
description: Текущая позиция в лидерборде
roundIndex:
type: integer
description: Индекс раунда, в котором размещена ставка
timestamp:
type: string
format: date-time
description: Временная метка ISO 8601
LeaderboardUpdate:
name: LeaderboardUpdate
title: Событие обновления лидерборда
summary: Генерируется при изменении лидерборда
payload:
type: object
required:
- type
- auctionId
- roundIndex
- topBids
properties:
type:
type: string
const: leaderboard_update
description: Тип события
auctionId:
type: string
description: Идентификатор аукциона
roundIndex:
type: integer
description: Индекс раунда
topBids:
type: array
description: Массив топовых ставок
items:
type: object
properties:
rank:
type: integer
description: Позиция в рейтинге
userId:
type: string
description: Идентификатор пользователя
amount:
type: number
description: Сумма ставки
isCurrentUser:
type: boolean
description: Является ли текущим пользователем
AntiSnipingExtension:
name: AntiSnipingExtension
title: Событие продления Anti-Sniping
summary: Генерируется при продлении раунда из-за ставки в последний момент
payload:
type: object
required:
- type
- auctionId
- roundIndex
- previousEndAt
- newEndAt
- extensionCount
- maxExtensions
properties:
type:
type: string
const: anti_sniping_extension
description: Тип события
auctionId:
type: string
description: Идентификатор аукциона
roundIndex:
type: integer
description: Индекс раунда
previousEndAt:
type: string
format: date-time
description: Предыдущее время окончания до продления
newEndAt:
type: string
format: date-time
description: Новое время окончания после продления
extensionCount:
type: integer
description: Количество применённых продлений
maxExtensions:
type: integer
description: Максимально допустимое количество продлений
RoundStatusChange:
name: RoundStatusChange
title: Событие изменения статуса раунда
summary: Генерируется при переходе раунда между состояниями
payload:
type: object
required:
- type
- auctionId
- roundIndex
- previousStatus
- newStatus
properties:
type:
type: string
const: round_status_change
description: Тип события
auctionId:
type: string
description: Идентификатор аукциона
roundIndex:
type: integer
description: Индекс раунда
previousStatus:
type: string
enum: [scheduled, live, closed]
description: Предыдущий статус
newStatus:
type: string
enum: [scheduled, live, closed]
description: Новый статус
effectiveEndAt:
type: string
format: date-time
description: Эффективное время окончания
BalanceUpdate:
name: BalanceUpdate
title: Событие обновления баланса
summary: Генерируется при изменении баланса пользователя
payload:
type: object
required:
- type
- userId
- currency
- available
- held
- current
properties:
type:
type: string
const: balance_update
description: Тип события
userId:
type: string
description: Идентификатор пользователя
currency:
type: string
description: Валюта
available:
type: number
description: Доступный баланс
held:
type: number
description: Заблокировано для отложенных операций
current:
type: number
description: Общий баланс (available + held)
changeType:
type: string
enum: [deposit, hold, capture, release, withdrawal]
description: Тип изменения
changeAmount:
type: number
description: Сумма изменения
OutbidAlert:
name: OutbidAlert
title: Событие алерта о перебитии
summary: Генерируется при перебитии пользователя
payload:
type: object
required:
- type
- auctionId
- roundIndex
- yourBid
- newTopBid
- yourRank
- winnersCount
properties:
type:
type: string
const: outbid
description: Тип события
auctionId:
type: string
description: Идентификатор аукциона
roundIndex:
type: integer
description: Индекс раунда
yourBid:
type: number
description: Ваша текущая сумма ставки
newTopBid:
type: number
description: Новая топовая ставка, которая вас перебила
yourRank:
type: integer
description: Ваша новая позиция в лидерборде
winnersCount:
type: integer
description: Количество победителей для этого раунда
UserNotification:
name: UserNotification
title: Событие уведомления пользователя
summary: События общих уведомлений
payload:
type: object
required:
- type
- notificationType
- message
properties:
type:
type: string
const: notification
description: Тип события
notificationType:
type: string
enum: [round_win, round_loss, deposit_confirmed, withdrawal_completed]
description: Тип уведомления
message:
type: string
description: Текст сообщения
data:
type: object
additionalProperties: true
description: Дополнительные данные
TurboBidRequest:
name: TurboBidRequest
title: Запрос Turbo ставки
summary: Размещение ставки через WebSocket для минимальной латентности
payload:
type: object
required:
- type
- requestId
- auctionId
- amount
- idempotencyKey
properties:
type:
type: string
const: place_bid
description: Тип запроса
requestId:
type: string
format: uuid
description: Клиентский ID запроса для корреляции
auctionId:
type: string
description: Идентификатор аукциона
amount:
type: number
description: Сумма ставки
idempotencyKey:
type: string
description: Уникальный ключ для идемпотентного retry
TurboBidResponse:
name: TurboBidResponse
title: Ответ Turbo ставки
summary: Результат запроса turbo ставки
payload:
type: object
required:
- type
- requestId
- success
- latencyMs
properties:
type:
type: string
const: bid_result
description: Тип ответа
requestId:
type: string
format: uuid
description: ID запроса для корреляции
success:
type: boolean
description: Успешность операции
bidId:
type: string
description: ID созданной ставки (при успехе)
rank:
type: integer
description: Позиция в лидерборде (при успехе)
amount:
type: number
description: Сумма ставки (при успехе)
error:
type: string
description: Код ошибки (при неудаче)
duplicate:
type: boolean
description: True если это идемпотентный дубликат
latencyMs:
type: number
description: Время обработки на сервере в миллисекундах