overtime-live-trading-utils 1.1.38 → 2.0.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/src/utils/odds.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  import * as oddslib from 'oddslib';
2
2
  import { DRAW, MIN_ODDS_FOR_DIFF_CHECKING, MONEYLINE_TYPE_ID, ZERO } from '../constants/common';
3
- import { checkOddsFromBookmakers } from './bookmakers';
4
- import { adjustSpreadOnOdds, getSpreadData } from './spread';
5
3
  import { MoneylineTypes } from '../enums/sports';
6
- import { ChildMarket, LeagueInfo } from '../types/sports';
4
+ import { HomeAwayTeams, Odds, OddsObject } from '../types/odds';
5
+ import { ChildMarket, LeagueConfigInfo } from '../types/sports';
6
+ import { checkOddsFromBookmakers } from './bookmakers';
7
7
  import { getLeagueInfo } from './sports';
8
- import { OddsObject } from '../types/odds';
8
+ import { adjustSpreadOnOdds, getSpreadData } from './spread';
9
9
 
10
10
  /**
11
11
  * Converts a given odds value from one format to another.
@@ -14,7 +14,7 @@ import { OddsObject } from '../types/odds';
14
14
  * @param {Number} odds - The odds value to convert.
15
15
  * @returns {Number} The converted odds value.
16
16
  */
17
- export const convertOddsToImpl = (odds) => {
17
+ export const convertOddsToImpl = (odds: number): number => {
18
18
  return odds === ZERO ? 0 : getOddsFromTo('decimal', 'impliedProbability', odds);
19
19
  };
20
20
 
@@ -25,7 +25,7 @@ export const convertOddsToImpl = (odds) => {
25
25
  * @param {Number} input - The odds value.
26
26
  * @returns {Number} The converted odds.
27
27
  */
28
- export const getOddsFromTo = (from, to, input) => {
28
+ export const getOddsFromTo = (from: string, to: string, input: number): number => {
29
29
  try {
30
30
  return oddslib.from(from, input).to(to);
31
31
  } catch (error) {
@@ -44,11 +44,11 @@ export const getOddsFromTo = (from, to, input) => {
44
44
  * @returns {Map} The filtered map for odds per provider.
45
45
  */
46
46
  export const filterOddsByMarketNameTeamNameBookmaker = (
47
- oddsArray,
48
- marketName,
49
- liveOddsProviders,
50
- commonData,
51
- isTwoPositionalSport
47
+ oddsArray: Odds,
48
+ marketName: MoneylineTypes,
49
+ liveOddsProviders: any[],
50
+ commonData: HomeAwayTeams,
51
+ isTwoPositionalSport: boolean
52
52
  ) => {
53
53
  const linesMap = new Map<any, any>();
54
54
  liveOddsProviders.forEach((oddsProvider) => {
@@ -115,13 +115,13 @@ export const filterOddsByMarketNameTeamNameBookmaker = (
115
115
  * @returns {Array} The parent odds for the event [homeOdds, awayOdds, drawOdds].
116
116
  */
117
117
  export const getParentOdds = (
118
- isTwoPositionalSport,
119
- sportSpreadData,
120
- liveOddsProviders,
121
- oddsApiObject,
122
- sportId,
123
- defaultSpreadForLiveMarkets,
124
- maxPercentageDiffBetwenOdds
118
+ isTwoPositionalSport: boolean,
119
+ sportSpreadData: any[],
120
+ liveOddsProviders: any[],
121
+ oddsApiObject: OddsObject,
122
+ sportId: string,
123
+ defaultSpreadForLiveMarkets: number,
124
+ maxPercentageDiffBetwenOdds: number
125
125
  ) => {
126
126
  const commonData = { homeTeam: oddsApiObject.homeTeam, awayTeam: oddsApiObject.awayTeam };
127
127
 
@@ -265,7 +265,11 @@ export const createChildMarkets: (
265
265
  * @param {string} oddsProvider - The main odds provider to filter by.
266
266
  * @returns {Array} The filtered odds array.
267
267
  */
268
- export const filterOddsByMarketNameBookmaker = (oddsArray, leagueInfos: LeagueInfo[], oddsProvider) => {
268
+ export const filterOddsByMarketNameBookmaker = (
269
+ oddsArray: Odds,
270
+ leagueInfos: LeagueConfigInfo[],
271
+ oddsProvider: string
272
+ ): any[] => {
269
273
  const allChildMarketsTypes = leagueInfos
270
274
  .filter(
271
275
  (leagueInfo) =>
@@ -296,7 +300,7 @@ export const filterOddsByMarketNameBookmaker = (oddsArray, leagueInfos: LeagueIn
296
300
  * @param {Object} commonData - The common data object containing homeTeam information.
297
301
  * @returns {Array} The grouped and formatted spread odds.
298
302
  */
299
- export const groupAndFormatSpreadOdds = (oddsArray, commonData) => {
303
+ export const groupAndFormatSpreadOdds = (oddsArray: any[], commonData: HomeAwayTeams) => {
300
304
  // Group odds by their selection points and selection
301
305
  const groupedOdds = oddsArray.reduce((acc: any, odd: any) => {
302
306
  const { points, marketName, price, selection, typeId, sportId, type } = odd;
@@ -321,16 +325,16 @@ export const groupAndFormatSpreadOdds = (oddsArray, commonData) => {
321
325
  return acc;
322
326
  }, {}) as any;
323
327
  // Format the grouped odds into the desired output
324
- const formattedOdds = (Object.entries(groupedOdds as any) as any).reduce((acc, [key, value]) => {
328
+ const formattedOdds = Object.entries(groupedOdds as any).reduce((acc: any, [key, value]) => {
325
329
  const [_marketName, lineFloat] = key.split('_');
326
330
  const line = parseFloat(lineFloat);
327
331
  if ((value as any).home !== null && (value as any).away !== null) {
328
332
  acc.push({
329
333
  line: line as any,
330
334
  odds: [(value as any).home, (value as any).away],
331
- typeId: value.typeId,
332
- sportId: value.sportId,
333
- type: value.type,
335
+ typeId: (value as any).typeId,
336
+ sportId: (value as any).sportId,
337
+ type: (value as any).type,
334
338
  });
335
339
  }
336
340
  return acc;
@@ -345,7 +349,7 @@ export const groupAndFormatSpreadOdds = (oddsArray, commonData) => {
345
349
  * @param {Array} oddsArray - The array of odds objects.
346
350
  * @returns {Object} The grouped odds.
347
351
  */
348
- export const groupAndFormatTotalOdds = (oddsArray, commonData) => {
352
+ export const groupAndFormatTotalOdds = (oddsArray: any[], commonData: HomeAwayTeams) => {
349
353
  // Group odds by their selection points and selection
350
354
  const groupedOdds = oddsArray.reduce((acc, odd) => {
351
355
  if (odd) {
@@ -368,7 +372,7 @@ export const groupAndFormatTotalOdds = (oddsArray, commonData) => {
368
372
  }, {});
369
373
 
370
374
  // Format the grouped odds into the desired output
371
- const formattedOdds = (Object.entries(groupedOdds as any) as any).reduce((acc, [key, value]) => {
375
+ const formattedOdds = Object.entries(groupedOdds as any).reduce((acc: any, [key, value]) => {
372
376
  const [_marketName, selection, selectionLine] = key.split('_');
373
377
  const line = parseFloat(selectionLine);
374
378
 
@@ -379,9 +383,9 @@ export const groupAndFormatTotalOdds = (oddsArray, commonData) => {
379
383
  acc.push({
380
384
  line: line as any,
381
385
  odds: [(value as any).over, (value as any).under],
382
- typeId: !isAwayTeam ? value.typeId : Number(value.typeId) + 1,
383
- sportId: value.sportId,
384
- type: value.type,
386
+ typeId: !isAwayTeam ? (value as any).typeId : Number((value as any).typeId) + 1,
387
+ sportId: (value as any).sportId,
388
+ type: (value as any).type,
385
389
  });
386
390
  }
387
391
  return acc;
@@ -397,7 +401,7 @@ export const groupAndFormatTotalOdds = (oddsArray, commonData) => {
397
401
  * @param {Object} commonData - The common data object containing homeTeam information.
398
402
  * @returns {Array} The grouped and formatted spread odds.
399
403
  */
400
- export const groupAndFormatMoneylineOdds = (oddsArray, commonData) => {
404
+ export const groupAndFormatMoneylineOdds = (oddsArray: any[], commonData: HomeAwayTeams) => {
401
405
  // Group odds by their selection points and selection
402
406
  const groupedOdds = oddsArray.reduce((acc: any, odd: any) => {
403
407
  const { price, selection, typeId, sportId, type } = odd;
@@ -418,15 +422,15 @@ export const groupAndFormatMoneylineOdds = (oddsArray, commonData) => {
418
422
  return acc;
419
423
  }, {}) as any;
420
424
  // Format the grouped odds into the desired output
421
- const formattedOdds = (Object.entries(groupedOdds as any) as any).reduce((acc, [_key, value]) => {
425
+ const formattedOdds = Object.entries(groupedOdds as any).reduce((acc: any, [_key, value]) => {
422
426
  if ((value as any).home !== null && (value as any).away !== null) {
423
427
  acc.push({
424
428
  odds: (value as any).draw
425
429
  ? [(value as any).home, (value as any).away, (value as any).draw]
426
430
  : [(value as any).home, (value as any).away],
427
- typeId: value.typeId,
428
- sportId: value.sportId,
429
- type: value.type,
431
+ typeId: (value as any).typeId,
432
+ sportId: (value as any).sportId,
433
+ type: (value as any).type,
430
434
  });
431
435
  }
432
436
  return acc;
@@ -435,7 +439,11 @@ export const groupAndFormatMoneylineOdds = (oddsArray, commonData) => {
435
439
  return formattedOdds;
436
440
  };
437
441
 
438
- export const adjustSpreadOnChildOdds = (iterableGroupedOdds, spreadDataForSport, defaultSpreadForLiveMarkets) => {
442
+ export const adjustSpreadOnChildOdds = (
443
+ iterableGroupedOdds: any[],
444
+ spreadDataForSport: any,
445
+ defaultSpreadForLiveMarkets: any
446
+ ) => {
439
447
  const result: any[] = [];
440
448
  iterableGroupedOdds.forEach((data) => {
441
449
  const hasDrawOdds = data.odds.length === 3;
@@ -1,68 +1,79 @@
1
1
  import bytes32 from 'bytes32';
2
2
  import { OPTIC_ODDS_ID_SEPARATOR, OVERTIME_ID_SEPARATOR } from '../constants/common';
3
3
  import { LeagueIdMapOpticOdds } from '../constants/sports';
4
+ import { Fixture, OddsObject, ScoresObject } from '../types/odds';
4
5
 
5
- export const mapOpticOddsApiFixtures = (fixturesData) =>
6
- fixturesData.map((fixtureData) => ({
7
- gameId: fixtureData.id, // fixture_id
8
- startDate: fixtureData.start_date,
9
- homeTeam: fixtureData.home_team_display,
10
- awayTeam: fixtureData.away_team_display,
11
- }));
6
+ export const mapOpticOddsApiFixtures = (fixturesData: any[]): Fixture[] =>
7
+ fixturesData.map(
8
+ (fixtureData) =>
9
+ ({
10
+ gameId: fixtureData.id, // fixture_id
11
+ startDate: fixtureData.start_date,
12
+ homeTeam: fixtureData.home_team_display,
13
+ awayTeam: fixtureData.away_team_display,
14
+ } as Fixture)
15
+ );
12
16
 
13
- export const mapOpticOddsApiResults = (resultsData) =>
14
- resultsData.map((resultData: any) => ({
15
- gameId: resultData.fixture.id, // fixture_id
16
- sport: resultData.sport.name,
17
- league: resultData.league.name.toLowerCase(),
18
- status: resultData.fixture.status ? resultData.fixture.status.toLowerCase() : resultData.fixture.status,
19
- isLive: resultData.fixture.is_live,
20
- clock: resultData.in_play.clock,
21
- period: resultData.in_play.period ? resultData.in_play.period.toLowerCase() : resultData.in_play.period,
22
- homeTeam: resultData.fixture.home_team_display,
23
- awayTeam: resultData.fixture.away_team_display,
24
- homeTotal: resultData.scores.home.total,
25
- awayTotal: resultData.scores.away.total,
26
- ...mapScorePeriods(resultData.scores.home.periods, 'home'),
27
- ...mapScorePeriods(resultData.scores.away.periods, 'away'),
28
- }));
17
+ export const mapOpticOddsApiResults = (resultsData: any[]): ScoresObject[] =>
18
+ resultsData.map(
19
+ (resultData) =>
20
+ ({
21
+ gameId: resultData.fixture.id, // fixture_id
22
+ sport: resultData.sport.name,
23
+ league: resultData.league.name.toLowerCase(),
24
+ status: resultData.fixture.status ? resultData.fixture.status.toLowerCase() : resultData.fixture.status,
25
+ isLive: resultData.fixture.is_live,
26
+ clock: resultData.in_play.clock,
27
+ period: resultData.in_play.period ? resultData.in_play.period.toLowerCase() : resultData.in_play.period,
28
+ homeTeam: resultData.fixture.home_team_display,
29
+ awayTeam: resultData.fixture.away_team_display,
30
+ homeTotal: resultData.scores.home.total,
31
+ awayTotal: resultData.scores.away.total,
32
+ ...mapScorePeriods(resultData.scores.home.periods, 'home'),
33
+ ...mapScorePeriods(resultData.scores.away.periods, 'away'),
34
+ } as ScoresObject)
35
+ );
29
36
 
30
- export const mapOpticOddsApiFixtureOdds = (oddsDataArray) =>
31
- oddsDataArray.map((oddsData) => ({
32
- gameId: oddsData.id, // fixture_id
33
- startDate: oddsData.start_date,
34
- homeTeam: oddsData.home_team_display,
35
- awayTeam: oddsData.away_team_display,
36
- isLive: oddsData.is_live,
37
- status: oddsData.status,
38
- sport: oddsData.sport.id,
39
- league: oddsData.league.name,
40
- odds: oddsData.odds.map((oddsObj) => ({
41
- id: oddsObj.id, // 39920-20584-2024-35:draftkings:2nd_set_moneyline:francisco_comesana
42
- sportsBookName: oddsObj.sportsbook,
43
- name: oddsObj.name,
44
- price: oddsObj.price,
45
- timestamp: oddsObj.timestamp,
46
- points: oddsObj.points,
47
- isMain: oddsObj.is_main,
48
- isLive: oddsData.is_live,
49
- marketName: oddsObj.market.toLowerCase(),
50
- playerId: oddsObj.player_id,
51
- selection: oddsObj.selection,
52
- selectionLine: oddsObj.selection_line,
53
- })),
54
- }));
37
+ export const mapOpticOddsApiFixtureOdds = (oddsDataArray: any[]): OddsObject[] =>
38
+ oddsDataArray.map(
39
+ (oddsData) =>
40
+ ({
41
+ gameId: oddsData.id, // fixture_id
42
+ startDate: oddsData.start_date,
43
+ homeTeam: oddsData.home_team_display,
44
+ awayTeam: oddsData.away_team_display,
45
+ isLive: oddsData.is_live,
46
+ status: oddsData.status,
47
+ sport: oddsData.sport.id,
48
+ league: oddsData.league.name,
49
+ odds: oddsData.odds.map((oddsObj: any) => ({
50
+ id: oddsObj.id, // 39920-20584-2024-35:draftkings:2nd_set_moneyline:francisco_comesana
51
+ sportsBookName: oddsObj.sportsbook,
52
+ name: oddsObj.name,
53
+ price: oddsObj.price,
54
+ timestamp: oddsObj.timestamp,
55
+ points: oddsObj.points,
56
+ isMain: oddsObj.is_main,
57
+ isLive: oddsData.is_live,
58
+ marketName: oddsObj.market.toLowerCase(),
59
+ playerId: oddsObj.player_id,
60
+ selection: oddsObj.selection,
61
+ selectionLine: oddsObj.selection_line,
62
+ })),
63
+ } as OddsObject)
64
+ );
55
65
 
56
- const mapScorePeriods = (periods, homeAwayType) =>
57
- Object.values(periods).reduce(
58
- (acc: any, periodValue, index) => ({
66
+ const mapScorePeriods = (periods: any, homeAwayType: string) =>
67
+ Object.entries(periods).reduce((acc, period) => {
68
+ const periodKey = period[0].split('_')[1];
69
+ const periodValue = period[1];
70
+ return {
59
71
  ...acc,
60
- [`${homeAwayType}Period${index + 1}`]: periodValue,
61
- }),
62
- {}
63
- ) as any;
72
+ [`${homeAwayType}Period${periodKey}`]: periodValue,
73
+ };
74
+ }, {});
64
75
 
65
- export const convertFromBytes32 = (value) => {
76
+ export const convertFromBytes32 = (value: string) => {
66
77
  const result = bytes32({ input: value });
67
78
  return result.replace(/\0/g, '');
68
79
  };
@@ -1,6 +1,5 @@
1
- import { LeagueMap } from '../constants/sports';
2
- import { League, Sport } from '../enums/sports';
3
- import { LeagueInfo } from '../types/sports';
1
+ import { League, LeagueMap, Sport } from 'overtime-utils';
2
+ import { LeagueConfigInfo } from '../types/sports';
4
3
 
5
4
  // Methods that use data from LeagueMap defined in constants in utils
6
5
  export const getLeagueSport = (league: League) => {
@@ -34,7 +33,7 @@ export const getLeagueOpticOddsName = (league: League) => {
34
33
  };
35
34
 
36
35
  // Methods are using data from live-markets-map.csv
37
- export const getLiveSupportedLeagues = (leagueInfoArray: LeagueInfo[]) => {
36
+ export const getLiveSupportedLeagues = (leagueInfoArray: LeagueConfigInfo[]) => {
38
37
  const uniqueId = new Set();
39
38
  leagueInfoArray
40
39
  .filter((leagueInfo) => leagueInfo.enabled === 'true')
@@ -42,7 +41,7 @@ export const getLiveSupportedLeagues = (leagueInfoArray: LeagueInfo[]) => {
42
41
  return Array.from(uniqueId);
43
42
  };
44
43
 
45
- export const getBetTypesForLeague = (league: League, leagueInfoArray: LeagueInfo[]) => {
44
+ export const getBetTypesForLeague = (league: League, leagueInfoArray: LeagueConfigInfo[]) => {
46
45
  const uniqueMarketNames = new Set();
47
46
  leagueInfoArray
48
47
  .filter((leagueInfo) => Number(leagueInfo.sportId) === Number(league) && leagueInfo.enabled === 'true')
@@ -51,12 +50,12 @@ export const getBetTypesForLeague = (league: League, leagueInfoArray: LeagueInfo
51
50
  return Array.from(uniqueMarketNames) as string[];
52
51
  };
53
52
 
54
- export const getLeagueInfo = (league: League, leagueInfoArray: LeagueInfo[]) => {
53
+ export const getLeagueInfo = (league: League, leagueInfoArray: LeagueConfigInfo[]) => {
55
54
  const leagueInfos = leagueInfoArray.filter((leagueInfo) => Number(leagueInfo.sportId) === league);
56
55
  return leagueInfos;
57
56
  };
58
57
 
59
- export const getLeagueSpreadTypes = (league: League, leagueInfoArray: LeagueInfo[]) => {
58
+ export const getLeagueSpreadTypes = (league: League, leagueInfoArray: LeagueConfigInfo[]) => {
60
59
  const betTypes = leagueInfoArray
61
60
  .filter(
62
61
  (leagueInfo) =>
@@ -69,7 +68,7 @@ export const getLeagueSpreadTypes = (league: League, leagueInfoArray: LeagueInfo
69
68
  return betTypes;
70
69
  };
71
70
 
72
- export const getLeagueTotalTypes = (league: League, leagueInfoArray: LeagueInfo[]) => {
71
+ export const getLeagueTotalTypes = (league: League, leagueInfoArray: LeagueConfigInfo[]) => {
73
72
  const betTypes = leagueInfoArray
74
73
  .filter(
75
74
  (leagueInfo) =>
@@ -1,6 +1,6 @@
1
- import { LeagueInfo } from '../types/sports';
1
+ import { LeagueConfigInfo } from '../types/sports';
2
2
 
3
- export const adjustSpreadOnOdds = (impliedProbs, minSpread, targetSpread) => {
3
+ export const adjustSpreadOnOdds = (impliedProbs: number[], minSpread: number, targetSpread: number) => {
4
4
  // Step 1: Check if any implied probability is zero
5
5
  if (impliedProbs.some((prob) => prob === 0)) {
6
6
  return impliedProbs;
@@ -54,7 +54,12 @@ export const adjustSpreadOnOdds = (impliedProbs, minSpread, targetSpread) => {
54
54
  return adjustedImpliedProbs;
55
55
  };
56
56
 
57
- export const getSpreadData = (spreadData, sportId, typeId, defaultSpreadForLiveMarkets) => {
57
+ export const getSpreadData = (
58
+ spreadData: any[],
59
+ sportId: string,
60
+ typeId: number,
61
+ defaultSpreadForLiveMarkets: number
62
+ ) => {
58
63
  const sportSpreadData = spreadData.find(
59
64
  (data) => Number(data.typeId) === Number(typeId) && Number(data.sportId) === Number(sportId)
60
65
  );
@@ -67,7 +72,7 @@ export const getSpreadData = (spreadData, sportId, typeId, defaultSpreadForLiveM
67
72
  return { minSpread: defaultSpreadForLiveMarkets, targetSpread: 0 };
68
73
  };
69
74
 
70
- export const adjustAddedSpread = (odds: number[], leagueInfo: LeagueInfo[], typeId: number) => {
75
+ export const adjustAddedSpread = (odds: number[], leagueInfo: LeagueConfigInfo[], typeId: number) => {
71
76
  // Pack market odds for UI
72
77
  return odds.map((probability) => {
73
78
  if (probability != 0) {
package/tsconfig.json CHANGED
@@ -3,10 +3,15 @@
3
3
  "module": "esnext",
4
4
  "esModuleInterop": true,
5
5
  "target": "es5",
6
- "lib": ["dom", "dom.iterable", "esnext"],
6
+ "lib": [
7
+ "dom",
8
+ "dom.iterable",
9
+ "esnext"
10
+ ],
7
11
  "moduleResolution": "node",
8
12
  "sourceMap": true,
9
13
  "outDir": "build",
10
- "declaration": true
14
+ "declaration": true,
15
+ "strict": true,
11
16
  }
12
- }
17
+ }