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.
Files changed (41) hide show
  1. package/.circleci/config.yml +32 -32
  2. package/.prettierrc +9 -9
  3. package/codecov.yml +20 -20
  4. package/index.ts +26 -26
  5. package/jest.config.ts +16 -16
  6. package/main.js +1 -1
  7. package/package.json +30 -30
  8. package/src/constants/common.ts +8 -7
  9. package/src/constants/errors.ts +7 -6
  10. package/src/constants/sports.ts +78 -78
  11. package/src/enums/sports.ts +109 -109
  12. package/src/tests/mock/MockLeagueMap.ts +200 -170
  13. package/src/tests/mock/MockOpticOddsEvents.ts +662 -662
  14. package/src/tests/mock/MockOpticSoccer.ts +9864 -9378
  15. package/src/tests/mock/MockSoccerRedis.ts +2308 -2308
  16. package/src/tests/unit/bookmakers.test.ts +148 -79
  17. package/src/tests/unit/markets.test.ts +176 -156
  18. package/src/tests/unit/odds.test.ts +103 -92
  19. package/src/tests/unit/resolution.test.ts +1488 -1393
  20. package/src/tests/unit/sports.test.ts +58 -58
  21. package/src/tests/unit/spread.test.ts +144 -131
  22. package/src/tests/utils/helper.ts +10 -0
  23. package/src/types/bookmakers.ts +7 -0
  24. package/src/types/missing-types.d.ts +2 -2
  25. package/src/types/odds.ts +80 -61
  26. package/src/types/resolution.ts +96 -96
  27. package/src/types/sports.ts +22 -19
  28. package/src/utils/bookmakers.ts +315 -159
  29. package/src/utils/constraints.ts +210 -210
  30. package/src/utils/gameMatching.ts +81 -81
  31. package/src/utils/markets.ts +119 -119
  32. package/src/utils/odds.ts +947 -918
  33. package/src/utils/opticOdds.ts +71 -71
  34. package/src/utils/resolution.ts +319 -319
  35. package/src/utils/sportPeriodMapping.ts +36 -36
  36. package/src/utils/sports.ts +51 -51
  37. package/src/utils/spread.ts +97 -97
  38. package/tsconfig.json +17 -13
  39. package/webpack.config.js +24 -24
  40. package/CLAUDE.md +0 -84
  41. package/resolution_live_markets.md +0 -356
@@ -1,96 +1,96 @@
1
- export type PeriodScores = {
2
- [key: string]: { home: number; away: number };
3
- };
4
-
5
- export type PeriodResolutionData = {
6
- completedPeriods: number[];
7
- readyForResolution: boolean;
8
- periodScores: PeriodScores;
9
- currentPeriod?: number;
10
- };
11
-
12
- /**
13
- * OpticOdds Event type from their API response
14
- * Uses 'any' for flexibility as API structure may vary
15
- */
16
- export type OpticOddsEvent = any;
17
-
18
- /**
19
- * Sport period structure types
20
- * Different sports have different period structures that affect how typeIds are resolved
21
- */
22
- export enum SportPeriodType {
23
- /** Sports with 2 halves (Soccer, NCAAB) */
24
- HALVES_BASED = 'halves_based',
25
- /** Sports with 4 quarters (NFL, NBA) */
26
- QUARTERS_BASED = 'quarters_based',
27
- /** Sports with 9+ innings (MLB, NPB, KBO, College Baseball, etc.) */
28
- INNINGS_BASED = 'innings_based',
29
- /** Sports with 9 periods without halves or secondary moneyline types */
30
- PERIOD_BASED = 'period_based',
31
- }
32
-
33
- /**
34
- * Halves-based sports period-to-typeId mapping (Soccer, NCAAB)
35
- * Period 1 = 1st half
36
- * Period 2 = 2nd half
37
- */
38
- export const HALVES_PERIOD_TYPE_ID_MAPPING: { [period: number]: number[] } = {
39
- 1: [10021, 10031, 10041, 10051, 10061, 10071, 10081, 10111, 10112, 10121, 10163, 10200, 10101], // 1st half
40
- 2: [10022, 10032, 10042, 10052, 10062, 10072, 10082, 10211, 10212, 10122, 10164, 10201, 10102], // 2nd half
41
- };
42
-
43
- /**
44
- * Quarters-based sports period-to-typeId mapping (NFL, NBA)
45
- * Period 1 = 1st quarter
46
- * Period 2 = 2nd quarter (also completes 1st half - typeId 10051)
47
- * Period 3 = 3rd quarter
48
- * Period 4 = 4th quarter (also completes 2nd half - typeId 10052)
49
- * Period 5+ = Overtime
50
- */
51
- export const QUARTERS_PERIOD_TYPE_ID_MAPPING: { [period: number]: number[] } = {
52
- 1: [10021, 10031, 10041, 10061, 10071, 10081, 10111, 10112, 10121, 10163, 10101], // 1st quarter
53
- 2: [10022, 10032, 10042, 10051, 10062, 10072, 10082, 10211, 10212, 10122, 10164, 10102], // 2nd quarter + 1st half
54
- 3: [10023, 10033, 10043, 10063, 10073, 10083, 10311, 10312, 10123, 10165, 10103], // 3rd quarter
55
- 4: [10024, 10034, 10044, 10052, 10064, 10074, 10084, 10411, 10412, 10124, 10166, 10104], // 4th quarter + 2nd half
56
- 5: [10025, 10035, 10045, 10055, 10065, 10075, 10085, 10511, 10512, 10167, 10105], // Overtime/5th period
57
- };
58
-
59
- /**
60
- * Innings-based sports period-to-typeId mapping (MLB, NPB, KBO, College Baseball)
61
- * Period 1-5 = Innings 1-5 (period 5 completes 1st half - typeId 10051)
62
- * Period 6-9 = Innings 6-9 (period 9 completes 2nd half - typeId 10052)
63
- */
64
- export const INNINGS_PERIOD_TYPE_ID_MAPPING: { [period: number]: number[] } = {
65
- 1: [10021, 10031, 10041, 10061, 10071, 10081, 10111, 10112, 10121, 10163, 10101], // 1st inning
66
- 2: [10022, 10032, 10042, 10062, 10072, 10082, 10211, 10212, 10122, 10164, 10102], // 2nd inning
67
- 3: [10023, 10033, 10043, 10063, 10073, 10083, 10311, 10312, 10123, 10165, 10170, 10171, 10172, 10173, 10174, 10201, 10103], // 3rd inning + first 3 innings
68
- 4: [10024, 10034, 10044, 10064, 10074, 10084, 10411, 10412, 10124, 10166, 10104], // 4th inning
69
- 5: [10025, 10035, 10045, 10051, 10065, 10075, 10085, 10511, 10512, 10167, 10200, 10105], // 5th inning + 1st half (first 5 innings)
70
- 6: [10026, 10036, 10046, 10056, 10066, 10076, 10086, 10611, 10612, 10168, 10106], // 6th inning
71
- 7: [10027, 10037, 10047, 10057, 10067, 10077, 10087, 10711, 10712, 10169, 10175, 10176, 10177, 10178, 10179, 10202, 10107], // 7th inning + first 7 innings
72
- 8: [10028, 10038, 10048, 10058, 10068, 10078, 10088, 10811, 10812, 10197, 10108], // 8th inning
73
- 9: [10029, 10039, 10049, 10052, 10069, 10079, 10089, 10198, 10109], // 9th inning
74
- };
75
-
76
- /**
77
- * Period-based sports period-to-typeId mapping (9 periods)
78
- * Excludes halves types (10051, 10052) and secondary moneyline types (ending in 11/12)
79
- */
80
- export const PERIOD_BASED_TYPE_ID_MAPPING: { [period: number]: number[] } = {
81
- 1: [10021, 10031, 10041, 10061, 10071, 10081, 10121, 10163, 10101], // 1st period
82
- 2: [10022, 10032, 10042, 10062, 10072, 10082, 10122, 10164, 10102], // 2nd period
83
- 3: [10023, 10033, 10043, 10063, 10073, 10083, 10123, 10165, 10103], // 3rd period
84
- 4: [10024, 10034, 10044, 10064, 10074, 10084, 10124, 10166, 10104], // 4th period
85
- 5: [10025, 10035, 10045, 10065, 10075, 10085, 10167, 10105], // 5th period
86
- 6: [10026, 10036, 10046, 10056, 10066, 10076, 10086, 10168, 10106], // 6th period
87
- 7: [10027, 10037, 10047, 10057, 10067, 10077, 10087, 10169, 10107], // 7th period
88
- 8: [10028, 10038, 10048, 10058, 10068, 10078, 10088, 10197, 10108], // 8th period
89
- 9: [10029, 10039, 10049, 10069, 10079, 10089, 10198, 10109], // 9th period
90
- };
91
-
92
- /**
93
- * Full game type IDs that should NOT be resolved during live games
94
- * These can only be resolved when the game status is "completed"
95
- */
96
- export const FULL_GAME_TYPE_IDS: number[] = [0, 10001, 10002, 10003, 10004, 10010, 10011, 10012];
1
+ export type PeriodScores = {
2
+ [key: string]: { home: number; away: number };
3
+ };
4
+
5
+ export type PeriodResolutionData = {
6
+ completedPeriods: number[];
7
+ readyForResolution: boolean;
8
+ periodScores: PeriodScores;
9
+ currentPeriod?: number;
10
+ };
11
+
12
+ /**
13
+ * OpticOdds Event type from their API response
14
+ * Uses 'any' for flexibility as API structure may vary
15
+ */
16
+ export type OpticOddsEvent = any;
17
+
18
+ /**
19
+ * Sport period structure types
20
+ * Different sports have different period structures that affect how typeIds are resolved
21
+ */
22
+ export enum SportPeriodType {
23
+ /** Sports with 2 halves (Soccer, NCAAB) */
24
+ HALVES_BASED = 'halves_based',
25
+ /** Sports with 4 quarters (NFL, NBA) */
26
+ QUARTERS_BASED = 'quarters_based',
27
+ /** Sports with 9+ innings (MLB, NPB, KBO, College Baseball, etc.) */
28
+ INNINGS_BASED = 'innings_based',
29
+ /** Sports with 9 periods without halves or secondary moneyline types */
30
+ PERIOD_BASED = 'period_based',
31
+ }
32
+
33
+ /**
34
+ * Halves-based sports period-to-typeId mapping (Soccer, NCAAB)
35
+ * Period 1 = 1st half
36
+ * Period 2 = 2nd half
37
+ */
38
+ export const HALVES_PERIOD_TYPE_ID_MAPPING: { [period: number]: number[] } = {
39
+ 1: [10021, 10031, 10041, 10051, 10061, 10071, 10081, 10111, 10112, 10121, 10163, 10200, 10101, 10118, 10119], // 1st half
40
+ 2: [10022, 10032, 10042, 10052, 10062, 10072, 10082, 10211, 10212, 10122, 10164, 10201, 10102, 10218, 10219], // 2nd half
41
+ };
42
+
43
+ /**
44
+ * Quarters-based sports period-to-typeId mapping (NFL, NBA)
45
+ * Period 1 = 1st quarter
46
+ * Period 2 = 2nd quarter (also completes 1st half - typeId 10051)
47
+ * Period 3 = 3rd quarter
48
+ * Period 4 = 4th quarter (also completes 2nd half - typeId 10052)
49
+ * Period 5+ = Overtime
50
+ */
51
+ export const QUARTERS_PERIOD_TYPE_ID_MAPPING: { [period: number]: number[] } = {
52
+ 1: [10021, 10031, 10041, 10061, 10071, 10081, 10111, 10112, 10121, 10163, 10101], // 1st quarter
53
+ 2: [10022, 10032, 10042, 10051, 10062, 10072, 10082, 10211, 10212, 10122, 10164, 10102, 10118, 10119], // 2nd quarter + 1st half
54
+ 3: [10023, 10033, 10043, 10063, 10073, 10083, 10311, 10312, 10123, 10165, 10103], // 3rd quarter
55
+ 4: [10024, 10034, 10044, 10052, 10064, 10074, 10084, 10411, 10412, 10124, 10166, 10104, 10218, 10219], // 4th quarter + 2nd half
56
+ 5: [10025, 10035, 10045, 10055, 10065, 10075, 10085, 10511, 10512, 10167, 10105], // Overtime/5th period
57
+ };
58
+
59
+ /**
60
+ * Innings-based sports period-to-typeId mapping (MLB, NPB, KBO, College Baseball)
61
+ * Period 1-5 = Innings 1-5 (period 5 completes 1st half - typeId 10051)
62
+ * Period 6-9 = Innings 6-9 (period 9 completes 2nd half - typeId 10052)
63
+ */
64
+ export const INNINGS_PERIOD_TYPE_ID_MAPPING: { [period: number]: number[] } = {
65
+ 1: [10021, 10031, 10041, 10061, 10071, 10081, 10111, 10112, 10121, 10163, 10101], // 1st inning
66
+ 2: [10022, 10032, 10042, 10062, 10072, 10082, 10211, 10212, 10122, 10164, 10102], // 2nd inning
67
+ 3: [10023, 10033, 10043, 10063, 10073, 10083, 10311, 10312, 10123, 10165, 10170, 10171, 10172, 10173, 10174, 10201, 10103], // 3rd inning + first 3 innings
68
+ 4: [10024, 10034, 10044, 10064, 10074, 10084, 10411, 10412, 10124, 10166, 10104], // 4th inning
69
+ 5: [10025, 10035, 10045, 10051, 10065, 10075, 10085, 10511, 10512, 10167, 10200, 10105], // 5th inning + 1st half (first 5 innings)
70
+ 6: [10026, 10036, 10046, 10056, 10066, 10076, 10086, 10611, 10612, 10168, 10106], // 6th inning
71
+ 7: [10027, 10037, 10047, 10057, 10067, 10077, 10087, 10711, 10712, 10169, 10175, 10176, 10177, 10178, 10179, 10202, 10107], // 7th inning + first 7 innings
72
+ 8: [10028, 10038, 10048, 10058, 10068, 10078, 10088, 10811, 10812, 10197, 10108], // 8th inning
73
+ 9: [10029, 10039, 10049, 10052, 10069, 10079, 10089, 10198, 10109], // 9th inning
74
+ };
75
+
76
+ /**
77
+ * Period-based sports period-to-typeId mapping (9 periods)
78
+ * Excludes halves types (10051, 10052) and secondary moneyline types (ending in 11/12)
79
+ */
80
+ export const PERIOD_BASED_TYPE_ID_MAPPING: { [period: number]: number[] } = {
81
+ 1: [10021, 10031, 10041, 10061, 10071, 10081, 10121, 10163, 10101], // 1st period
82
+ 2: [10022, 10032, 10042, 10062, 10072, 10082, 10122, 10164, 10102], // 2nd period
83
+ 3: [10023, 10033, 10043, 10063, 10073, 10083, 10123, 10165, 10103], // 3rd period
84
+ 4: [10024, 10034, 10044, 10064, 10074, 10084, 10124, 10166, 10104], // 4th period
85
+ 5: [10025, 10035, 10045, 10065, 10075, 10085, 10167, 10105], // 5th period
86
+ 6: [10026, 10036, 10046, 10056, 10066, 10076, 10086, 10168, 10106], // 6th period
87
+ 7: [10027, 10037, 10047, 10057, 10067, 10077, 10087, 10169, 10107], // 7th period
88
+ 8: [10028, 10038, 10048, 10058, 10068, 10078, 10088, 10197, 10108], // 8th period
89
+ 9: [10029, 10039, 10049, 10069, 10079, 10089, 10198, 10109], // 9th period
90
+ };
91
+
92
+ /**
93
+ * Full game type IDs that should NOT be resolved during live games
94
+ * These can only be resolved when the game status is "completed"
95
+ */
96
+ export const FULL_GAME_TYPE_IDS: number[] = [0, 10001, 10002, 10003, 10004, 10010, 10011, 10012];
@@ -1,19 +1,22 @@
1
-
2
- export type LeagueConfigInfo = {
3
- sportId: number;
4
- typeId: number;
5
- marketName: string;
6
- type: string;
7
- enabled: string;
8
- minOdds: number;
9
- maxOdds: number;
10
- addedSpread?: number;
11
- };
12
-
13
- export type ChildMarket = {
14
- leagueId: number;
15
- typeId: number;
16
- type: string;
17
- line: number;
18
- odds: Array<number>;
19
- };
1
+ export type LeagueConfigInfo = {
2
+ sportId: number;
3
+ typeId: number;
4
+ marketName: string;
5
+ type: string;
6
+ enabled: string;
7
+ minOdds: number;
8
+ maxOdds: number;
9
+ addedSpread?: number;
10
+ primaryBookmaker?: string;
11
+ secondaryBookmaker?: string;
12
+ };
13
+
14
+ export type ChildMarket = {
15
+ leagueId: number;
16
+ typeId: number;
17
+ type: string;
18
+ line: number;
19
+ odds: Array<number>;
20
+ };
21
+
22
+ export type LastPolledArray = { sportsbook: string; timestamp: number }[];