overtime-live-trading-utils 2.1.35 → 2.1.37-rc.0
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.
- package/.circleci/config.yml +32 -32
- package/.prettierrc +9 -9
- package/codecov.yml +20 -20
- package/index.ts +26 -26
- package/jest.config.ts +16 -16
- package/main.js +1 -1
- package/package.json +30 -30
- package/src/constants/common.ts +8 -7
- package/src/constants/errors.ts +7 -6
- package/src/constants/sports.ts +78 -78
- package/src/enums/sports.ts +109 -109
- package/src/tests/mock/MockLeagueMap.ts +200 -170
- package/src/tests/mock/MockOpticOddsEvents.ts +662 -662
- package/src/tests/mock/MockOpticSoccer.ts +9864 -9378
- package/src/tests/mock/MockSoccerRedis.ts +2308 -2308
- package/src/tests/unit/bookmakers.test.ts +148 -79
- package/src/tests/unit/markets.test.ts +176 -156
- package/src/tests/unit/odds.test.ts +103 -92
- package/src/tests/unit/resolution.test.ts +1488 -1393
- package/src/tests/unit/sports.test.ts +58 -58
- package/src/tests/unit/spread.test.ts +144 -131
- package/src/tests/utils/helper.ts +10 -0
- package/src/types/bookmakers.ts +7 -0
- package/src/types/missing-types.d.ts +2 -2
- package/src/types/odds.ts +80 -61
- package/src/types/resolution.ts +96 -96
- package/src/types/sports.ts +22 -19
- package/src/utils/bookmakers.ts +315 -159
- package/src/utils/constraints.ts +210 -210
- package/src/utils/gameMatching.ts +81 -81
- package/src/utils/markets.ts +119 -119
- package/src/utils/odds.ts +947 -918
- package/src/utils/opticOdds.ts +71 -71
- package/src/utils/resolution.ts +319 -319
- package/src/utils/sportPeriodMapping.ts +36 -36
- package/src/utils/sports.ts +51 -51
- package/src/utils/spread.ts +97 -97
- package/tsconfig.json +17 -13
- package/webpack.config.js +24 -24
- package/CLAUDE.md +0 -84
- package/resolution_live_markets.md +0 -356
package/src/utils/odds.ts
CHANGED
|
@@ -1,918 +1,947 @@
|
|
|
1
|
-
import * as oddslib from 'oddslib';
|
|
2
|
-
import { MarketType, MarketTypeMap } from 'overtime-utils';
|
|
3
|
-
import { DRAW, MIN_ODDS_FOR_DIFF_CHECKING, MONEYLINE_TYPE_ID, ZERO } from '../constants/common';
|
|
4
|
-
import { NO_MARKETS_FOR_LEAGUE_ID } from '../constants/errors';
|
|
5
|
-
import { MoneylineTypes } from '../enums/sports';
|
|
6
|
-
import { HomeAwayTeams, Odds, OddsObject } from '../types/odds';
|
|
7
|
-
import { ChildMarket, LeagueConfigInfo } from '../types/sports';
|
|
8
|
-
import {
|
|
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
|
-
liveOddsProviders
|
|
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
|
-
if (
|
|
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
|
-
* @param {
|
|
116
|
-
* @param {
|
|
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
|
-
const
|
|
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
|
-
const
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
if (
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
)
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
otherFormattedOdds
|
|
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
|
-
acc
|
|
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
|
-
acc
|
|
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
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
};
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
[
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
[`${homeTeamKey}
|
|
611
|
-
[`${homeTeamKey}
|
|
612
|
-
[`${homeTeamKey}
|
|
613
|
-
[`${homeTeamKey}
|
|
614
|
-
[`${homeTeamKey}
|
|
615
|
-
[`${homeTeamKey}
|
|
616
|
-
[`${homeTeamKey}
|
|
617
|
-
[`${homeTeamKey}
|
|
618
|
-
[`${homeTeamKey}
|
|
619
|
-
[`${
|
|
620
|
-
[`${
|
|
621
|
-
[`${
|
|
622
|
-
[`${
|
|
623
|
-
[`${
|
|
624
|
-
[`${
|
|
625
|
-
[`${
|
|
626
|
-
[`${
|
|
627
|
-
[`${
|
|
628
|
-
[`${
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
[`${homeTeamKey}
|
|
640
|
-
[`${homeTeamKey}
|
|
641
|
-
[`${homeTeamKey}
|
|
642
|
-
[`${homeTeamKey}
|
|
643
|
-
[`${homeTeamKey}
|
|
644
|
-
[`${homeTeamKey}
|
|
645
|
-
[`${homeTeamKey}
|
|
646
|
-
[`${homeTeamKey}
|
|
647
|
-
[`${homeTeamKey}
|
|
648
|
-
[`${homeTeamKey}
|
|
649
|
-
[`${homeTeamKey}
|
|
650
|
-
[`${homeTeamKey}
|
|
651
|
-
[`${homeTeamKey}
|
|
652
|
-
[`${homeTeamKey}
|
|
653
|
-
[`${homeTeamKey}
|
|
654
|
-
[`${homeTeamKey}
|
|
655
|
-
[`${homeTeamKey}
|
|
656
|
-
[`${homeTeamKey}
|
|
657
|
-
[`${homeTeamKey}
|
|
658
|
-
[`${homeTeamKey}
|
|
659
|
-
[`${homeTeamKey}
|
|
660
|
-
[`${homeTeamKey}
|
|
661
|
-
[`${homeTeamKey}
|
|
662
|
-
[`${homeTeamKey}
|
|
663
|
-
[`${homeTeamKey}
|
|
664
|
-
[`${homeTeamKey}
|
|
665
|
-
[`${homeTeamKey}
|
|
666
|
-
[`${homeTeamKey}
|
|
667
|
-
[`${homeTeamKey}
|
|
668
|
-
[`${homeTeamKey}
|
|
669
|
-
[`${homeTeamKey}
|
|
670
|
-
[`${homeTeamKey}
|
|
671
|
-
[`${homeTeamKey}
|
|
672
|
-
[`${homeTeamKey}
|
|
673
|
-
[`${homeTeamKey}
|
|
674
|
-
[`${homeTeamKey}
|
|
675
|
-
[`${homeTeamKey}
|
|
676
|
-
[`${homeTeamKey}
|
|
677
|
-
[`${homeTeamKey}
|
|
678
|
-
[`${homeTeamKey}
|
|
679
|
-
[`${homeTeamKey}
|
|
680
|
-
[`${homeTeamKey}
|
|
681
|
-
[`${homeTeamKey}
|
|
682
|
-
[`${homeTeamKey}
|
|
683
|
-
[`${homeTeamKey}
|
|
684
|
-
[`${homeTeamKey}
|
|
685
|
-
[`${homeTeamKey}
|
|
686
|
-
[`${homeTeamKey}
|
|
687
|
-
[`${homeTeamKey}
|
|
688
|
-
[`${homeTeamKey}
|
|
689
|
-
[`${homeTeamKey}
|
|
690
|
-
[`${homeTeamKey}
|
|
691
|
-
[`${homeTeamKey}
|
|
692
|
-
[`${homeTeamKey}
|
|
693
|
-
[`${homeTeamKey}
|
|
694
|
-
[`${homeTeamKey}
|
|
695
|
-
[`${homeTeamKey}
|
|
696
|
-
[`${homeTeamKey}
|
|
697
|
-
[`${homeTeamKey}
|
|
698
|
-
[`${homeTeamKey}
|
|
699
|
-
[`${homeTeamKey}
|
|
700
|
-
[`${homeTeamKey}
|
|
701
|
-
[`${homeTeamKey}
|
|
702
|
-
[`${homeTeamKey}
|
|
703
|
-
[`${homeTeamKey}
|
|
704
|
-
[`${homeTeamKey}
|
|
705
|
-
[`${
|
|
706
|
-
[`${
|
|
707
|
-
[`${
|
|
708
|
-
[`${
|
|
709
|
-
[`${
|
|
710
|
-
[`${
|
|
711
|
-
[`${
|
|
712
|
-
[`${
|
|
713
|
-
[`${
|
|
714
|
-
[`${
|
|
715
|
-
[`${
|
|
716
|
-
[`${
|
|
717
|
-
[`${
|
|
718
|
-
[`${
|
|
719
|
-
[`${
|
|
720
|
-
[`${
|
|
721
|
-
[`${
|
|
722
|
-
[`${
|
|
723
|
-
[`${
|
|
724
|
-
[`${
|
|
725
|
-
[`${
|
|
726
|
-
[`${
|
|
727
|
-
[`${
|
|
728
|
-
[`${
|
|
729
|
-
[`${
|
|
730
|
-
[`${
|
|
731
|
-
[`${
|
|
732
|
-
[`${
|
|
733
|
-
[`${
|
|
734
|
-
[`${awayTeamKey}
|
|
735
|
-
[`${awayTeamKey}
|
|
736
|
-
[`${awayTeamKey}
|
|
737
|
-
[`${awayTeamKey}
|
|
738
|
-
[`${awayTeamKey}
|
|
739
|
-
[`${awayTeamKey}
|
|
740
|
-
[`${awayTeamKey}
|
|
741
|
-
[`${awayTeamKey}
|
|
742
|
-
[`${awayTeamKey}
|
|
743
|
-
[`${awayTeamKey}
|
|
744
|
-
[`${awayTeamKey}
|
|
745
|
-
[`${awayTeamKey}
|
|
746
|
-
[`${awayTeamKey}
|
|
747
|
-
[`${awayTeamKey}
|
|
748
|
-
[`${awayTeamKey}
|
|
749
|
-
[`${awayTeamKey}
|
|
750
|
-
[`${awayTeamKey}
|
|
751
|
-
[`${awayTeamKey}
|
|
752
|
-
[`${awayTeamKey}
|
|
753
|
-
[`${awayTeamKey}
|
|
754
|
-
[`${awayTeamKey}
|
|
755
|
-
[`${awayTeamKey}
|
|
756
|
-
[`${awayTeamKey}
|
|
757
|
-
[`${awayTeamKey}
|
|
758
|
-
[`${awayTeamKey}
|
|
759
|
-
[`${awayTeamKey}
|
|
760
|
-
[`${awayTeamKey}
|
|
761
|
-
[`${awayTeamKey}
|
|
762
|
-
[`${awayTeamKey}
|
|
763
|
-
[`${awayTeamKey}
|
|
764
|
-
[`${awayTeamKey}
|
|
765
|
-
[`${awayTeamKey}
|
|
766
|
-
[`${awayTeamKey}
|
|
767
|
-
[`${awayTeamKey}
|
|
768
|
-
[`${awayTeamKey}
|
|
769
|
-
[`${awayTeamKey}
|
|
770
|
-
[`${awayTeamKey}
|
|
771
|
-
[`${awayTeamKey}
|
|
772
|
-
[`${awayTeamKey}
|
|
773
|
-
[`${awayTeamKey}
|
|
774
|
-
[`${awayTeamKey}
|
|
775
|
-
[`${awayTeamKey}
|
|
776
|
-
[`${awayTeamKey}
|
|
777
|
-
[`${awayTeamKey}
|
|
778
|
-
[`${awayTeamKey}
|
|
779
|
-
[`${awayTeamKey}
|
|
780
|
-
[`${awayTeamKey}
|
|
781
|
-
[`${awayTeamKey}
|
|
782
|
-
[`${awayTeamKey}
|
|
783
|
-
[`${awayTeamKey}
|
|
784
|
-
[`${awayTeamKey}
|
|
785
|
-
[`${awayTeamKey}
|
|
786
|
-
[`${awayTeamKey}
|
|
787
|
-
[`${awayTeamKey}
|
|
788
|
-
[`${awayTeamKey}
|
|
789
|
-
[`${awayTeamKey}
|
|
790
|
-
[`${awayTeamKey}
|
|
791
|
-
[`${awayTeamKey}
|
|
792
|
-
[`${awayTeamKey}
|
|
793
|
-
[`${awayTeamKey}
|
|
794
|
-
[`${awayTeamKey}
|
|
795
|
-
[`${awayTeamKey}
|
|
796
|
-
[`${awayTeamKey}
|
|
797
|
-
[`${awayTeamKey}
|
|
798
|
-
[`${awayTeamKey}
|
|
799
|
-
[`${awayTeamKey}
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
}
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
}
|
|
829
|
-
|
|
830
|
-
}
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
}
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
}
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
1
|
+
import * as oddslib from 'oddslib';
|
|
2
|
+
import { MarketType, MarketTypeMap } from 'overtime-utils';
|
|
3
|
+
import { DRAW, MIN_ODDS_FOR_DIFF_CHECKING, MONEYLINE_TYPE_ID, ZERO } from '../constants/common';
|
|
4
|
+
import { LAST_POLLED_TOO_OLD, NO_MARKETS_FOR_LEAGUE_ID } from '../constants/errors';
|
|
5
|
+
import { MoneylineTypes } from '../enums/sports';
|
|
6
|
+
import { HomeAwayTeams, Odds, OddsObject } from '../types/odds';
|
|
7
|
+
import { ChildMarket, LastPolledArray, LeagueConfigInfo } from '../types/sports';
|
|
8
|
+
import {
|
|
9
|
+
checkOddsFromBookmakers,
|
|
10
|
+
checkOddsFromBookmakersForChildMarkets,
|
|
11
|
+
getPrimaryAndSecondaryBookmakerForTypeId,
|
|
12
|
+
isLastPolledForBookmakersValid,
|
|
13
|
+
} from './bookmakers';
|
|
14
|
+
import { getLeagueInfo } from './sports';
|
|
15
|
+
import { adjustSpreadOnOdds, getSpreadData } from './spread';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Converts a given odds value from one format to another.
|
|
19
|
+
* Specifically, it converts from 'moneyline' to 'impliedProbability', handling special cases.
|
|
20
|
+
*
|
|
21
|
+
* @param {Number} odds - The odds value to convert.
|
|
22
|
+
* @returns {Number} The converted odds value.
|
|
23
|
+
*/
|
|
24
|
+
export const convertOddsToImpl = (odds: number): number => {
|
|
25
|
+
return odds === ZERO ? 0 : getOddsFromTo('decimal', 'impliedProbability', odds);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Converts odds from one format to another.
|
|
30
|
+
* @param {String} from - The original odds format.
|
|
31
|
+
* @param {String} to - The target odds format.
|
|
32
|
+
* @param {Number} input - The odds value.
|
|
33
|
+
* @returns {Number} The converted odds.
|
|
34
|
+
*/
|
|
35
|
+
export const getOddsFromTo = (from: string, to: string, input: number): number => {
|
|
36
|
+
try {
|
|
37
|
+
return oddslib.from(from, input).to(to);
|
|
38
|
+
} catch (error) {
|
|
39
|
+
return 0;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Filters the odds array to find entries matching the specified market name and bookmaker.
|
|
45
|
+
*
|
|
46
|
+
* @param {Array} oddsArray - The array of odds objects.
|
|
47
|
+
* @param {string} marketName - The market name to filter by.
|
|
48
|
+
* @param {Array} liveOddsProviders - Odds providers for live odds
|
|
49
|
+
* @param {Object} commonData - The common data object.
|
|
50
|
+
* @param {boolean} isTwoPositionalSport - Indicates if the sport is a two positional sport.,
|
|
51
|
+
* @returns {Map} The filtered map for odds per provider.
|
|
52
|
+
*/
|
|
53
|
+
export const filterOddsByMarketNameTeamNameBookmaker = (
|
|
54
|
+
oddsArray: Odds,
|
|
55
|
+
marketName: MoneylineTypes,
|
|
56
|
+
liveOddsProviders: any[],
|
|
57
|
+
commonData: HomeAwayTeams,
|
|
58
|
+
isTwoPositionalSport: boolean
|
|
59
|
+
) => {
|
|
60
|
+
const linesMap = new Map<any, any>();
|
|
61
|
+
liveOddsProviders.forEach((oddsProvider) => {
|
|
62
|
+
let homeOdds = 0;
|
|
63
|
+
const homeTeamOddsObject = oddsArray.filter((odd) => {
|
|
64
|
+
return (
|
|
65
|
+
odd &&
|
|
66
|
+
odd.marketName.toLowerCase() === marketName.toLowerCase() &&
|
|
67
|
+
odd.sportsBookName.toLowerCase() == oddsProvider.toLowerCase() &&
|
|
68
|
+
odd.selection.toLowerCase() === commonData.homeTeam.toLowerCase()
|
|
69
|
+
);
|
|
70
|
+
});
|
|
71
|
+
if (homeTeamOddsObject.length !== 0) {
|
|
72
|
+
homeOdds = homeTeamOddsObject[0].price;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
let awayOdds = 0;
|
|
76
|
+
const awayTeamOddsObject = oddsArray.filter(
|
|
77
|
+
(odd) =>
|
|
78
|
+
odd &&
|
|
79
|
+
odd.marketName.toLowerCase() === marketName.toLowerCase() &&
|
|
80
|
+
odd.sportsBookName.toLowerCase() == oddsProvider.toLowerCase() &&
|
|
81
|
+
odd.selection.toLowerCase() === commonData.awayTeam.toLowerCase()
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
if (awayTeamOddsObject.length !== 0) {
|
|
85
|
+
awayOdds = awayTeamOddsObject[0].price;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
let drawOdds = 0;
|
|
89
|
+
if (!isTwoPositionalSport) {
|
|
90
|
+
const drawOddsObject = oddsArray.filter(
|
|
91
|
+
(odd) =>
|
|
92
|
+
odd &&
|
|
93
|
+
odd.marketName.toLowerCase() === marketName.toLowerCase() &&
|
|
94
|
+
odd.sportsBookName.toLowerCase() == oddsProvider.toLowerCase() &&
|
|
95
|
+
odd.selection.toLowerCase() === DRAW.toLowerCase()
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
if (drawOddsObject.length !== 0) {
|
|
99
|
+
drawOdds = drawOddsObject[0].price;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
linesMap.set(oddsProvider.toLowerCase(), {
|
|
104
|
+
homeOdds: homeOdds,
|
|
105
|
+
awayOdds: awayOdds,
|
|
106
|
+
drawOdds: drawOdds,
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
return linesMap;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Retrieves the parent odds for the given event.
|
|
114
|
+
*
|
|
115
|
+
* @param {boolean} isTwoPositionalSport - Indicates if the sport is a two positional sport.
|
|
116
|
+
* @param {Array} sportSpreadData - Spread data specific to the sport.
|
|
117
|
+
* @param {Array} liveOddsProviders - Odds providers for live odds
|
|
118
|
+
* @param {Object} oddsApiObject - Odds data from the API.
|
|
119
|
+
* @param {String} sportId - Sport ID API.
|
|
120
|
+
* @param {Number} defaultSpreadForLiveMarkets - Default spread for live markets,
|
|
121
|
+
* @param {Number} maxPercentageDiffBetwenOdds - Maximum allowed percentage difference between same position odds from different providers
|
|
122
|
+
* @returns {Array} The parent odds for the event [homeOdds, awayOdds, drawOdds].
|
|
123
|
+
*/
|
|
124
|
+
export const getParentOdds = (
|
|
125
|
+
isTwoPositionalSport: boolean,
|
|
126
|
+
sportSpreadData: any[],
|
|
127
|
+
liveOddsProviders: any[],
|
|
128
|
+
oddsApiObject: OddsObject,
|
|
129
|
+
sportId: string,
|
|
130
|
+
defaultSpreadForLiveMarkets: number,
|
|
131
|
+
maxPercentageDiffBetwenOdds: number,
|
|
132
|
+
leagueInfo: LeagueConfigInfo[],
|
|
133
|
+
lastPolledMap: LastPolledArray,
|
|
134
|
+
MAX_ALLOWED_PROVIDER_DATA_STALE_DELAY: number
|
|
135
|
+
) => {
|
|
136
|
+
const commonData = { homeTeam: oddsApiObject.homeTeam, awayTeam: oddsApiObject.awayTeam };
|
|
137
|
+
|
|
138
|
+
const { primaryBookmaker, secondaryBookmaker } = getPrimaryAndSecondaryBookmakerForTypeId(
|
|
139
|
+
liveOddsProviders,
|
|
140
|
+
leagueInfo,
|
|
141
|
+
0 // typeId for moneyline
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
const isValidLastPolled = isLastPolledForBookmakersValid(
|
|
145
|
+
lastPolledMap,
|
|
146
|
+
MAX_ALLOWED_PROVIDER_DATA_STALE_DELAY,
|
|
147
|
+
primaryBookmaker,
|
|
148
|
+
secondaryBookmaker
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
if (!isValidLastPolled) {
|
|
152
|
+
return {
|
|
153
|
+
odds: isTwoPositionalSport ? [0, 0] : [0, 0, 0],
|
|
154
|
+
errorMessage: LAST_POLLED_TOO_OLD,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// EXTRACTING ODDS FROM THE RESPONSE PER MARKET NAME AND BOOKMAKER
|
|
159
|
+
const moneylineOddsMap = filterOddsByMarketNameTeamNameBookmaker(
|
|
160
|
+
oddsApiObject.odds,
|
|
161
|
+
MoneylineTypes.MONEYLINE,
|
|
162
|
+
liveOddsProviders,
|
|
163
|
+
commonData,
|
|
164
|
+
isTwoPositionalSport
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
// CHECKING AND COMPARING ODDS FOR THE GIVEN BOOKMAKERS
|
|
168
|
+
const oddsObject = checkOddsFromBookmakers(
|
|
169
|
+
moneylineOddsMap,
|
|
170
|
+
liveOddsProviders,
|
|
171
|
+
isTwoPositionalSport,
|
|
172
|
+
maxPercentageDiffBetwenOdds,
|
|
173
|
+
MIN_ODDS_FOR_DIFF_CHECKING
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
if (oddsObject.errorMessage) {
|
|
177
|
+
return {
|
|
178
|
+
odds: isTwoPositionalSport ? [0, 0] : [0, 0, 0],
|
|
179
|
+
errorMessage: oddsObject.errorMessage,
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
const primaryBookmakerOdds = isTwoPositionalSport
|
|
183
|
+
? [oddsObject.homeOdds, oddsObject.awayOdds]
|
|
184
|
+
: [oddsObject.homeOdds, oddsObject.awayOdds, oddsObject.drawOdds];
|
|
185
|
+
|
|
186
|
+
let parentOdds = primaryBookmakerOdds.map((odd) => convertOddsToImpl(odd));
|
|
187
|
+
const spreadData = getSpreadData(sportSpreadData, sportId, MONEYLINE_TYPE_ID, defaultSpreadForLiveMarkets);
|
|
188
|
+
|
|
189
|
+
if (spreadData !== null) {
|
|
190
|
+
parentOdds = adjustSpreadOnOdds(parentOdds, spreadData.minSpread, spreadData.targetSpread);
|
|
191
|
+
} else {
|
|
192
|
+
// Use min spread by sport if available, otherwise use default min spread
|
|
193
|
+
parentOdds = adjustSpreadOnOdds(parentOdds, defaultSpreadForLiveMarkets, 0);
|
|
194
|
+
}
|
|
195
|
+
return { odds: parentOdds };
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Creates child markets based on the given parameters.
|
|
200
|
+
*
|
|
201
|
+
* @param {Object} leagueId - leagueId AKA sportId
|
|
202
|
+
* @param {Array} spreadDataForSport - Spread data for sport.
|
|
203
|
+
* @param {Object} apiResponseWithOdds - API response from the provider
|
|
204
|
+
* @param {Array} liveOddsProviders - Odds providers for live odds
|
|
205
|
+
* @param {Number} defaultSpreadForLiveMarkets - Default spread for live markets
|
|
206
|
+
* @param {Boolean} leagueMap - League Map info
|
|
207
|
+
* @returns {Array} The child markets.
|
|
208
|
+
*/
|
|
209
|
+
export const createChildMarkets: (
|
|
210
|
+
apiResponseWithOdds: OddsObject,
|
|
211
|
+
spreadDataForSport: any,
|
|
212
|
+
leagueId: number,
|
|
213
|
+
liveOddsProviders: any,
|
|
214
|
+
defaultSpreadForLiveMarkets: any,
|
|
215
|
+
leagueMap: any,
|
|
216
|
+
lastPolledMap: LastPolledArray,
|
|
217
|
+
MAX_ALLOWED_PROVIDER_DATA_STALE_DELAY: number
|
|
218
|
+
) => ChildMarket[] = (
|
|
219
|
+
apiResponseWithOdds,
|
|
220
|
+
spreadDataForSport,
|
|
221
|
+
leagueId,
|
|
222
|
+
liveOddsProviders,
|
|
223
|
+
defaultSpreadForLiveMarkets,
|
|
224
|
+
leagueMap,
|
|
225
|
+
lastPolledMap,
|
|
226
|
+
MAX_ALLOWED_PROVIDER_DATA_STALE_DELAY
|
|
227
|
+
) => {
|
|
228
|
+
const [spreadOdds, totalOdds, moneylineOdds, correctScoreOdds, doubleChanceOdds, ggOdds, childMarkets]: any[] = [
|
|
229
|
+
[],
|
|
230
|
+
[],
|
|
231
|
+
[],
|
|
232
|
+
[],
|
|
233
|
+
[],
|
|
234
|
+
[],
|
|
235
|
+
[],
|
|
236
|
+
];
|
|
237
|
+
const leagueInfo = getLeagueInfo(leagueId, leagueMap);
|
|
238
|
+
const commonData = {
|
|
239
|
+
homeTeam: apiResponseWithOdds.homeTeam,
|
|
240
|
+
awayTeam: apiResponseWithOdds.awayTeam,
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
if (leagueInfo.length > 0) {
|
|
244
|
+
const allChildOdds = filterOddsByMarketNameBookmaker(apiResponseWithOdds.odds, leagueInfo);
|
|
245
|
+
const checkedChildOdds = checkOddsFromBookmakersForChildMarkets(
|
|
246
|
+
allChildOdds,
|
|
247
|
+
leagueInfo,
|
|
248
|
+
liveOddsProviders,
|
|
249
|
+
lastPolledMap,
|
|
250
|
+
MAX_ALLOWED_PROVIDER_DATA_STALE_DELAY
|
|
251
|
+
);
|
|
252
|
+
checkedChildOdds.forEach((odd) => {
|
|
253
|
+
if (odd.type === 'Total') {
|
|
254
|
+
if (Math.abs(Number(odd.points) % 1) === 0.5) totalOdds.push(odd);
|
|
255
|
+
} else if (odd.type === 'Spread') {
|
|
256
|
+
if (Math.abs(Number(odd.points) % 1) === 0.5) spreadOdds.push(odd);
|
|
257
|
+
} else if (odd.type === 'Moneyline') {
|
|
258
|
+
moneylineOdds.push(odd);
|
|
259
|
+
} else if (odd.type === 'Correct Score') {
|
|
260
|
+
correctScoreOdds.push(odd);
|
|
261
|
+
} else if (odd.type === 'Double Chance') {
|
|
262
|
+
doubleChanceOdds.push(odd);
|
|
263
|
+
} else if (odd.type === 'Both Teams To Score') {
|
|
264
|
+
ggOdds.push(odd);
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
const homeAwayFormattedOdds = [
|
|
269
|
+
...groupAndFormatSpreadOdds(spreadOdds, commonData),
|
|
270
|
+
...groupAndFormatTotalOdds(totalOdds, commonData),
|
|
271
|
+
...groupAndFormatMoneylineOdds(moneylineOdds, commonData),
|
|
272
|
+
...groupAndFormatGGOdds(ggOdds),
|
|
273
|
+
...groupAndFormatDoubleChanceOdds(doubleChanceOdds, commonData),
|
|
274
|
+
];
|
|
275
|
+
const otherFormattedOdds = [...groupAndFormatCorrectScoreOdds(correctScoreOdds, commonData)];
|
|
276
|
+
|
|
277
|
+
const homeAwayOddsWithSpreadAdjusted = adjustSpreadOnChildOdds(
|
|
278
|
+
homeAwayFormattedOdds,
|
|
279
|
+
spreadDataForSport,
|
|
280
|
+
defaultSpreadForLiveMarkets
|
|
281
|
+
);
|
|
282
|
+
|
|
283
|
+
homeAwayOddsWithSpreadAdjusted.forEach((data) => {
|
|
284
|
+
const childMarket = {
|
|
285
|
+
leagueId: Number(data.sportId),
|
|
286
|
+
typeId: Number(data.typeId),
|
|
287
|
+
type: MarketTypeMap[data.typeId as MarketType]?.key || '',
|
|
288
|
+
line: Number(data.line || 0),
|
|
289
|
+
odds: data.odds,
|
|
290
|
+
};
|
|
291
|
+
const leagueInfoByTypeId = leagueInfo.find((league) => Number(league.typeId) === Number(data.typeId));
|
|
292
|
+
const minOdds = leagueInfoByTypeId?.minOdds;
|
|
293
|
+
const maxOdds = leagueInfoByTypeId?.maxOdds;
|
|
294
|
+
if (
|
|
295
|
+
!(
|
|
296
|
+
minOdds &&
|
|
297
|
+
maxOdds &&
|
|
298
|
+
(data.odds[0] >= minOdds ||
|
|
299
|
+
data.odds[0] <= maxOdds ||
|
|
300
|
+
data.odds[1] >= minOdds ||
|
|
301
|
+
data.odds[1] <= maxOdds)
|
|
302
|
+
)
|
|
303
|
+
) {
|
|
304
|
+
childMarkets.push(childMarket);
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
otherFormattedOdds.forEach((data) => {
|
|
309
|
+
const leagueInfoByTypeId = leagueInfo.find((league) => Number(league.typeId) === Number(data.typeId));
|
|
310
|
+
const minOdds = leagueInfoByTypeId?.minOdds;
|
|
311
|
+
const maxOdds = leagueInfoByTypeId?.maxOdds;
|
|
312
|
+
|
|
313
|
+
const childMarket = {
|
|
314
|
+
leagueId: Number(data.sportId),
|
|
315
|
+
typeId: Number(data.typeId),
|
|
316
|
+
type: MarketTypeMap[data.typeId as MarketType]?.key || '',
|
|
317
|
+
line: Number(data.line || 0),
|
|
318
|
+
odds: data.odds.map((odd: any) => {
|
|
319
|
+
const impliedOdds = convertOddsToImpl(odd) || ZERO;
|
|
320
|
+
return !minOdds || !maxOdds || impliedOdds >= minOdds || impliedOdds <= maxOdds ? 0 : impliedOdds;
|
|
321
|
+
}),
|
|
322
|
+
positionNames: data.positionNames,
|
|
323
|
+
};
|
|
324
|
+
childMarkets.push(childMarket);
|
|
325
|
+
});
|
|
326
|
+
} else {
|
|
327
|
+
console.warn(`${NO_MARKETS_FOR_LEAGUE_ID}: ${Number(leagueId)}`);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
return childMarkets;
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* Filters the odds array to find entries matching the specified market name.
|
|
335
|
+
*
|
|
336
|
+
* @param {Array} oddsArray - The array of odds objects.
|
|
337
|
+
* @param {string} leagueInfos - The market names to filter by.
|
|
338
|
+
* @param {string} oddsProvider - The main odds provider to filter by.
|
|
339
|
+
* @returns {Array} The filtered odds array.
|
|
340
|
+
*/
|
|
341
|
+
export const filterOddsByMarketNameBookmaker = (oddsArray: Odds, leagueInfos: LeagueConfigInfo[]): any => {
|
|
342
|
+
const allChildMarketsTypes = leagueInfos
|
|
343
|
+
.filter(
|
|
344
|
+
(leagueInfo) =>
|
|
345
|
+
leagueInfo.marketName.toLowerCase() !== MoneylineTypes.MONEYLINE.toLowerCase() &&
|
|
346
|
+
leagueInfo.enabled === 'true'
|
|
347
|
+
)
|
|
348
|
+
.map((leagueInfo) => leagueInfo.marketName.toLowerCase());
|
|
349
|
+
return oddsArray.reduce((acc: any, odd: any) => {
|
|
350
|
+
if (allChildMarketsTypes.includes(odd.marketName.toLowerCase())) {
|
|
351
|
+
const { points, marketName, selection, selectionLine, sportsBookName } = odd;
|
|
352
|
+
const key = `${sportsBookName.toLowerCase()}_${marketName.toLowerCase()}_${points}_${selection}_${selectionLine}`;
|
|
353
|
+
acc[key] = {
|
|
354
|
+
...odd,
|
|
355
|
+
...leagueInfos.find(
|
|
356
|
+
(leagueInfo) => leagueInfo.marketName.toLowerCase() === odd.marketName.toLowerCase()
|
|
357
|
+
), // using .find() for team totals means that we will always assign 10017 as typeID at this point
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
return acc;
|
|
362
|
+
}, {}) as any;
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Groups spread odds by their lines and formats the result.
|
|
367
|
+
*
|
|
368
|
+
* @param {Array} oddsArray - The input array of odds objects.
|
|
369
|
+
* @param {Object} commonData - The common data object containing homeTeam information.
|
|
370
|
+
* @returns {Array} The grouped and formatted spread odds.
|
|
371
|
+
*/
|
|
372
|
+
export const groupAndFormatSpreadOdds = (oddsArray: any[], commonData: HomeAwayTeams) => {
|
|
373
|
+
// Group odds by their selection points and selection
|
|
374
|
+
const groupedOdds = oddsArray.reduce((acc: any, odd: any) => {
|
|
375
|
+
const { points, marketName, price, selection, typeId, sportId, type } = odd;
|
|
376
|
+
const isHomeTeam = selection === commonData.homeTeam;
|
|
377
|
+
|
|
378
|
+
const key = `${marketName}_${isHomeTeam ? points : -points}`;
|
|
379
|
+
|
|
380
|
+
if (!acc[key]) {
|
|
381
|
+
acc[key] = { home: null, away: null, typeId: null, sportId: null };
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
if (isHomeTeam) {
|
|
385
|
+
acc[key].home = price;
|
|
386
|
+
} else {
|
|
387
|
+
acc[key].away = price;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
acc[key].typeId = typeId;
|
|
391
|
+
acc[key].type = type;
|
|
392
|
+
acc[key].sportId = sportId;
|
|
393
|
+
|
|
394
|
+
return acc;
|
|
395
|
+
}, {}) as any;
|
|
396
|
+
// Format the grouped odds into the desired output
|
|
397
|
+
const formattedOdds = Object.entries(groupedOdds as any).reduce((acc: any, [key, value]) => {
|
|
398
|
+
const [_marketName, lineFloat] = key.split('_');
|
|
399
|
+
const line = parseFloat(lineFloat);
|
|
400
|
+
if ((value as any).home !== null && (value as any).away !== null) {
|
|
401
|
+
acc.push({
|
|
402
|
+
line: line as any,
|
|
403
|
+
odds: [(value as any).home, (value as any).away],
|
|
404
|
+
typeId: (value as any).typeId,
|
|
405
|
+
sportId: (value as any).sportId,
|
|
406
|
+
type: (value as any).type,
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
return acc;
|
|
410
|
+
}, []);
|
|
411
|
+
|
|
412
|
+
return formattedOdds;
|
|
413
|
+
};
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* Groups odds by selection and points over/under.
|
|
417
|
+
*
|
|
418
|
+
* @param {Array} oddsArray - The array of odds objects.
|
|
419
|
+
* @returns {Object} The grouped odds.
|
|
420
|
+
*/
|
|
421
|
+
export const groupAndFormatTotalOdds = (oddsArray: any[], commonData: HomeAwayTeams) => {
|
|
422
|
+
// Group odds by their selection points and selection
|
|
423
|
+
const groupedOdds = oddsArray.reduce((acc, odd) => {
|
|
424
|
+
if (odd) {
|
|
425
|
+
const key = `${odd.marketName}_${odd.selection}_${odd.points}`;
|
|
426
|
+
if (!acc[key]) {
|
|
427
|
+
acc[key] = { over: null, under: null };
|
|
428
|
+
}
|
|
429
|
+
if (odd.selectionLine === 'over') {
|
|
430
|
+
acc[key].over = odd.price;
|
|
431
|
+
} else if (odd.selectionLine === 'under') {
|
|
432
|
+
acc[key].under = odd.price;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
acc[key].typeId = odd.typeId;
|
|
436
|
+
acc[key].type = odd.type;
|
|
437
|
+
acc[key].sportId = odd.sportId;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
return acc;
|
|
441
|
+
}, {});
|
|
442
|
+
|
|
443
|
+
// Format the grouped odds into the desired output
|
|
444
|
+
const formattedOdds = Object.entries(groupedOdds as any).reduce((acc: any, [key, value]) => {
|
|
445
|
+
const [_marketName, selection, selectionLine] = key.split('_');
|
|
446
|
+
const line = parseFloat(selectionLine);
|
|
447
|
+
|
|
448
|
+
// if we have away team in total odds we know the market is team total and we need to increase typeId by one.
|
|
449
|
+
// if this is false typeId is already mapped correctly
|
|
450
|
+
const isAwayTeam = selection === commonData.awayTeam;
|
|
451
|
+
if ((value as any).over !== null && (value as any).under !== null) {
|
|
452
|
+
acc.push({
|
|
453
|
+
line: line as any,
|
|
454
|
+
odds: [(value as any).over, (value as any).under],
|
|
455
|
+
typeId: !isAwayTeam ? (value as any).typeId : Number((value as any).typeId) + 1,
|
|
456
|
+
sportId: (value as any).sportId,
|
|
457
|
+
type: (value as any).type,
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
return acc;
|
|
461
|
+
}, []);
|
|
462
|
+
|
|
463
|
+
return formattedOdds;
|
|
464
|
+
};
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* Groups moneyline odds by their lines and formats the result.
|
|
468
|
+
*
|
|
469
|
+
* @param {Array} oddsArray - The input array of odds objects.
|
|
470
|
+
* @param {Object} commonData - The common data object containing homeTeam information.
|
|
471
|
+
* @returns {Array} The grouped and formatted moneyline odds.
|
|
472
|
+
*/
|
|
473
|
+
export const groupAndFormatMoneylineOdds = (oddsArray: any[], commonData: HomeAwayTeams) => {
|
|
474
|
+
// Group odds by their selection points and selection
|
|
475
|
+
const groupedOdds = oddsArray.reduce((acc: any, odd: any) => {
|
|
476
|
+
const { price, selection, typeId, sportId, type } = odd;
|
|
477
|
+
const key = typeId;
|
|
478
|
+
|
|
479
|
+
if (!acc[key]) {
|
|
480
|
+
acc[key] = { home: null, away: null, draw: null, typeId: null, sportId: null };
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
if (selection.toLowerCase() === commonData.homeTeam.toLowerCase()) acc[key].home = price;
|
|
484
|
+
else if (selection.toLowerCase() === commonData.awayTeam.toLowerCase()) acc[key].away = price;
|
|
485
|
+
else if (selection.toLowerCase() === DRAW.toLowerCase()) acc[key].draw = price;
|
|
486
|
+
|
|
487
|
+
acc[key].typeId = typeId;
|
|
488
|
+
acc[key].type = type;
|
|
489
|
+
acc[key].sportId = sportId;
|
|
490
|
+
|
|
491
|
+
return acc;
|
|
492
|
+
}, {}) as any;
|
|
493
|
+
|
|
494
|
+
// Format the grouped odds into the desired output
|
|
495
|
+
const formattedOdds = Object.entries(groupedOdds as any).reduce((acc: any, [_key, value]) => {
|
|
496
|
+
if ((value as any).home !== null && (value as any).away !== null) {
|
|
497
|
+
acc.push({
|
|
498
|
+
odds: (value as any).draw
|
|
499
|
+
? [(value as any).home, (value as any).away, (value as any).draw]
|
|
500
|
+
: [(value as any).home, (value as any).away],
|
|
501
|
+
typeId: (value as any).typeId,
|
|
502
|
+
sportId: (value as any).sportId,
|
|
503
|
+
type: (value as any).type,
|
|
504
|
+
});
|
|
505
|
+
}
|
|
506
|
+
return acc;
|
|
507
|
+
}, []);
|
|
508
|
+
|
|
509
|
+
return formattedOdds;
|
|
510
|
+
};
|
|
511
|
+
|
|
512
|
+
/**w
|
|
513
|
+
* Groups GG (Both Teams to Score) odds by their lines and formats the result.
|
|
514
|
+
*
|
|
515
|
+
* @param {Array} oddsArray - The input array of odds objects.
|
|
516
|
+
* @returns {Array} The grouped and formatted moneyline odds.
|
|
517
|
+
*/
|
|
518
|
+
export const groupAndFormatGGOdds = (oddsArray: any[]) => {
|
|
519
|
+
const groupedOdds = oddsArray.reduce((acc: any, odd: any) => {
|
|
520
|
+
const { price, selection, typeId, sportId, type } = odd;
|
|
521
|
+
const key = typeId;
|
|
522
|
+
|
|
523
|
+
if (!acc[key]) {
|
|
524
|
+
acc[key] = { home: null, away: null, draw: null, typeId: null, sportId: null };
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
if (selection.toLowerCase() === 'yes') acc[key].home = price;
|
|
528
|
+
else if (selection.toLowerCase() === 'no') acc[key].away = price;
|
|
529
|
+
|
|
530
|
+
acc[key].typeId = typeId;
|
|
531
|
+
acc[key].type = type;
|
|
532
|
+
acc[key].sportId = sportId;
|
|
533
|
+
|
|
534
|
+
return acc;
|
|
535
|
+
}, {}) as any;
|
|
536
|
+
|
|
537
|
+
// Format the grouped odds into the desired output
|
|
538
|
+
const formattedOdds = Object.entries(groupedOdds as any).reduce((acc: any, [_key, value]) => {
|
|
539
|
+
if ((value as any).home !== null && (value as any).away !== null) {
|
|
540
|
+
acc.push({
|
|
541
|
+
odds: (value as any).draw
|
|
542
|
+
? [(value as any).home, (value as any).away, (value as any).draw]
|
|
543
|
+
: [(value as any).home, (value as any).away],
|
|
544
|
+
typeId: (value as any).typeId,
|
|
545
|
+
sportId: (value as any).sportId,
|
|
546
|
+
type: (value as any).type,
|
|
547
|
+
});
|
|
548
|
+
}
|
|
549
|
+
return acc;
|
|
550
|
+
}, []);
|
|
551
|
+
|
|
552
|
+
return formattedOdds;
|
|
553
|
+
};
|
|
554
|
+
|
|
555
|
+
/**
|
|
556
|
+
* Normalize a score line like "A:B" to a map-friendly key "A_B" with
|
|
557
|
+
* numeric normalization (removing any leading zeros).
|
|
558
|
+
*
|
|
559
|
+
* Behavior:
|
|
560
|
+
* - Accepts optional whitespace around the colon (e.g., "03 : 10").
|
|
561
|
+
* - Parses both sides as numbers to strip leading zeros:
|
|
562
|
+
* "13:09" → "13_9", "13:00" → "13_0", "03:10" → "3_10".
|
|
563
|
+
* - If the input does NOT match "<digits> : <digits>", falls back to a simple
|
|
564
|
+
* string replace of ":" with "_" without numeric parsing.
|
|
565
|
+
*
|
|
566
|
+
* @param {string|number} line
|
|
567
|
+
* A score string (e.g., "13:09") or any value coercible to string.
|
|
568
|
+
*
|
|
569
|
+
* @returns {string}
|
|
570
|
+
* The normalized key (e.g., "13_9"). If not a digit:digit pattern, returns
|
|
571
|
+
* the string with ":" replaced by "_".
|
|
572
|
+
*/
|
|
573
|
+
function normalizeScoreLine(line: any) {
|
|
574
|
+
const m = String(line).match(/(\d+)\s*:\s*(\d+)/);
|
|
575
|
+
return m ? `${Number(m[1])}_${Number(m[2])}` : String(line).replace(':', '_');
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
/**
|
|
579
|
+
* Groups correct score odds by their lines and formats the result.
|
|
580
|
+
*
|
|
581
|
+
* @param {Array} oddsArray - The input array of odds objects.
|
|
582
|
+
* @param {Object} commonData - The common data object containing homeTeam and awayTeam information.
|
|
583
|
+
* @returns {Array} The grouped and formatted correct score odds.
|
|
584
|
+
*/
|
|
585
|
+
export const groupAndFormatCorrectScoreOdds = (oddsArray: any[], commonData: HomeAwayTeams): any[] => {
|
|
586
|
+
const homeTeamKey = commonData.homeTeam.toLowerCase().replace(/\s+/g, '_');
|
|
587
|
+
const awayTeamKey = commonData.awayTeam.toLowerCase().replace(/\s+/g, '_');
|
|
588
|
+
|
|
589
|
+
// Group odds by typeId first
|
|
590
|
+
const oddsByTypeId = oddsArray.reduce((acc: any, odd: any) => {
|
|
591
|
+
const typeId = odd.typeId || 10100;
|
|
592
|
+
if (!acc[typeId]) {
|
|
593
|
+
acc[typeId] = [];
|
|
594
|
+
}
|
|
595
|
+
acc[typeId].push(odd);
|
|
596
|
+
return acc;
|
|
597
|
+
}, {});
|
|
598
|
+
|
|
599
|
+
// Create market objects for each unique typeId
|
|
600
|
+
const marketObjects: any[] = [];
|
|
601
|
+
|
|
602
|
+
Object.entries(oddsByTypeId).forEach(([typeId, odds]: [string, any]) => {
|
|
603
|
+
const oddsMap = {
|
|
604
|
+
draw_0_0: 0,
|
|
605
|
+
draw_1_1: 0,
|
|
606
|
+
draw_2_2: 0,
|
|
607
|
+
draw_3_3: 0,
|
|
608
|
+
draw_4_4: 0,
|
|
609
|
+
[`${homeTeamKey}_1_0`]: 0,
|
|
610
|
+
[`${homeTeamKey}_2_0`]: 0,
|
|
611
|
+
[`${homeTeamKey}_2_1`]: 0,
|
|
612
|
+
[`${homeTeamKey}_3_0`]: 0,
|
|
613
|
+
[`${homeTeamKey}_3_1`]: 0,
|
|
614
|
+
[`${homeTeamKey}_3_2`]: 0,
|
|
615
|
+
[`${homeTeamKey}_4_0`]: 0,
|
|
616
|
+
[`${homeTeamKey}_4_1`]: 0,
|
|
617
|
+
[`${homeTeamKey}_4_2`]: 0,
|
|
618
|
+
[`${homeTeamKey}_4_3`]: 0,
|
|
619
|
+
[`${awayTeamKey}_1_0`]: 0,
|
|
620
|
+
[`${awayTeamKey}_2_0`]: 0,
|
|
621
|
+
[`${awayTeamKey}_2_1`]: 0,
|
|
622
|
+
[`${awayTeamKey}_3_0`]: 0,
|
|
623
|
+
[`${awayTeamKey}_3_1`]: 0,
|
|
624
|
+
[`${awayTeamKey}_3_2`]: 0,
|
|
625
|
+
[`${awayTeamKey}_4_0`]: 0,
|
|
626
|
+
[`${awayTeamKey}_4_1`]: 0,
|
|
627
|
+
[`${awayTeamKey}_4_2`]: 0,
|
|
628
|
+
[`${awayTeamKey}_4_3`]: 0,
|
|
629
|
+
draw_5_5: 0,
|
|
630
|
+
draw_6_6: 0,
|
|
631
|
+
draw_7_7: 0,
|
|
632
|
+
draw_8_8: 0,
|
|
633
|
+
draw_9_9: 0,
|
|
634
|
+
draw_10_10: 0,
|
|
635
|
+
draw_11_11: 0,
|
|
636
|
+
draw_12_12: 0,
|
|
637
|
+
draw_13_13: 0,
|
|
638
|
+
draw_14_14: 0,
|
|
639
|
+
[`${homeTeamKey}_5_0`]: 0,
|
|
640
|
+
[`${homeTeamKey}_5_1`]: 0,
|
|
641
|
+
[`${homeTeamKey}_5_2`]: 0,
|
|
642
|
+
[`${homeTeamKey}_5_3`]: 0,
|
|
643
|
+
[`${homeTeamKey}_5_4`]: 0,
|
|
644
|
+
[`${homeTeamKey}_6_0`]: 0,
|
|
645
|
+
[`${homeTeamKey}_6_1`]: 0,
|
|
646
|
+
[`${homeTeamKey}_6_2`]: 0,
|
|
647
|
+
[`${homeTeamKey}_6_3`]: 0,
|
|
648
|
+
[`${homeTeamKey}_6_4`]: 0,
|
|
649
|
+
[`${homeTeamKey}_6_5`]: 0,
|
|
650
|
+
[`${homeTeamKey}_7_0`]: 0,
|
|
651
|
+
[`${homeTeamKey}_7_1`]: 0,
|
|
652
|
+
[`${homeTeamKey}_7_2`]: 0,
|
|
653
|
+
[`${homeTeamKey}_7_3`]: 0,
|
|
654
|
+
[`${homeTeamKey}_7_4`]: 0,
|
|
655
|
+
[`${homeTeamKey}_7_5`]: 0,
|
|
656
|
+
[`${homeTeamKey}_7_6`]: 0,
|
|
657
|
+
[`${homeTeamKey}_8_0`]: 0,
|
|
658
|
+
[`${homeTeamKey}_8_1`]: 0,
|
|
659
|
+
[`${homeTeamKey}_8_2`]: 0,
|
|
660
|
+
[`${homeTeamKey}_8_3`]: 0,
|
|
661
|
+
[`${homeTeamKey}_8_4`]: 0,
|
|
662
|
+
[`${homeTeamKey}_8_5`]: 0,
|
|
663
|
+
[`${homeTeamKey}_8_6`]: 0,
|
|
664
|
+
[`${homeTeamKey}_8_7`]: 0,
|
|
665
|
+
[`${homeTeamKey}_9_0`]: 0,
|
|
666
|
+
[`${homeTeamKey}_9_1`]: 0,
|
|
667
|
+
[`${homeTeamKey}_9_2`]: 0,
|
|
668
|
+
[`${homeTeamKey}_9_3`]: 0,
|
|
669
|
+
[`${homeTeamKey}_9_4`]: 0,
|
|
670
|
+
[`${homeTeamKey}_9_5`]: 0,
|
|
671
|
+
[`${homeTeamKey}_9_6`]: 0,
|
|
672
|
+
[`${homeTeamKey}_9_7`]: 0,
|
|
673
|
+
[`${homeTeamKey}_9_8`]: 0,
|
|
674
|
+
[`${homeTeamKey}_10_0`]: 0,
|
|
675
|
+
[`${homeTeamKey}_10_1`]: 0,
|
|
676
|
+
[`${homeTeamKey}_10_2`]: 0,
|
|
677
|
+
[`${homeTeamKey}_10_3`]: 0,
|
|
678
|
+
[`${homeTeamKey}_10_4`]: 0,
|
|
679
|
+
[`${homeTeamKey}_10_5`]: 0,
|
|
680
|
+
[`${homeTeamKey}_10_6`]: 0,
|
|
681
|
+
[`${homeTeamKey}_10_7`]: 0,
|
|
682
|
+
[`${homeTeamKey}_10_8`]: 0,
|
|
683
|
+
[`${homeTeamKey}_10_9`]: 0,
|
|
684
|
+
[`${homeTeamKey}_11_0`]: 0,
|
|
685
|
+
[`${homeTeamKey}_11_1`]: 0,
|
|
686
|
+
[`${homeTeamKey}_11_2`]: 0,
|
|
687
|
+
[`${homeTeamKey}_11_3`]: 0,
|
|
688
|
+
[`${homeTeamKey}_11_4`]: 0,
|
|
689
|
+
[`${homeTeamKey}_11_5`]: 0,
|
|
690
|
+
[`${homeTeamKey}_11_6`]: 0,
|
|
691
|
+
[`${homeTeamKey}_11_7`]: 0,
|
|
692
|
+
[`${homeTeamKey}_11_8`]: 0,
|
|
693
|
+
[`${homeTeamKey}_11_9`]: 0,
|
|
694
|
+
[`${homeTeamKey}_11_10`]: 0,
|
|
695
|
+
[`${homeTeamKey}_12_0`]: 0,
|
|
696
|
+
[`${homeTeamKey}_12_1`]: 0,
|
|
697
|
+
[`${homeTeamKey}_12_2`]: 0,
|
|
698
|
+
[`${homeTeamKey}_12_3`]: 0,
|
|
699
|
+
[`${homeTeamKey}_12_4`]: 0,
|
|
700
|
+
[`${homeTeamKey}_12_5`]: 0,
|
|
701
|
+
[`${homeTeamKey}_12_6`]: 0,
|
|
702
|
+
[`${homeTeamKey}_12_7`]: 0,
|
|
703
|
+
[`${homeTeamKey}_12_8`]: 0,
|
|
704
|
+
[`${homeTeamKey}_12_9`]: 0,
|
|
705
|
+
[`${homeTeamKey}_12_10`]: 0,
|
|
706
|
+
[`${homeTeamKey}_12_11`]: 0,
|
|
707
|
+
[`${homeTeamKey}_13_0`]: 0,
|
|
708
|
+
[`${homeTeamKey}_13_1`]: 0,
|
|
709
|
+
[`${homeTeamKey}_13_2`]: 0,
|
|
710
|
+
[`${homeTeamKey}_13_3`]: 0,
|
|
711
|
+
[`${homeTeamKey}_13_4`]: 0,
|
|
712
|
+
[`${homeTeamKey}_13_5`]: 0,
|
|
713
|
+
[`${homeTeamKey}_13_6`]: 0,
|
|
714
|
+
[`${homeTeamKey}_13_7`]: 0,
|
|
715
|
+
[`${homeTeamKey}_13_8`]: 0,
|
|
716
|
+
[`${homeTeamKey}_13_9`]: 0,
|
|
717
|
+
[`${homeTeamKey}_13_10`]: 0,
|
|
718
|
+
[`${homeTeamKey}_13_11`]: 0,
|
|
719
|
+
[`${homeTeamKey}_13_12`]: 0,
|
|
720
|
+
[`${homeTeamKey}_14_0`]: 0,
|
|
721
|
+
[`${homeTeamKey}_14_1`]: 0,
|
|
722
|
+
[`${homeTeamKey}_14_2`]: 0,
|
|
723
|
+
[`${homeTeamKey}_14_3`]: 0,
|
|
724
|
+
[`${homeTeamKey}_14_4`]: 0,
|
|
725
|
+
[`${homeTeamKey}_14_5`]: 0,
|
|
726
|
+
[`${homeTeamKey}_14_6`]: 0,
|
|
727
|
+
[`${homeTeamKey}_14_7`]: 0,
|
|
728
|
+
[`${homeTeamKey}_14_8`]: 0,
|
|
729
|
+
[`${homeTeamKey}_14_9`]: 0,
|
|
730
|
+
[`${homeTeamKey}_14_10`]: 0,
|
|
731
|
+
[`${homeTeamKey}_14_11`]: 0,
|
|
732
|
+
[`${homeTeamKey}_14_12`]: 0,
|
|
733
|
+
[`${homeTeamKey}_14_13`]: 0,
|
|
734
|
+
[`${awayTeamKey}_5_0`]: 0,
|
|
735
|
+
[`${awayTeamKey}_5_1`]: 0,
|
|
736
|
+
[`${awayTeamKey}_5_2`]: 0,
|
|
737
|
+
[`${awayTeamKey}_5_3`]: 0,
|
|
738
|
+
[`${awayTeamKey}_5_4`]: 0,
|
|
739
|
+
[`${awayTeamKey}_6_0`]: 0,
|
|
740
|
+
[`${awayTeamKey}_6_1`]: 0,
|
|
741
|
+
[`${awayTeamKey}_6_2`]: 0,
|
|
742
|
+
[`${awayTeamKey}_6_3`]: 0,
|
|
743
|
+
[`${awayTeamKey}_6_4`]: 0,
|
|
744
|
+
[`${awayTeamKey}_6_5`]: 0,
|
|
745
|
+
[`${awayTeamKey}_7_0`]: 0,
|
|
746
|
+
[`${awayTeamKey}_7_1`]: 0,
|
|
747
|
+
[`${awayTeamKey}_7_2`]: 0,
|
|
748
|
+
[`${awayTeamKey}_7_3`]: 0,
|
|
749
|
+
[`${awayTeamKey}_7_4`]: 0,
|
|
750
|
+
[`${awayTeamKey}_7_5`]: 0,
|
|
751
|
+
[`${awayTeamKey}_7_6`]: 0,
|
|
752
|
+
[`${awayTeamKey}_8_0`]: 0,
|
|
753
|
+
[`${awayTeamKey}_8_1`]: 0,
|
|
754
|
+
[`${awayTeamKey}_8_2`]: 0,
|
|
755
|
+
[`${awayTeamKey}_8_3`]: 0,
|
|
756
|
+
[`${awayTeamKey}_8_4`]: 0,
|
|
757
|
+
[`${awayTeamKey}_8_5`]: 0,
|
|
758
|
+
[`${awayTeamKey}_8_6`]: 0,
|
|
759
|
+
[`${awayTeamKey}_8_7`]: 0,
|
|
760
|
+
[`${awayTeamKey}_9_0`]: 0,
|
|
761
|
+
[`${awayTeamKey}_9_1`]: 0,
|
|
762
|
+
[`${awayTeamKey}_9_2`]: 0,
|
|
763
|
+
[`${awayTeamKey}_9_3`]: 0,
|
|
764
|
+
[`${awayTeamKey}_9_4`]: 0,
|
|
765
|
+
[`${awayTeamKey}_9_5`]: 0,
|
|
766
|
+
[`${awayTeamKey}_9_6`]: 0,
|
|
767
|
+
[`${awayTeamKey}_9_7`]: 0,
|
|
768
|
+
[`${awayTeamKey}_9_8`]: 0,
|
|
769
|
+
[`${awayTeamKey}_10_0`]: 0,
|
|
770
|
+
[`${awayTeamKey}_10_1`]: 0,
|
|
771
|
+
[`${awayTeamKey}_10_2`]: 0,
|
|
772
|
+
[`${awayTeamKey}_10_3`]: 0,
|
|
773
|
+
[`${awayTeamKey}_10_4`]: 0,
|
|
774
|
+
[`${awayTeamKey}_10_5`]: 0,
|
|
775
|
+
[`${awayTeamKey}_10_6`]: 0,
|
|
776
|
+
[`${awayTeamKey}_10_7`]: 0,
|
|
777
|
+
[`${awayTeamKey}_10_8`]: 0,
|
|
778
|
+
[`${awayTeamKey}_10_9`]: 0,
|
|
779
|
+
[`${awayTeamKey}_11_0`]: 0,
|
|
780
|
+
[`${awayTeamKey}_11_1`]: 0,
|
|
781
|
+
[`${awayTeamKey}_11_2`]: 0,
|
|
782
|
+
[`${awayTeamKey}_11_3`]: 0,
|
|
783
|
+
[`${awayTeamKey}_11_4`]: 0,
|
|
784
|
+
[`${awayTeamKey}_11_5`]: 0,
|
|
785
|
+
[`${awayTeamKey}_11_6`]: 0,
|
|
786
|
+
[`${awayTeamKey}_11_7`]: 0,
|
|
787
|
+
[`${awayTeamKey}_11_8`]: 0,
|
|
788
|
+
[`${awayTeamKey}_11_9`]: 0,
|
|
789
|
+
[`${awayTeamKey}_11_10`]: 0,
|
|
790
|
+
[`${awayTeamKey}_12_0`]: 0,
|
|
791
|
+
[`${awayTeamKey}_12_1`]: 0,
|
|
792
|
+
[`${awayTeamKey}_12_2`]: 0,
|
|
793
|
+
[`${awayTeamKey}_12_3`]: 0,
|
|
794
|
+
[`${awayTeamKey}_12_4`]: 0,
|
|
795
|
+
[`${awayTeamKey}_12_5`]: 0,
|
|
796
|
+
[`${awayTeamKey}_12_6`]: 0,
|
|
797
|
+
[`${awayTeamKey}_12_7`]: 0,
|
|
798
|
+
[`${awayTeamKey}_12_8`]: 0,
|
|
799
|
+
[`${awayTeamKey}_12_9`]: 0,
|
|
800
|
+
[`${awayTeamKey}_12_10`]: 0,
|
|
801
|
+
[`${awayTeamKey}_12_11`]: 0,
|
|
802
|
+
[`${awayTeamKey}_13_0`]: 0,
|
|
803
|
+
[`${awayTeamKey}_13_1`]: 0,
|
|
804
|
+
[`${awayTeamKey}_13_2`]: 0,
|
|
805
|
+
[`${awayTeamKey}_13_3`]: 0,
|
|
806
|
+
[`${awayTeamKey}_13_4`]: 0,
|
|
807
|
+
[`${awayTeamKey}_13_5`]: 0,
|
|
808
|
+
[`${awayTeamKey}_13_6`]: 0,
|
|
809
|
+
[`${awayTeamKey}_13_7`]: 0,
|
|
810
|
+
[`${awayTeamKey}_13_8`]: 0,
|
|
811
|
+
[`${awayTeamKey}_13_9`]: 0,
|
|
812
|
+
[`${awayTeamKey}_13_10`]: 0,
|
|
813
|
+
[`${awayTeamKey}_13_11`]: 0,
|
|
814
|
+
[`${awayTeamKey}_13_12`]: 0,
|
|
815
|
+
[`${awayTeamKey}_14_0`]: 0,
|
|
816
|
+
[`${awayTeamKey}_14_1`]: 0,
|
|
817
|
+
[`${awayTeamKey}_14_2`]: 0,
|
|
818
|
+
[`${awayTeamKey}_14_3`]: 0,
|
|
819
|
+
[`${awayTeamKey}_14_4`]: 0,
|
|
820
|
+
[`${awayTeamKey}_14_5`]: 0,
|
|
821
|
+
[`${awayTeamKey}_14_6`]: 0,
|
|
822
|
+
[`${awayTeamKey}_14_7`]: 0,
|
|
823
|
+
[`${awayTeamKey}_14_8`]: 0,
|
|
824
|
+
[`${awayTeamKey}_14_9`]: 0,
|
|
825
|
+
[`${awayTeamKey}_14_10`]: 0,
|
|
826
|
+
[`${awayTeamKey}_14_11`]: 0,
|
|
827
|
+
[`${awayTeamKey}_14_12`]: 0,
|
|
828
|
+
[`${awayTeamKey}_14_13`]: 0,
|
|
829
|
+
other: 0,
|
|
830
|
+
};
|
|
831
|
+
|
|
832
|
+
// Populate the oddsMap with the odds from this typeId's odds
|
|
833
|
+
odds.forEach((odd: any) => {
|
|
834
|
+
const normalizedSelection = `${odd.selection.toLowerCase().replace(/\s+/g, '_')}_${normalizeScoreLine(
|
|
835
|
+
odd.selectionLine
|
|
836
|
+
)}`;
|
|
837
|
+
if (oddsMap.hasOwnProperty(normalizedSelection)) {
|
|
838
|
+
oddsMap[normalizedSelection] = odd.price;
|
|
839
|
+
}
|
|
840
|
+
});
|
|
841
|
+
|
|
842
|
+
const allOddsAreZero = Object.values(oddsMap).every((odd) => odd === ZERO);
|
|
843
|
+
|
|
844
|
+
if (!allOddsAreZero) {
|
|
845
|
+
const positionNames = Object.keys(oddsMap);
|
|
846
|
+
|
|
847
|
+
// Create a market object for this typeId
|
|
848
|
+
const marketObject = {
|
|
849
|
+
homeTeam: commonData.homeTeam,
|
|
850
|
+
awayTeam: commonData.awayTeam,
|
|
851
|
+
line: 0,
|
|
852
|
+
positionNames: positionNames,
|
|
853
|
+
odds: Object.values(oddsMap),
|
|
854
|
+
type: odds?.[0]?.type ? odds[0].type : 'Correct Score',
|
|
855
|
+
typeId: Number(typeId),
|
|
856
|
+
sportId: odds?.[0]?.sportId ? odds[0].sportId : undefined,
|
|
857
|
+
};
|
|
858
|
+
marketObjects.push(marketObject);
|
|
859
|
+
}
|
|
860
|
+
});
|
|
861
|
+
|
|
862
|
+
return marketObjects;
|
|
863
|
+
};
|
|
864
|
+
|
|
865
|
+
/**
|
|
866
|
+
* Groups double chance odds by their lines and formats the result.
|
|
867
|
+
*
|
|
868
|
+
* @param {Array} oddsArray - The input array of odds objects.
|
|
869
|
+
* @param {Object} commonData - The common data object containing homeTeam and awayTeam information.
|
|
870
|
+
* @returns {Array} The grouped and formatted correct score odds.
|
|
871
|
+
*/
|
|
872
|
+
export const groupAndFormatDoubleChanceOdds = (oddsArray: any[], commonData: HomeAwayTeams) => {
|
|
873
|
+
let probability1X = 0;
|
|
874
|
+
let probability12 = 0;
|
|
875
|
+
let probabilityX2 = 0;
|
|
876
|
+
|
|
877
|
+
let sportId;
|
|
878
|
+
|
|
879
|
+
oddsArray.forEach((odd) => {
|
|
880
|
+
if (odd.sportId) {
|
|
881
|
+
sportId = odd.sportId;
|
|
882
|
+
}
|
|
883
|
+
if (odd.selection.includes(commonData.homeTeam)) {
|
|
884
|
+
if (odd.selection.includes(commonData.awayTeam)) {
|
|
885
|
+
probability12 = odd.price;
|
|
886
|
+
} else {
|
|
887
|
+
probability1X = odd.price;
|
|
888
|
+
}
|
|
889
|
+
} else if (odd.selection.includes(commonData.awayTeam)) {
|
|
890
|
+
probabilityX2 = odd.price;
|
|
891
|
+
}
|
|
892
|
+
});
|
|
893
|
+
|
|
894
|
+
if ([probability1X, probability12, probabilityX2].every((odd) => odd === ZERO)) {
|
|
895
|
+
return [];
|
|
896
|
+
}
|
|
897
|
+
// Create the market object
|
|
898
|
+
const marketObject = {
|
|
899
|
+
homeTeam: commonData.homeTeam,
|
|
900
|
+
awayTeam: commonData.awayTeam,
|
|
901
|
+
line: 0,
|
|
902
|
+
odds: [probability1X, probability12, probabilityX2],
|
|
903
|
+
type: 'Double Chance',
|
|
904
|
+
typeId: 10003,
|
|
905
|
+
sportId: sportId,
|
|
906
|
+
};
|
|
907
|
+
return [marketObject];
|
|
908
|
+
};
|
|
909
|
+
|
|
910
|
+
// used for home/away markets
|
|
911
|
+
export const adjustSpreadOnChildOdds = (
|
|
912
|
+
iterableGroupedOdds: any[],
|
|
913
|
+
spreadDataForSport: any,
|
|
914
|
+
defaultSpreadForLiveMarkets: any
|
|
915
|
+
) => {
|
|
916
|
+
const result: any[] = [];
|
|
917
|
+
iterableGroupedOdds.forEach((data) => {
|
|
918
|
+
const hasDrawOdds = data.odds.length === 3;
|
|
919
|
+
const homeTeamOdds = convertOddsToImpl(data.odds[0]) || ZERO;
|
|
920
|
+
const awayTeamOdds = convertOddsToImpl(data.odds[1]) || ZERO;
|
|
921
|
+
const drawOdds = convertOddsToImpl(data.odds[2]) || ZERO;
|
|
922
|
+
const odds = hasDrawOdds ? [homeTeamOdds, awayTeamOdds, drawOdds] : [homeTeamOdds, awayTeamOdds];
|
|
923
|
+
|
|
924
|
+
const isZeroOddsChild = homeTeamOdds === ZERO || awayTeamOdds === ZERO || (hasDrawOdds && drawOdds === ZERO);
|
|
925
|
+
if (!isZeroOddsChild) {
|
|
926
|
+
const spreadData = getSpreadData(
|
|
927
|
+
spreadDataForSport,
|
|
928
|
+
data.sportId,
|
|
929
|
+
data.typeId,
|
|
930
|
+
defaultSpreadForLiveMarkets
|
|
931
|
+
);
|
|
932
|
+
|
|
933
|
+
let adjustedOdds;
|
|
934
|
+
if (spreadData !== null) {
|
|
935
|
+
adjustedOdds = adjustSpreadOnOdds(odds, spreadData.minSpread, spreadData.targetSpread);
|
|
936
|
+
} else {
|
|
937
|
+
adjustedOdds = adjustSpreadOnOdds(odds, defaultSpreadForLiveMarkets, 0);
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
result.push({
|
|
941
|
+
...data,
|
|
942
|
+
odds: adjustedOdds,
|
|
943
|
+
});
|
|
944
|
+
}
|
|
945
|
+
});
|
|
946
|
+
return result;
|
|
947
|
+
};
|