overtime-live-trading-utils 2.1.18 → 2.1.19

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "overtime-live-trading-utils",
3
- "version": "2.1.18",
3
+ "version": "2.1.19",
4
4
  "description": "",
5
5
  "main": "main.js",
6
6
  "scripts": {
@@ -26,6 +26,8 @@ export enum SportPeriodType {
26
26
  QUARTERS_BASED = 'quarters_based',
27
27
  /** Sports with 9+ innings (MLB, NPB, KBO, College Baseball, etc.) */
28
28
  INNINGS_BASED = 'innings_based',
29
+ /** Sports with 9 periods without halves or secondary moneyline types */
30
+ PERIOD_BASED = 'period_based',
29
31
  }
30
32
 
31
33
  /**
@@ -71,6 +73,22 @@ export const INNINGS_PERIOD_TYPE_ID_MAPPING: { [period: number]: number[] } = {
71
73
  9: [10029, 10039, 10049, 10052, 10069, 10079, 10089], // 9th inning + 2nd half
72
74
  };
73
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], // 1st period
82
+ 2: [10022, 10032, 10042, 10062, 10072, 10082, 10122], // 2nd period
83
+ 3: [10023, 10033, 10043, 10063, 10073, 10083, 10123], // 3rd period
84
+ 4: [10024, 10034, 10044, 10064, 10074, 10084, 10124], // 4th period
85
+ 5: [10025, 10035, 10045, 10065, 10075, 10085], // 5th period
86
+ 6: [10026, 10036, 10046, 10056, 10066, 10076, 10086], // 6th period
87
+ 7: [10027, 10037, 10047, 10057, 10067, 10077, 10087], // 7th period
88
+ 8: [10028, 10038, 10048, 10058, 10068, 10078, 10088], // 8th period
89
+ 9: [10029, 10039, 10049, 10069, 10079, 10089], // 9th period
90
+ };
91
+
74
92
  /**
75
93
  * Full game type IDs that should NOT be resolved during live games
76
94
  * These can only be resolved when the game status is "completed"
@@ -6,6 +6,7 @@ import {
6
6
  HALVES_PERIOD_TYPE_ID_MAPPING,
7
7
  QUARTERS_PERIOD_TYPE_ID_MAPPING,
8
8
  INNINGS_PERIOD_TYPE_ID_MAPPING,
9
+ PERIOD_BASED_TYPE_ID_MAPPING,
9
10
  FULL_GAME_TYPE_IDS,
10
11
  } from '../types/resolution';
11
12
 
@@ -122,6 +123,27 @@ export const canResolveMarketViaOpticOddsApi = (
122
123
  return detectCompletedPeriods(event);
123
124
  };
124
125
 
126
+ /**
127
+ * Maps a numeric value to a SportPeriodType enum
128
+ * @param sportTypeNum - Numeric representation of sport type (0 = halves, 1 = quarters, 2 = innings, 3 = period)
129
+ * @returns SportPeriodType enum value
130
+ * @throws Error if invalid number provided
131
+ */
132
+ export function mapNumberToSportPeriodType(sportTypeNum: number): SportPeriodType {
133
+ switch (sportTypeNum) {
134
+ case 0:
135
+ return SportPeriodType.HALVES_BASED;
136
+ case 1:
137
+ return SportPeriodType.QUARTERS_BASED;
138
+ case 2:
139
+ return SportPeriodType.INNINGS_BASED;
140
+ case 3:
141
+ return SportPeriodType.PERIOD_BASED;
142
+ default:
143
+ throw new Error(`Invalid sport type number: ${sportTypeNum}. Must be 0 (halves), 1 (quarters), 2 (innings), or 3 (period).`);
144
+ }
145
+ }
146
+
125
147
  /**
126
148
  * Selects the appropriate period-to-typeId mapping based on sport type
127
149
  * @param sportType - Sport period structure type
@@ -135,6 +157,8 @@ function selectMappingForSportType(sportType: SportPeriodType): { [period: numbe
135
157
  return QUARTERS_PERIOD_TYPE_ID_MAPPING;
136
158
  case SportPeriodType.INNINGS_BASED:
137
159
  return INNINGS_PERIOD_TYPE_ID_MAPPING;
160
+ case SportPeriodType.PERIOD_BASED:
161
+ return PERIOD_BASED_TYPE_ID_MAPPING;
138
162
  }
139
163
  }
140
164
 
@@ -142,26 +166,26 @@ function selectMappingForSportType(sportType: SportPeriodType): { [period: numbe
142
166
  * Checks if a single market type can be resolved based on completed periods
143
167
  * @param event - Event object from OpticOdds API
144
168
  * @param typeId - Single market type ID to check
145
- * @param sportType - Sport period structure type (halves, quarters, or innings based) - REQUIRED
169
+ * @param sportType - Sport period structure type - REQUIRED (enum or number: 0=halves, 1=quarters, 2=innings, 3=period)
146
170
  * @returns boolean indicating if that typeId can be resolved
147
171
  */
148
172
  export function canResolveMarketsForEvent(
149
173
  event: OpticOddsEvent,
150
174
  typeId: number,
151
- sportType: SportPeriodType
175
+ sportType: SportPeriodType | number
152
176
  ): boolean;
153
177
 
154
178
  /**
155
179
  * Checks which market types can be resolved from a batch based on completed periods
156
180
  * @param event - Event object from OpticOdds API
157
181
  * @param typeIds - Array of market type IDs to check
158
- * @param sportType - Sport period structure type (halves, quarters, or innings based) - REQUIRED
182
+ * @param sportType - Sport period structure type - REQUIRED (enum or number: 0=halves, 1=quarters, 2=innings, 3=period)
159
183
  * @returns Array of typeIds that can be resolved
160
184
  */
161
185
  export function canResolveMarketsForEvent(
162
186
  event: OpticOddsEvent,
163
187
  typeIds: number[],
164
- sportType: SportPeriodType
188
+ sportType: SportPeriodType | number
165
189
  ): number[];
166
190
 
167
191
  /**
@@ -170,15 +194,22 @@ export function canResolveMarketsForEvent(
170
194
  * @example
171
195
  * // Check single typeId for NFL (quarters-based)
172
196
  * const canResolve = canResolveMarketsForEvent(event, 10021, SportPeriodType.QUARTERS_BASED);
197
+ * // Or using number
198
+ * const canResolve = canResolveMarketsForEvent(event, 10021, 1);
173
199
  *
174
200
  * // Check batch of typeIds for MLB (innings-based)
175
201
  * const resolvable = canResolveMarketsForEvent(event, [10021, 10051], SportPeriodType.INNINGS_BASED);
176
202
  * // Returns: [10021] if only period 1-4 complete, [10021, 10051] if period 5 complete
203
+ *
204
+ * // Check with period-based (no halves/secondary moneyline)
205
+ * const canResolve = canResolveMarketsForEvent(event, 10021, SportPeriodType.PERIOD_BASED);
206
+ * // Or using number
207
+ * const canResolve = canResolveMarketsForEvent(event, 10021, 3);
177
208
  */
178
209
  export function canResolveMarketsForEvent(
179
210
  event: OpticOddsEvent,
180
211
  typeIdOrTypeIds: number | number[],
181
- sportType: SportPeriodType
212
+ sportType: SportPeriodType | number
182
213
  ): boolean | number[] {
183
214
  // Get completed periods
184
215
  const periodData = detectCompletedPeriods(event);
@@ -190,8 +221,11 @@ export function canResolveMarketsForEvent(
190
221
  const status = (event.fixture?.status || event.status || '').toLowerCase();
191
222
  const isCompleted = status === 'completed' || status === 'complete' || status === 'finished';
192
223
 
224
+ // Convert number to SportPeriodType if needed
225
+ const sportTypeEnum = typeof sportType === 'number' ? mapNumberToSportPeriodType(sportType) : sportType;
226
+
193
227
  // Select appropriate mapping based on sport type
194
- const mapping = selectMappingForSportType(sportType);
228
+ const mapping = selectMappingForSportType(sportTypeEnum);
195
229
 
196
230
  // Collect all resolvable typeIds based on completed periods
197
231
  const resolvableTypeIds = new Set<number>();