-
Notifications
You must be signed in to change notification settings - Fork 17
/
enum.go
493 lines (432 loc) · 10.3 KB
/
enum.go
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
486
487
488
489
490
491
492
493
package uof
import (
"fmt"
"hash/fnv"
"strconv"
"strings"
)
type Producer int8
const (
ProducerUnknown Producer = 0
ProducerLiveOdds Producer = 1
ProducerPrematch Producer = 3
)
var producers = []struct {
id Producer
name string
description string
code string
scope string
recoveryWindow int // in minutes
}{
{id: 1, name: "LO", description: "Live Odds", code: "liveodds", scope: "live", recoveryWindow: 4320},
{id: 3, name: "Ctrl", description: "Betradar Ctrl", code: "pre", scope: "prematch", recoveryWindow: 4320},
{id: 4, name: "BetPal", description: "BetPal", code: "betpal", scope: "live", recoveryWindow: 4320},
{id: 5, name: "PremiumCricket", description: "Premium Cricket", code: "premium_cricket", scope: "live|prematch", recoveryWindow: 4320},
{id: 6, name: "VF", description: "Virtual football", code: "vf", scope: "virtual", recoveryWindow: 180},
{id: 7, name: "WNS", description: "Numbers Betting", code: "wns", scope: "prematch", recoveryWindow: 4320},
{id: 8, name: "VBL", description: "Virtual Basketball League", code: "vbl", scope: "virtual", recoveryWindow: 180},
{id: 9, name: "VTO", description: "Virtual Tennis Open", code: "vto", scope: "virtual", recoveryWindow: 180},
{id: 10, name: "VDR", description: "Virtual Dog Racing", code: "vdr", scope: "virtual", recoveryWindow: 180},
{id: 11, name: "VHC", description: "Virtual Horse Classics", code: "vhc", scope: "virtual", recoveryWindow: 180},
{id: 12, name: "VTI", description: "Virtual Tennis In-Play", code: "vti", scope: "virtual", recoveryWindow: 180},
{id: 15, name: "VBI", description: "Virtual Baseball In-Play", code: "vbi", scope: "virtual", recoveryWindow: 180},
}
func (p Producer) String() string {
return p.Code()
}
func (p Producer) Name() string {
for _, d := range producers {
if p == d.id {
return d.name
}
}
return InvalidName
}
func (p Producer) Description() string {
for _, d := range producers {
if p == d.id {
return d.description
}
}
return InvalidName
}
func (p Producer) Code() string {
for _, d := range producers {
if p == d.id {
return d.code
}
}
return InvalidName
}
// RecoveryWindow in milliseconds
func (p Producer) RecoveryWindow() int {
for _, d := range producers {
if p == d.id {
return d.recoveryWindow * 60 * 1000
}
}
return 0
}
// Prematch means that producer markets are valid only for betting before the
// match starts.
func (p Producer) Prematch() bool {
return p == 3
}
const (
InvalidName = "?"
srMatch = "sr:match:"
srPlayer = "sr:player:"
)
type URN string
func (u URN) ID() int {
if u == "" {
return 0
}
p := strings.Split(string(u), ":")
if len(p) != 3 {
return 0
}
i, _ := strconv.ParseUint(p[2], 10, 64)
return int(i)
}
/*
const (
URNTypeMatch int8 = iota
URNTypeStage
URNTypeTournament
URNTypeSimpleTournament
URNTypeSeason
URNTypeDraw
URNTypeLottery
URNTypePlayer
URNTypeUnknown = int8(-1)
)
func (u URN) Type() int8 {
if u == "" {
return URNTypeUnknown
}
p := strings.Split(string(u), ":")
if len(p) != 3 {
return URNTypeUnknown
}
switch p[1] {
case "match":
return URNTypeMatch
case "stage":
return URNTypeStage
case "tournament":
return URNTypeTournament
case "simple_tournament":
return URNTypeSimpleTournament
case "season":
return URNTypeSeason
case "draw":
return URNTypeDraw
case "lottery":
return URNTypeLottery
case "player":
return URNTypePlayer
}
return URNTypeUnknown
}
*/
func (u URN) Empty() bool {
return string(u) == ""
}
func NewEventURN(eventID int) URN {
return URN(fmt.Sprintf("%s%d", srMatch, eventID))
}
func (u URN) String() string {
return string(u)
}
func (u *URN) Parse(s string) {
r := URN(s)
if id, err := strconv.Atoi(s); err == nil {
r = NewEventURN(id)
}
*u = r
}
const NoURN = URN("")
// EventID tries to generate unique id for all types of events. Most comon are
// those with prefix sr:match for them we reserve positive id-s. All others got
// range in negative ids.
// Reference: https://docs.betradar.com/display/BD/MG+-+Entities
// http://sdk.sportradar.com/content/unifiedfeedsdk/net/doc/html/e1f73019-73cd-c9f8-0d58-7fe25800abf2.htm
// List of currently existing event types is taken from the combo box in the
// integration control page. From method "Fixture for a specified sport event".
//nolint:gocyclo //accepting complexity of 23
func (u URN) EventID() int {
id, prefix := u.split()
if id == 0 {
return 0
}
suffixID := func(suffix int8) int {
return -(id<<8 | int(suffix))
}
switch prefix {
case "sr:match":
return id
case "sr:stage":
return suffixID(1)
case "sr:season":
return suffixID(2)
case "sr:tournament":
return suffixID(3)
case "sr:simple_tournament":
return suffixID(4)
case "test:match":
return suffixID(15)
case "vf:match":
return suffixID(16)
case "vf:season":
return suffixID(17)
case "vf:tournament":
return suffixID(18)
case "vbl:match":
return suffixID(19)
case "vbl:season":
return suffixID(20)
case "vbl:tournament":
return suffixID(21)
case "vto:match":
return suffixID(22)
case "vto:season":
return suffixID(23)
case "vto:tournament":
return suffixID(24)
case "vdr:stage":
return suffixID(25)
case "vhc:stage":
return suffixID(26)
case "vti:match":
return suffixID(27)
case "vti:tournament":
return suffixID(28)
case "wns:draw":
return suffixID(29)
default:
return 0
}
}
// splits urn into id and prefix
func (u URN) split() (int, string) {
if u == "" {
return 0, ""
}
p := strings.Split(string(u), ":")
if len(p) != 3 {
return 0, ""
}
i, err := strconv.ParseUint(p[2], 10, 64)
if err != nil {
return 0, ""
}
id := int(i)
prefix := p[0] + ":" + p[1]
return id, prefix
}
func toLineID(specifiers string) int {
if specifiers == "" {
return 0
}
return hash32(specifiers)
}
func hash32(s string) int {
h := fnv.New32a()
_, _ = h.Write([]byte(s))
return int(h.Sum32())
}
func Hash(s string) int {
return hash32(s)
}
type EventReporting int8
const (
EventReportingNotAvailable EventReporting = 0
EventReportingActive EventReporting = 1
EventReportingSuspended EventReporting = -1
)
// Values must match the pattern [0-9]+:[0-9]+|[0-9]+
type ClockTime string
func (c *ClockTime) Minute() string {
p := strings.Split(string(*c), ":")
if len(p) > 0 {
return p[0]
}
return ""
}
func (c *ClockTime) String() string {
return string(*c)
}
func (c *ClockTime) PtrVal() *string {
if c == nil {
return nil
}
v := string(*c)
return &v
}
// The change_type attribute (if present), describes what type of change that
// caused the message to be sent. In general, best practices are to always
// re-fetch the updated fixture from the API and not solely rely on the
// change_type and the message content. This is because multiple different
// changes could have been made.
// May be one of 1, 2, 3, 4, 5
type FixtureChangeType int8
const (
// This is a new match/event that has been just added.
FixtureChangeTypeNew FixtureChangeType = 1
// Start-time update
FixtureChangeTypeTime FixtureChangeType = 2
// This sport event will not take place. It has been cancelled.
FixtureChangeTypeCancelled FixtureChangeType = 3
// The format of the sport-event has been updated (e.g. the number of sets to
// play has been updated or the length of the match etc.)
FixtureChangeTypeFromat FixtureChangeType = 4
// Coverage update. Sent for example when liveodds coverage for some reason
// cannot be offered for a match.
FixtureChangeTypeCoverage FixtureChangeType = 5
)
type MessageType int8
const (
MessageTypeUnknown MessageType = -1
)
// event related message types
const (
MessageTypeOddsChange MessageType = iota
MessageTypeFixtureChange
MessageTypeBetCancel
MessageTypeBetSettlement
MessageTypeBetStop
MessageTypeRollbackBetSettlement
MessageTypeRollbackBetCancel
)
// api message types
const (
MessageTypeFixture MessageType = iota + 32
MessageTypeMarkets
MessageTypePlayer
)
// system message types
const (
MessageTypeAlive MessageType = iota + 64
MessageTypeSnapshotComplete
MessageTypeConnection
MessageTypeProducersChange
)
var messageTypes = []MessageType{
MessageTypeUnknown,
MessageTypeOddsChange,
MessageTypeFixtureChange,
MessageTypeBetCancel,
MessageTypeBetSettlement,
MessageTypeBetStop,
MessageTypeRollbackBetSettlement,
MessageTypeRollbackBetCancel,
MessageTypeFixture,
MessageTypeMarkets,
MessageTypePlayer,
MessageTypeAlive,
MessageTypeSnapshotComplete,
MessageTypeConnection,
MessageTypeProducersChange,
}
var messageTypeNames = []string{
InvalidName,
"odds_change",
"fixture_change",
"bet_cancel",
"bet_settlement",
"bet_stop",
"rollback_bet_settlement",
"rollback_bet_cancel",
"fixture",
"market",
"player",
"alive",
"snapshot_complete",
"connection",
"producer_change",
}
func (m *MessageType) Parse(name string) {
v := MessageTypeUnknown
for i, n := range messageTypeNames {
if n == name {
v = messageTypes[i]
break
}
}
*m = v
}
func (m MessageType) String() string {
for i, t := range messageTypes {
if t == m {
return messageTypeNames[i]
}
}
return InvalidName
}
func (m MessageType) Kind() MessageKind {
if m < 32 {
return MessageKindEvent
}
if m < 64 {
return MessageKindLexicon
}
return MessageKindSystem
}
type MessageKind int8
const (
MessageKindEvent MessageKind = iota
MessageKindLexicon
MessageKindSystem
)
type MessageScope int8
// Scope of the message
const (
MessageScopePrematch MessageScope = iota
MessageScopeLive
MessageScopePrematchAndLive
MessageScopeVirtuals
MessageScopeSystem // system scope messages, like alive, product down
)
func (s *MessageScope) Parse(prematchInterest, liveInterest string) {
v := func() MessageScope {
if prematchInterest == "pre" {
if liveInterest == "live" {
return MessageScopePrematchAndLive
}
return MessageScopePrematch
}
if prematchInterest == "virt" {
return MessageScopeVirtuals
}
if liveInterest == "live" {
return MessageScopeLive
}
return MessageScopeSystem
}()
*s = v
}
type MessagePriority int8
const (
MessagePriorityLow MessagePriority = iota
MessagePriorityHigh
)
func (p *MessagePriority) Parse(priority string) {
v := func() MessagePriority {
switch priority {
case "hi":
return MessagePriorityHigh
default:
return MessagePriorityLow
}
}()
*p = v
}
type Environment int8
const (
Production Environment = iota
Staging
Replay
ProductionGlobal
)