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,110 +1,110 @@
1
- import * as oddslib from 'oddslib';
2
- import { createChildMarkets, getParentOdds } from './odds';
3
- import { OddsObject } from '../types/odds';
4
- import { getLeagueInfo } from './sports';
5
- import { adjustAddedSpread } from './spread';
6
- /**
7
- * Processes a single sports event. This function maps event data to a specific format,
8
- * filters invalid events, and optionally fetches player properties if the sport supports it.
9
- * Returns the mapped event object or null if the event is filtered out or mapping results in a null object.
10
- *
11
- * @param {Object} market - The market API object to process
12
- * @param {Object} apiResponseWithOdds - Provider's API object to process
13
- * @param {Array} liveOddsProviders - Odds providers for live odds
14
- * @param {Array} spreadData - Spread data for odds.
15
- * @param {Boolean} isDrawAvailable - Is it two or three-positional sport
16
- * @param {Number} defaultSpreadForLiveMarkets - Default spread for live markets
17
- * @param {Number} maxPercentageDiffBetwenOdds - Maximum allowed percentage difference between same position odds from different providers
18
- * @param {Boolean} isTestnet - Flag showing should we process for testnet or mainnet
19
- * @returns {Promise<Object|null>} A promise that resolves to the processed event object or null if the event is invalid or mapping fails.
20
- */
21
- export const processMarket = (
22
- market: any,
23
- apiResponseWithOdds: OddsObject,
24
- liveOddsProviders: any,
25
- spreadData: any,
26
- isDrawAvailable: any,
27
- defaultSpreadForLiveMarkets: any,
28
- maxPercentageDiffBetwenOdds: any,
29
- leagueMap: any
30
- ) => {
31
- const sportSpreadData = spreadData.filter((data) => data.sportId === String(market.leagueId));
32
- const leagueInfo = getLeagueInfo(market.leagueId, leagueMap);
33
-
34
- const moneylineOdds = getParentOdds(
35
- !isDrawAvailable,
36
- sportSpreadData,
37
- liveOddsProviders,
38
- apiResponseWithOdds,
39
- market.leagueId,
40
- defaultSpreadForLiveMarkets,
41
- maxPercentageDiffBetwenOdds
42
- );
43
-
44
- const oddsAfterSpread = adjustAddedSpread(moneylineOdds.odds, leagueInfo, market.typeId);
45
-
46
- if (moneylineOdds.errorMessage) {
47
- market.odds = market.odds.map(() => {
48
- return {
49
- american: 0,
50
- decimal: 0,
51
- normalizedImplied: 0,
52
- };
53
- });
54
-
55
- market.errorMessage = moneylineOdds.errorMessage;
56
- } else {
57
- // Pack market odds for UI
58
- market.odds = oddsAfterSpread.map((probability) => {
59
- if (probability != 0) {
60
- return {
61
- american: oddslib.from('impliedProbability', probability).to('moneyline'),
62
- decimal: Number(oddslib.from('impliedProbability', probability).to('decimal').toFixed(10)),
63
- normalizedImplied: probability,
64
- };
65
- } else {
66
- market.errorMessage = 'Bad odds after spread adjustment';
67
- return {
68
- american: 0,
69
- decimal: 0,
70
- normalizedImplied: 0,
71
- };
72
- }
73
- });
74
- }
75
-
76
- const childMarkets = createChildMarkets(
77
- apiResponseWithOdds,
78
- sportSpreadData,
79
- market.leagueId,
80
- liveOddsProviders,
81
- defaultSpreadForLiveMarkets,
82
- leagueMap
83
- );
84
-
85
- const packedChildMarkets = childMarkets.map((childMarket: any) => {
86
- const preparedMarket = { ...market, ...childMarket };
87
- const oddsAfterSpread = adjustAddedSpread(preparedMarket.odds, leagueInfo, preparedMarket.typeId);
88
- if (preparedMarket.odds.length > 0) {
89
- preparedMarket.odds = oddsAfterSpread.map((probability) => {
90
- if (probability == 0) {
91
- return {
92
- american: 0,
93
- decimal: 0,
94
- normalizedImplied: 0,
95
- };
96
- }
97
-
98
- return {
99
- american: oddslib.from('impliedProbability', probability).to('moneyline'),
100
- decimal: Number(oddslib.from('impliedProbability', probability).to('decimal').toFixed(10)),
101
- normalizedImplied: probability,
102
- };
103
- });
104
- }
105
- return preparedMarket;
106
- });
107
- market.childMarkets = packedChildMarkets;
108
-
109
- return market;
110
- };
1
+ import * as oddslib from 'oddslib';
2
+ import { createChildMarkets, getParentOdds } from './odds';
3
+ import { OddsObject } from '../types/odds';
4
+ import { getLeagueInfo } from './sports';
5
+ import { adjustAddedSpread } from './spread';
6
+ /**
7
+ * Processes a single sports event. This function maps event data to a specific format,
8
+ * filters invalid events, and optionally fetches player properties if the sport supports it.
9
+ * Returns the mapped event object or null if the event is filtered out or mapping results in a null object.
10
+ *
11
+ * @param {Object} market - The market API object to process
12
+ * @param {Object} apiResponseWithOdds - Provider's API object to process
13
+ * @param {Array} liveOddsProviders - Odds providers for live odds
14
+ * @param {Array} spreadData - Spread data for odds.
15
+ * @param {Boolean} isDrawAvailable - Is it two or three-positional sport
16
+ * @param {Number} defaultSpreadForLiveMarkets - Default spread for live markets
17
+ * @param {Number} maxPercentageDiffBetwenOdds - Maximum allowed percentage difference between same position odds from different providers
18
+ * @param {Boolean} isTestnet - Flag showing should we process for testnet or mainnet
19
+ * @returns {Promise<Object|null>} A promise that resolves to the processed event object or null if the event is invalid or mapping fails.
20
+ */
21
+ export const processMarket = (
22
+ market: any,
23
+ apiResponseWithOdds: OddsObject,
24
+ liveOddsProviders: any,
25
+ spreadData: any,
26
+ isDrawAvailable: any,
27
+ defaultSpreadForLiveMarkets: any,
28
+ maxPercentageDiffBetwenOdds: any,
29
+ leagueMap: any
30
+ ) => {
31
+ const sportSpreadData = spreadData.filter((data) => data.sportId === String(market.leagueId));
32
+ const leagueInfo = getLeagueInfo(market.leagueId, leagueMap);
33
+
34
+ const moneylineOdds = getParentOdds(
35
+ !isDrawAvailable,
36
+ sportSpreadData,
37
+ liveOddsProviders,
38
+ apiResponseWithOdds,
39
+ market.leagueId,
40
+ defaultSpreadForLiveMarkets,
41
+ maxPercentageDiffBetwenOdds
42
+ );
43
+
44
+ const oddsAfterSpread = adjustAddedSpread(moneylineOdds.odds, leagueInfo, market.typeId);
45
+
46
+ if (moneylineOdds.errorMessage) {
47
+ market.odds = market.odds.map(() => {
48
+ return {
49
+ american: 0,
50
+ decimal: 0,
51
+ normalizedImplied: 0,
52
+ };
53
+ });
54
+
55
+ market.errorMessage = moneylineOdds.errorMessage;
56
+ } else {
57
+ // Pack market odds for UI
58
+ market.odds = oddsAfterSpread.map((probability) => {
59
+ if (probability != 0) {
60
+ return {
61
+ american: oddslib.from('impliedProbability', probability).to('moneyline'),
62
+ decimal: Number(oddslib.from('impliedProbability', probability).to('decimal').toFixed(10)),
63
+ normalizedImplied: probability,
64
+ };
65
+ } else {
66
+ market.errorMessage = 'Bad odds after spread adjustment';
67
+ return {
68
+ american: 0,
69
+ decimal: 0,
70
+ normalizedImplied: 0,
71
+ };
72
+ }
73
+ });
74
+ }
75
+
76
+ const childMarkets = createChildMarkets(
77
+ apiResponseWithOdds,
78
+ sportSpreadData,
79
+ market.leagueId,
80
+ liveOddsProviders,
81
+ defaultSpreadForLiveMarkets,
82
+ leagueMap
83
+ );
84
+
85
+ const packedChildMarkets = childMarkets.map((childMarket: any) => {
86
+ const preparedMarket = { ...market, ...childMarket };
87
+ const oddsAfterSpread = adjustAddedSpread(preparedMarket.odds, leagueInfo, preparedMarket.typeId);
88
+ if (preparedMarket.odds.length > 0) {
89
+ preparedMarket.odds = oddsAfterSpread.map((probability) => {
90
+ if (probability == 0) {
91
+ return {
92
+ american: 0,
93
+ decimal: 0,
94
+ normalizedImplied: 0,
95
+ };
96
+ }
97
+
98
+ return {
99
+ american: oddslib.from('impliedProbability', probability).to('moneyline'),
100
+ decimal: Number(oddslib.from('impliedProbability', probability).to('decimal').toFixed(10)),
101
+ normalizedImplied: probability,
102
+ };
103
+ });
104
+ }
105
+ return preparedMarket;
106
+ });
107
+ market.childMarkets = packedChildMarkets;
108
+
109
+ return market;
110
+ };