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