overtime-live-trading-utils 1.1.36 → 1.1.38

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.
@@ -1,102 +1,102 @@
1
- import bytes32 from 'bytes32';
2
- import { OPTIC_ODDS_ID_SEPARATOR, OVERTIME_ID_SEPARATOR } from '../constants/common';
3
- import { LeagueIdMapOpticOdds } from '../constants/sports';
4
-
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
- }));
12
-
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
- }));
29
-
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
- }));
55
-
56
- const mapScorePeriods = (periods, homeAwayType) =>
57
- Object.values(periods).reduce(
58
- (acc: any, periodValue, index) => ({
59
- ...acc,
60
- [`${homeAwayType}Period${index + 1}`]: periodValue,
61
- }),
62
- {}
63
- ) as any;
64
-
65
- export const convertFromBytes32 = (value) => {
66
- const result = bytes32({ input: value });
67
- return result.replace(/\0/g, '');
68
- };
69
-
70
- export const formatOpticOddsLeagueName = (leagueName: string) => leagueName.replaceAll(' ', '_').toLowerCase();
71
-
72
- export const mapFromOpticOddsToOvertimeFormat = (fixtureId: string) => {
73
- if (!fixtureId.includes(OPTIC_ODDS_ID_SEPARATOR)) {
74
- return fixtureId;
75
- }
76
- const [leagueName, id] = fixtureId.split(OPTIC_ODDS_ID_SEPARATOR);
77
- const overtimeLeagueId = Object.keys(LeagueIdMapOpticOdds).find(
78
- (key) => formatOpticOddsLeagueName(LeagueIdMapOpticOdds[Number(key)]) === leagueName
79
- );
80
- if (!overtimeLeagueId) {
81
- throw `Optic Odds league ${leagueName} not mapped.`;
82
- }
83
- return `${overtimeLeagueId}${OVERTIME_ID_SEPARATOR}${id}`;
84
- };
85
-
86
- export const mapFromOvertimeToOpticOddsFormat = (gameId: string) => {
87
- if (!gameId.includes(OVERTIME_ID_SEPARATOR)) {
88
- return gameId;
89
- }
90
- const [leagueId, id] = gameId.split(OVERTIME_ID_SEPARATOR);
91
- const opticOddsLeagueName = LeagueIdMapOpticOdds[Number(leagueId)];
92
- if (!opticOddsLeagueName) {
93
- throw `Overtime league ID ${leagueId} not mapped.`;
94
- }
95
- return `${formatOpticOddsLeagueName(opticOddsLeagueName)}${OPTIC_ODDS_ID_SEPARATOR}${id}`;
96
- };
97
-
98
- export const mapFromOpticOddsFormatToBytes32 = (fixtureId: string) =>
99
- bytes32({ input: mapFromOpticOddsToOvertimeFormat(fixtureId) });
100
-
101
- export const mapFromBytes32ToOpticOddsFormat = (gameId: string) =>
102
- mapFromOvertimeToOpticOddsFormat(convertFromBytes32(gameId));
1
+ import bytes32 from 'bytes32';
2
+ import { OPTIC_ODDS_ID_SEPARATOR, OVERTIME_ID_SEPARATOR } from '../constants/common';
3
+ import { LeagueIdMapOpticOdds } from '../constants/sports';
4
+
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
+ }));
12
+
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
+ }));
29
+
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
+ }));
55
+
56
+ const mapScorePeriods = (periods, homeAwayType) =>
57
+ Object.values(periods).reduce(
58
+ (acc: any, periodValue, index) => ({
59
+ ...acc,
60
+ [`${homeAwayType}Period${index + 1}`]: periodValue,
61
+ }),
62
+ {}
63
+ ) as any;
64
+
65
+ export const convertFromBytes32 = (value) => {
66
+ const result = bytes32({ input: value });
67
+ return result.replace(/\0/g, '');
68
+ };
69
+
70
+ export const formatOpticOddsLeagueName = (leagueName: string) => leagueName.replaceAll(' ', '_').toLowerCase();
71
+
72
+ export const mapFromOpticOddsToOvertimeFormat = (fixtureId: string) => {
73
+ if (!fixtureId.includes(OPTIC_ODDS_ID_SEPARATOR)) {
74
+ return fixtureId;
75
+ }
76
+ const [leagueName, id] = fixtureId.split(OPTIC_ODDS_ID_SEPARATOR);
77
+ const overtimeLeagueId = Object.keys(LeagueIdMapOpticOdds).find(
78
+ (key) => formatOpticOddsLeagueName(LeagueIdMapOpticOdds[Number(key)]) === leagueName
79
+ );
80
+ if (!overtimeLeagueId) {
81
+ throw `Optic Odds league ${leagueName} not mapped.`;
82
+ }
83
+ return `${overtimeLeagueId}${OVERTIME_ID_SEPARATOR}${id}`;
84
+ };
85
+
86
+ export const mapFromOvertimeToOpticOddsFormat = (gameId: string) => {
87
+ if (!gameId.includes(OVERTIME_ID_SEPARATOR)) {
88
+ return gameId;
89
+ }
90
+ const [leagueId, id] = gameId.split(OVERTIME_ID_SEPARATOR);
91
+ const opticOddsLeagueName = LeagueIdMapOpticOdds[Number(leagueId)];
92
+ if (!opticOddsLeagueName) {
93
+ throw `Overtime league ID ${leagueId} not mapped.`;
94
+ }
95
+ return `${formatOpticOddsLeagueName(opticOddsLeagueName)}${OPTIC_ODDS_ID_SEPARATOR}${id}`;
96
+ };
97
+
98
+ export const mapFromOpticOddsFormatToBytes32 = (fixtureId: string) =>
99
+ bytes32({ input: mapFromOpticOddsToOvertimeFormat(fixtureId) });
100
+
101
+ export const mapFromBytes32ToOpticOddsFormat = (gameId: string) =>
102
+ mapFromOvertimeToOpticOddsFormat(convertFromBytes32(gameId));
@@ -1,83 +1,83 @@
1
- import { LeagueMap } from '../constants/sports';
2
- import { League, Sport } from '../enums/sports';
3
- import { LeagueInfo } from '../types/sports';
4
-
5
- // Methods that use data from LeagueMap defined in constants in utils
6
- export const getLeagueSport = (league: League) => {
7
- const leagueInfo = LeagueMap[league];
8
- return leagueInfo ? leagueInfo.sport : Sport.EMPTY;
9
- };
10
-
11
- export const getLeagueLabel = (league: League) => {
12
- const leagueInfo = LeagueMap[league];
13
- return leagueInfo ? leagueInfo.label : '';
14
- };
15
-
16
- export const getLeagueProvider = (league: League) => {
17
- const leagueInfo = LeagueMap[league];
18
- return leagueInfo ? leagueInfo.provider : '';
19
- };
20
-
21
- export const getLeagueIsDrawAvailable = (league: League) => {
22
- const leagueInfo = LeagueMap[league];
23
- return leagueInfo ? leagueInfo.isDrawAvailable : false;
24
- };
25
-
26
- export const getLeaguePeriodType = (league: League) => {
27
- const leagueInfo = LeagueMap[league];
28
- return leagueInfo ? leagueInfo.periodType : '';
29
- };
30
-
31
- export const getLeagueOpticOddsName = (league: League) => {
32
- const leagueInfo = LeagueMap[league];
33
- return leagueInfo ? leagueInfo.opticOddsName : undefined;
34
- };
35
-
36
- // Methods are using data from live-markets-map.csv
37
- export const getLiveSupportedLeagues = (leagueInfoArray: LeagueInfo[]) => {
38
- const uniqueId = new Set();
39
- leagueInfoArray
40
- .filter((leagueInfo) => leagueInfo.enabled === 'true')
41
- .map((league) => uniqueId.add(Number(league.sportId)));
42
- return Array.from(uniqueId);
43
- };
44
-
45
- export const getBetTypesForLeague = (league: League, leagueInfoArray: LeagueInfo[]) => {
46
- const uniqueMarketNames = new Set();
47
- leagueInfoArray
48
- .filter((leagueInfo) => Number(leagueInfo.sportId) === Number(league) && leagueInfo.enabled === 'true')
49
- .map((leagueInfo) => uniqueMarketNames.add(leagueInfo.marketName));
50
-
51
- return Array.from(uniqueMarketNames) as string[];
52
- };
53
-
54
- export const getLeagueInfo = (league: League, leagueInfoArray: LeagueInfo[]) => {
55
- const leagueInfos = leagueInfoArray.filter((leagueInfo) => Number(leagueInfo.sportId) === league);
56
- return leagueInfos;
57
- };
58
-
59
- export const getLeagueSpreadTypes = (league: League, leagueInfoArray: LeagueInfo[]) => {
60
- const betTypes = leagueInfoArray
61
- .filter(
62
- (leagueInfo) =>
63
- Number(leagueInfo.sportId) === Number(league) &&
64
- leagueInfo.type === 'Spread' &&
65
- leagueInfo.enabled === 'true'
66
- )
67
- .map((leagueInfo) => leagueInfo.marketName.toLowerCase());
68
-
69
- return betTypes;
70
- };
71
-
72
- export const getLeagueTotalTypes = (league: League, leagueInfoArray: LeagueInfo[]) => {
73
- const betTypes = leagueInfoArray
74
- .filter(
75
- (leagueInfo) =>
76
- Number(leagueInfo.sportId) === Number(league) &&
77
- leagueInfo.type === 'Total' &&
78
- leagueInfo.enabled === 'true'
79
- )
80
- .map((leagueInfo) => leagueInfo.marketName.toLowerCase());
81
-
82
- return betTypes;
83
- };
1
+ import { LeagueMap } from '../constants/sports';
2
+ import { League, Sport } from '../enums/sports';
3
+ import { LeagueInfo } from '../types/sports';
4
+
5
+ // Methods that use data from LeagueMap defined in constants in utils
6
+ export const getLeagueSport = (league: League) => {
7
+ const leagueInfo = LeagueMap[league];
8
+ return leagueInfo ? leagueInfo.sport : Sport.EMPTY;
9
+ };
10
+
11
+ export const getLeagueLabel = (league: League) => {
12
+ const leagueInfo = LeagueMap[league];
13
+ return leagueInfo ? leagueInfo.label : '';
14
+ };
15
+
16
+ export const getLeagueProvider = (league: League) => {
17
+ const leagueInfo = LeagueMap[league];
18
+ return leagueInfo ? leagueInfo.provider : '';
19
+ };
20
+
21
+ export const getLeagueIsDrawAvailable = (league: League) => {
22
+ const leagueInfo = LeagueMap[league];
23
+ return leagueInfo ? leagueInfo.isDrawAvailable : false;
24
+ };
25
+
26
+ export const getLeaguePeriodType = (league: League) => {
27
+ const leagueInfo = LeagueMap[league];
28
+ return leagueInfo ? leagueInfo.periodType : '';
29
+ };
30
+
31
+ export const getLeagueOpticOddsName = (league: League) => {
32
+ const leagueInfo = LeagueMap[league];
33
+ return leagueInfo ? leagueInfo.opticOddsName : undefined;
34
+ };
35
+
36
+ // Methods are using data from live-markets-map.csv
37
+ export const getLiveSupportedLeagues = (leagueInfoArray: LeagueInfo[]) => {
38
+ const uniqueId = new Set();
39
+ leagueInfoArray
40
+ .filter((leagueInfo) => leagueInfo.enabled === 'true')
41
+ .map((league) => uniqueId.add(Number(league.sportId)));
42
+ return Array.from(uniqueId);
43
+ };
44
+
45
+ export const getBetTypesForLeague = (league: League, leagueInfoArray: LeagueInfo[]) => {
46
+ const uniqueMarketNames = new Set();
47
+ leagueInfoArray
48
+ .filter((leagueInfo) => Number(leagueInfo.sportId) === Number(league) && leagueInfo.enabled === 'true')
49
+ .map((leagueInfo) => uniqueMarketNames.add(leagueInfo.marketName));
50
+
51
+ return Array.from(uniqueMarketNames) as string[];
52
+ };
53
+
54
+ export const getLeagueInfo = (league: League, leagueInfoArray: LeagueInfo[]) => {
55
+ const leagueInfos = leagueInfoArray.filter((leagueInfo) => Number(leagueInfo.sportId) === league);
56
+ return leagueInfos;
57
+ };
58
+
59
+ export const getLeagueSpreadTypes = (league: League, leagueInfoArray: LeagueInfo[]) => {
60
+ const betTypes = leagueInfoArray
61
+ .filter(
62
+ (leagueInfo) =>
63
+ Number(leagueInfo.sportId) === Number(league) &&
64
+ leagueInfo.type === 'Spread' &&
65
+ leagueInfo.enabled === 'true'
66
+ )
67
+ .map((leagueInfo) => leagueInfo.marketName.toLowerCase());
68
+
69
+ return betTypes;
70
+ };
71
+
72
+ export const getLeagueTotalTypes = (league: League, leagueInfoArray: LeagueInfo[]) => {
73
+ const betTypes = leagueInfoArray
74
+ .filter(
75
+ (leagueInfo) =>
76
+ Number(leagueInfo.sportId) === Number(league) &&
77
+ leagueInfo.type === 'Total' &&
78
+ leagueInfo.enabled === 'true'
79
+ )
80
+ .map((leagueInfo) => leagueInfo.marketName.toLowerCase());
81
+
82
+ return betTypes;
83
+ };
@@ -1,92 +1,92 @@
1
- import { LeagueInfo } from '../types/sports';
2
-
3
- export const adjustSpreadOnOdds = (impliedProbs, minSpread, targetSpread) => {
4
- // Step 1: Check if any implied probability is zero
5
- if (impliedProbs.some((prob) => prob === 0)) {
6
- return impliedProbs;
7
- }
8
-
9
- // Step 2: Calculate the current total implied probabilities
10
- const totalImpliedProbs = impliedProbs.reduce((sum, prob) => sum + prob, 0);
11
-
12
- // Step 3: Check if the sum of implied probabilities is greater than 1
13
- if (totalImpliedProbs <= 1) {
14
- return Array(impliedProbs.length).fill(0);
15
- }
16
-
17
- // Step 4: Check if targetSpread is zero
18
- if (targetSpread === 0) {
19
- const currentSpread = (totalImpliedProbs - 1) * 100;
20
- // If minSpread is set and greater than current spread, use minSpread
21
- if (minSpread > currentSpread) {
22
- targetSpread = minSpread;
23
- } else {
24
- // If minSpread is less than current spread, return odds as they are
25
- return impliedProbs;
26
- }
27
- }
28
-
29
- // Step 5: Calculate the target total implied probabilities
30
- const targetTotalImpliedProbs = 1 + targetSpread / 100;
31
-
32
- // Step 6: Calculate the adjustment factor
33
- const adjustmentFactor = targetTotalImpliedProbs / totalImpliedProbs;
34
-
35
- // Step 7: Adjust the probabilities to reflect the target spread
36
- let adjustedImpliedProbs = impliedProbs.map((prob) => prob * adjustmentFactor);
37
-
38
- // Step 8: Check if any adjusted probability equals or exceeds 1
39
- if (adjustedImpliedProbs.some((prob) => prob >= 1)) {
40
- return Array(impliedProbs.length).fill(0);
41
- }
42
-
43
- // Step 9: Ensure the sum of the adjusted probabilities equals the target total implied probabilities
44
- const sumAdjustedProbs = adjustedImpliedProbs.reduce((sum, prob) => sum + prob, 0);
45
-
46
- // Step 10: If the sum of the adjusted probabilities is less than 1, return zeros
47
- if (sumAdjustedProbs < 1) {
48
- return Array(impliedProbs.length).fill(0);
49
- }
50
-
51
- const normalizationFactor = targetTotalImpliedProbs / sumAdjustedProbs;
52
- adjustedImpliedProbs = adjustedImpliedProbs.map((prob) => prob * normalizationFactor);
53
-
54
- return adjustedImpliedProbs;
55
- };
56
-
57
- export const getSpreadData = (spreadData, sportId, typeId, defaultSpreadForLiveMarkets) => {
58
- const sportSpreadData = spreadData.find(
59
- (data) => Number(data.typeId) === Number(typeId) && Number(data.sportId) === Number(sportId)
60
- );
61
- if (sportSpreadData) {
62
- return {
63
- minSpread: sportSpreadData.minSpread ? Number(sportSpreadData.minSpread) : defaultSpreadForLiveMarkets,
64
- targetSpread: sportSpreadData.targetSpread ? Number(sportSpreadData.targetSpread) : 0,
65
- };
66
- }
67
- return { minSpread: defaultSpreadForLiveMarkets, targetSpread: 0 };
68
- };
69
-
70
- export const adjustAddedSpread = (odds: number[], leagueInfo: LeagueInfo[], typeId: number) => {
71
- // Pack market odds for UI
72
- return odds.map((probability) => {
73
- if (probability != 0) {
74
- const leagueInfoByTypeId = leagueInfo.find((league) => Number(league.typeId) === Number(typeId));
75
- let finalProbability = probability;
76
-
77
- if (probability < 0.95) {
78
- if (leagueInfoByTypeId && Number(leagueInfoByTypeId.addedSpread)) {
79
- finalProbability = (probability * (100 + Number(leagueInfoByTypeId.addedSpread))) / 100;
80
- // edge case if added spread is bigger than 5%, it can happen that odd goes above 1, in that case return odd from api.
81
- if (finalProbability >= 1) {
82
- finalProbability = probability;
83
- }
84
- }
85
- }
86
-
87
- return finalProbability;
88
- } else {
89
- return 0;
90
- }
91
- });
92
- };
1
+ import { LeagueInfo } from '../types/sports';
2
+
3
+ export const adjustSpreadOnOdds = (impliedProbs, minSpread, targetSpread) => {
4
+ // Step 1: Check if any implied probability is zero
5
+ if (impliedProbs.some((prob) => prob === 0)) {
6
+ return impliedProbs;
7
+ }
8
+
9
+ // Step 2: Calculate the current total implied probabilities
10
+ const totalImpliedProbs = impliedProbs.reduce((sum, prob) => sum + prob, 0);
11
+
12
+ // Step 3: Check if the sum of implied probabilities is greater than 1
13
+ if (totalImpliedProbs <= 1) {
14
+ return Array(impliedProbs.length).fill(0);
15
+ }
16
+
17
+ // Step 4: Check if targetSpread is zero
18
+ if (targetSpread === 0) {
19
+ const currentSpread = (totalImpliedProbs - 1) * 100;
20
+ // If minSpread is set and greater than current spread, use minSpread
21
+ if (minSpread > currentSpread) {
22
+ targetSpread = minSpread;
23
+ } else {
24
+ // If minSpread is less than current spread, return odds as they are
25
+ return impliedProbs;
26
+ }
27
+ }
28
+
29
+ // Step 5: Calculate the target total implied probabilities
30
+ const targetTotalImpliedProbs = 1 + targetSpread / 100;
31
+
32
+ // Step 6: Calculate the adjustment factor
33
+ const adjustmentFactor = targetTotalImpliedProbs / totalImpliedProbs;
34
+
35
+ // Step 7: Adjust the probabilities to reflect the target spread
36
+ let adjustedImpliedProbs = impliedProbs.map((prob) => prob * adjustmentFactor);
37
+
38
+ // Step 8: Check if any adjusted probability equals or exceeds 1
39
+ if (adjustedImpliedProbs.some((prob) => prob >= 1)) {
40
+ return Array(impliedProbs.length).fill(0);
41
+ }
42
+
43
+ // Step 9: Ensure the sum of the adjusted probabilities equals the target total implied probabilities
44
+ const sumAdjustedProbs = adjustedImpliedProbs.reduce((sum, prob) => sum + prob, 0);
45
+
46
+ // Step 10: If the sum of the adjusted probabilities is less than 1, return zeros
47
+ if (sumAdjustedProbs < 1) {
48
+ return Array(impliedProbs.length).fill(0);
49
+ }
50
+
51
+ const normalizationFactor = targetTotalImpliedProbs / sumAdjustedProbs;
52
+ adjustedImpliedProbs = adjustedImpliedProbs.map((prob) => prob * normalizationFactor);
53
+
54
+ return adjustedImpliedProbs;
55
+ };
56
+
57
+ export const getSpreadData = (spreadData, sportId, typeId, defaultSpreadForLiveMarkets) => {
58
+ const sportSpreadData = spreadData.find(
59
+ (data) => Number(data.typeId) === Number(typeId) && Number(data.sportId) === Number(sportId)
60
+ );
61
+ if (sportSpreadData) {
62
+ return {
63
+ minSpread: sportSpreadData.minSpread ? Number(sportSpreadData.minSpread) : defaultSpreadForLiveMarkets,
64
+ targetSpread: sportSpreadData.targetSpread ? Number(sportSpreadData.targetSpread) : 0,
65
+ };
66
+ }
67
+ return { minSpread: defaultSpreadForLiveMarkets, targetSpread: 0 };
68
+ };
69
+
70
+ export const adjustAddedSpread = (odds: number[], leagueInfo: LeagueInfo[], typeId: number) => {
71
+ // Pack market odds for UI
72
+ return odds.map((probability) => {
73
+ if (probability != 0) {
74
+ const leagueInfoByTypeId = leagueInfo.find((league) => Number(league.typeId) === Number(typeId));
75
+ let finalProbability = probability;
76
+
77
+ if (probability < 0.95) {
78
+ if (leagueInfoByTypeId && Number(leagueInfoByTypeId.addedSpread)) {
79
+ finalProbability = (probability * (100 + Number(leagueInfoByTypeId.addedSpread))) / 100;
80
+ // edge case if added spread is bigger than 5%, it can happen that odd goes above 1, in that case return odd from api.
81
+ if (finalProbability >= 1) {
82
+ finalProbability = probability;
83
+ }
84
+ }
85
+ }
86
+
87
+ return finalProbability;
88
+ } else {
89
+ return 0;
90
+ }
91
+ });
92
+ };
package/tsconfig.json CHANGED
@@ -1,12 +1,12 @@
1
- {
2
- "compilerOptions": {
3
- "module": "esnext",
4
- "esModuleInterop": true,
5
- "target": "es5",
6
- "lib": ["dom", "dom.iterable", "esnext"],
7
- "moduleResolution": "node",
8
- "sourceMap": true,
9
- "outDir": "build",
10
- "declaration": true
11
- }
12
- }
1
+ {
2
+ "compilerOptions": {
3
+ "module": "esnext",
4
+ "esModuleInterop": true,
5
+ "target": "es5",
6
+ "lib": ["dom", "dom.iterable", "esnext"],
7
+ "moduleResolution": "node",
8
+ "sourceMap": true,
9
+ "outDir": "build",
10
+ "declaration": true
11
+ }
12
+ }
package/webpack.config.js CHANGED
@@ -1,24 +1,24 @@
1
- const path = require('path');
2
-
3
- module.exports = {
4
- entry: './index.ts',
5
- module: {
6
- rules: [
7
- {
8
- test: /\.ts?$/,
9
- use: 'ts-loader',
10
- exclude: /node_modules/,
11
- },
12
- ],
13
- },
14
- resolve: {
15
- extensions: ['.tsx', '.ts', '.js'],
16
- },
17
- output: {
18
- filename: 'main.js',
19
- path: path.resolve(__dirname),
20
- library: 'thalesUtils',
21
- libraryTarget: 'umd',
22
- globalObject: 'this',
23
- },
24
- };
1
+ const path = require('path');
2
+
3
+ module.exports = {
4
+ entry: './index.ts',
5
+ module: {
6
+ rules: [
7
+ {
8
+ test: /\.ts?$/,
9
+ use: 'ts-loader',
10
+ exclude: /node_modules/,
11
+ },
12
+ ],
13
+ },
14
+ resolve: {
15
+ extensions: ['.tsx', '.ts', '.js'],
16
+ },
17
+ output: {
18
+ filename: 'main.js',
19
+ path: path.resolve(__dirname),
20
+ library: 'thalesUtils',
21
+ libraryTarget: 'umd',
22
+ globalObject: 'this',
23
+ },
24
+ };