overtime-live-trading-utils 1.1.35 → 1.1.37

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,189 +1,186 @@
1
- import { League, Sport } from '../enums/sports';
2
- import { ScoresObject } from '../types/odds';
3
- import { getLeagueSport } from './sports';
4
-
5
- export const checkGameContraints = (opticOddsScoresApiResponse: ScoresObject, marketLeague: League, constraintsMap) => {
6
- const marketSport = getLeagueSport(marketLeague);
7
- const homeTeam = opticOddsScoresApiResponse.homeTeam;
8
- const currentScoreHome = opticOddsScoresApiResponse.homeTotal;
9
- const awayTeam = opticOddsScoresApiResponse.awayTeam;
10
- const currentScoreAway = opticOddsScoresApiResponse.awayTotal;
11
-
12
- const currentClock = opticOddsScoresApiResponse.clock;
13
- const currentPeriod = opticOddsScoresApiResponse.period;
14
- const currentGameStatus = opticOddsScoresApiResponse.status;
15
- const currentPeriodNumber = parseInt(currentPeriod);
16
-
17
- if (currentGameStatus.toLowerCase() == 'completed') {
18
- return {
19
- allow: false,
20
- message: `Blocking game ${homeTeam} - ${awayTeam} because it is no longer live.`,
21
- };
22
- }
23
-
24
- if (marketSport === Sport.SOCCER) {
25
- return allowSoccerGame(homeTeam, awayTeam, currentClock, currentPeriod, constraintsMap.get(Sport.SOCCER));
26
- }
27
-
28
- return {
29
- allow: true,
30
- message: `The sport ${marketLeague} does not have constraint`,
31
- };
32
- };
33
-
34
- export const allowGameSportWithPeriodConstraint = (homeTeam, awayTeam, currentPeriod, periodLimitForLiveTrade) => {
35
- if (!Number.isNaN(currentPeriod) && currentPeriod >= periodLimitForLiveTrade) {
36
- return {
37
- allow: false,
38
- message: `Blocking game ${homeTeam} - ${awayTeam} due to period: ${currentPeriod}. period`,
39
- };
40
- }
41
- return { allow: true, message: '' };
42
- };
43
-
44
- export const allowSoccerGame = (homeTeam, awayTeam, currentClock, currentPeriod, soccerMinuteLimitForLiveTrading) => {
45
- const currentClockNumber = Number(currentClock);
46
- if (
47
- (!Number.isNaN(currentClockNumber) && currentClockNumber >= soccerMinuteLimitForLiveTrading) ||
48
- (Number.isNaN(currentClockNumber) && currentPeriod.toLowerCase() != 'half')
49
- ) {
50
- return { allow: false, message: `Blocking game ${homeTeam} - ${awayTeam} due to clock: ${currentClock}min` };
51
- }
52
-
53
- return { allow: true, message: '' };
54
- };
55
-
56
- export const allowGameSportWithResultConstraint = (
57
- opticOddsScoresApiResponse: ScoresObject,
58
- homeTeam,
59
- awayTeam,
60
- currentPeriod,
61
- currentScoreHome,
62
- currentScoreAway,
63
- marketLeague,
64
- marketSport
65
- ) => {
66
- const setInProgress = Number(currentPeriod);
67
- const currentResultInSet = fetchResultInCurrentSet(setInProgress, opticOddsScoresApiResponse);
68
- const atpGrandSlamMatch = opticOddsScoresApiResponse.league.toLowerCase() == 'atp';
69
- const currentSetsScore = { home: currentScoreHome, away: currentScoreAway };
70
-
71
- if (marketSport == Sport.VOLLEYBALL) {
72
- if (setInProgress == 5) {
73
- return checkResultConstraint(
74
- homeTeam,
75
- awayTeam,
76
- currentResultInSet,
77
- currentSetsScore,
78
- VOLLEYBALL_SET_THRESHOLD,
79
- VOLLEYBALL_FIFTH_SET_POINTS_LIMIT
80
- );
81
- } else {
82
- return checkResultConstraint(
83
- homeTeam,
84
- awayTeam,
85
- currentResultInSet,
86
- currentSetsScore,
87
- VOLLEYBALL_SET_THRESHOLD,
88
- VOLLEYBALL_POINTS_LIMIT
89
- );
90
- }
91
- }
92
-
93
- if (marketLeague.toString().startsWith(League.TENNIS_GS) && atpGrandSlamMatch) {
94
- return checkResultConstraint(
95
- homeTeam,
96
- awayTeam,
97
- currentResultInSet,
98
- currentSetsScore,
99
- TENNIS_ATP_GRAND_SLAM_SET_THRESHOLD,
100
- TENNIS_GEMS_LIMIT
101
- );
102
- }
103
-
104
- if (
105
- (marketLeague.toString().startsWith(League.TENNIS_GS) && !atpGrandSlamMatch) ||
106
- marketLeague.toString().startsWith(League.TENNIS_MASTERS) ||
107
- marketLeague.toString().startsWith(League.SUMMER_OLYMPICS_TENNIS) ||
108
- marketLeague.toString().startsWith(League.TENNIS_WTA)
109
- ) {
110
- return checkResultConstraint(
111
- homeTeam,
112
- awayTeam,
113
- currentResultInSet,
114
- currentSetsScore,
115
- TENNIS_MASTERS_SET_THRESHOLD,
116
- TENNIS_GEMS_LIMIT
117
- );
118
- }
119
-
120
- return {
121
- allow: true,
122
- message: `The sport ${marketLeague} does not have result constraint`,
123
- };
124
- };
125
-
126
- export const fetchResultInCurrentSet = (currentSet: number, opticOddsScoresApiResponse: ScoresObject) => {
127
- let currentHomeGameScore = 0;
128
- let currentAwayGameScore = 0;
129
- switch (currentSet) {
130
- case 1:
131
- currentHomeGameScore = Number(opticOddsScoresApiResponse.homePeriod1);
132
- currentAwayGameScore = Number(opticOddsScoresApiResponse.awayPeriod1);
133
- break;
134
- case 2:
135
- currentHomeGameScore = Number(opticOddsScoresApiResponse.homePeriod2);
136
- currentAwayGameScore = Number(opticOddsScoresApiResponse.awayPeriod2);
137
- break;
138
- case 3:
139
- currentHomeGameScore = Number(opticOddsScoresApiResponse.homePeriod3);
140
- currentAwayGameScore = Number(opticOddsScoresApiResponse.awayPeriod3);
141
- break;
142
- case 4:
143
- currentHomeGameScore = Number(opticOddsScoresApiResponse.homePeriod4);
144
- currentAwayGameScore = Number(opticOddsScoresApiResponse.awayPeriod4);
145
- break;
146
- case 5:
147
- currentHomeGameScore = Number(opticOddsScoresApiResponse.homePeriod5);
148
- currentAwayGameScore = Number(opticOddsScoresApiResponse.awayPeriod5);
149
- break;
150
- }
151
- return { home: currentHomeGameScore, away: currentAwayGameScore };
152
- };
153
-
154
- const checkResultConstraint = (homeTeam, awayTeam, currentResultInSet, currentSetsWon, setThreshold, resultLimit) => {
155
- if (Number(currentSetsWon.home) == setThreshold || Number(currentSetsWon.away) == setThreshold) {
156
- if (Number(currentSetsWon.home) == setThreshold && currentResultInSet.home >= resultLimit) {
157
- return {
158
- allow: false,
159
- message: `Blocking game ${homeTeam} - ${awayTeam} due to current result: ${currentSetsWon.home} - ${currentSetsWon.away} (${currentResultInSet.home} - ${currentResultInSet.away})`,
160
- };
161
- }
162
-
163
- if (Number(currentSetsWon.away) == setThreshold && currentResultInSet.away >= resultLimit) {
164
- return {
165
- allow: false,
166
- message: `Blocking game ${homeTeam} - ${awayTeam} due to current result: ${currentSetsWon.home} - ${currentSetsWon.away} (${currentResultInSet.home} - ${currentResultInSet.away})`,
167
- };
168
- }
169
- return {
170
- allow: true,
171
- message: '',
172
- currentHomeGameScore: currentResultInSet.home,
173
- currentAwayGameScore: currentResultInSet.away,
174
- };
175
- }
176
- return {
177
- allow: true,
178
- message: '',
179
- currentHomeGameScore: currentResultInSet.home,
180
- currentAwayGameScore: currentResultInSet.away,
181
- };
182
- };
183
-
184
- const VOLLEYBALL_SET_THRESHOLD = 2;
185
- const VOLLEYBALL_POINTS_LIMIT = 20;
186
- const VOLLEYBALL_FIFTH_SET_POINTS_LIMIT = 10;
187
- const TENNIS_ATP_GRAND_SLAM_SET_THRESHOLD = 2;
188
- const TENNIS_MASTERS_SET_THRESHOLD = 1;
189
- const TENNIS_GEMS_LIMIT = 5;
1
+ import { League, Sport } from '../enums/sports';
2
+ import { ScoresObject } from '../types/odds';
3
+ import { getLeagueSport } from './sports';
4
+
5
+ export const checkGameContraints = (opticOddsScoresApiResponse: ScoresObject, marketLeague: League, constraintsMap) => {
6
+ const marketSport = getLeagueSport(marketLeague);
7
+ const homeTeam = opticOddsScoresApiResponse.homeTeam;
8
+ const awayTeam = opticOddsScoresApiResponse.awayTeam;
9
+
10
+ const currentClock = opticOddsScoresApiResponse.clock;
11
+ const currentPeriod = opticOddsScoresApiResponse.period;
12
+ const currentGameStatus = opticOddsScoresApiResponse.status;
13
+
14
+ if (currentGameStatus.toLowerCase() == 'completed') {
15
+ return {
16
+ allow: false,
17
+ message: `Blocking game ${homeTeam} - ${awayTeam} because it is no longer live.`,
18
+ };
19
+ }
20
+
21
+ if (marketSport === Sport.SOCCER) {
22
+ return allowSoccerGame(homeTeam, awayTeam, currentClock, currentPeriod, constraintsMap.get(Sport.SOCCER));
23
+ }
24
+
25
+ return {
26
+ allow: true,
27
+ message: `The sport ${marketLeague} does not have constraint`,
28
+ };
29
+ };
30
+
31
+ export const allowGameSportWithPeriodConstraint = (homeTeam, awayTeam, currentPeriod, periodLimitForLiveTrade) => {
32
+ if (!Number.isNaN(currentPeriod) && currentPeriod >= periodLimitForLiveTrade) {
33
+ return {
34
+ allow: false,
35
+ message: `Blocking game ${homeTeam} - ${awayTeam} due to period: ${currentPeriod}. period`,
36
+ };
37
+ }
38
+ return { allow: true, message: '' };
39
+ };
40
+
41
+ export const allowSoccerGame = (homeTeam, awayTeam, currentClock, currentPeriod, soccerMinuteLimitForLiveTrading) => {
42
+ const currentClockNumber = Number(currentClock);
43
+ if (
44
+ (!Number.isNaN(currentClockNumber) && currentClockNumber >= soccerMinuteLimitForLiveTrading) ||
45
+ (Number.isNaN(currentClockNumber) && currentPeriod.toLowerCase() != 'half')
46
+ ) {
47
+ return { allow: false, message: `Blocking game ${homeTeam} - ${awayTeam} due to clock: ${currentClock}min` };
48
+ }
49
+
50
+ return { allow: true, message: '' };
51
+ };
52
+
53
+ export const allowGameSportWithResultConstraint = (
54
+ opticOddsScoresApiResponse: ScoresObject,
55
+ homeTeam,
56
+ awayTeam,
57
+ currentPeriod,
58
+ currentScoreHome,
59
+ currentScoreAway,
60
+ marketLeague,
61
+ marketSport
62
+ ) => {
63
+ const setInProgress = Number(currentPeriod);
64
+ const currentResultInSet = fetchResultInCurrentSet(setInProgress, opticOddsScoresApiResponse);
65
+ const atpGrandSlamMatch = opticOddsScoresApiResponse.league.toLowerCase() == 'atp';
66
+ const currentSetsScore = { home: currentScoreHome, away: currentScoreAway };
67
+
68
+ if (marketSport == Sport.VOLLEYBALL) {
69
+ if (setInProgress == 5) {
70
+ return checkResultConstraint(
71
+ homeTeam,
72
+ awayTeam,
73
+ currentResultInSet,
74
+ currentSetsScore,
75
+ VOLLEYBALL_SET_THRESHOLD,
76
+ VOLLEYBALL_FIFTH_SET_POINTS_LIMIT
77
+ );
78
+ } else {
79
+ return checkResultConstraint(
80
+ homeTeam,
81
+ awayTeam,
82
+ currentResultInSet,
83
+ currentSetsScore,
84
+ VOLLEYBALL_SET_THRESHOLD,
85
+ VOLLEYBALL_POINTS_LIMIT
86
+ );
87
+ }
88
+ }
89
+
90
+ if (marketLeague.toString().startsWith(League.TENNIS_GS) && atpGrandSlamMatch) {
91
+ return checkResultConstraint(
92
+ homeTeam,
93
+ awayTeam,
94
+ currentResultInSet,
95
+ currentSetsScore,
96
+ TENNIS_ATP_GRAND_SLAM_SET_THRESHOLD,
97
+ TENNIS_GEMS_LIMIT
98
+ );
99
+ }
100
+
101
+ if (
102
+ (marketLeague.toString().startsWith(League.TENNIS_GS) && !atpGrandSlamMatch) ||
103
+ marketLeague.toString().startsWith(League.TENNIS_MASTERS) ||
104
+ marketLeague.toString().startsWith(League.SUMMER_OLYMPICS_TENNIS) ||
105
+ marketLeague.toString().startsWith(League.TENNIS_WTA)
106
+ ) {
107
+ return checkResultConstraint(
108
+ homeTeam,
109
+ awayTeam,
110
+ currentResultInSet,
111
+ currentSetsScore,
112
+ TENNIS_MASTERS_SET_THRESHOLD,
113
+ TENNIS_GEMS_LIMIT
114
+ );
115
+ }
116
+
117
+ return {
118
+ allow: true,
119
+ message: `The sport ${marketLeague} does not have result constraint`,
120
+ };
121
+ };
122
+
123
+ export const fetchResultInCurrentSet = (currentSet: number, opticOddsScoresApiResponse: ScoresObject) => {
124
+ let currentHomeGameScore = 0;
125
+ let currentAwayGameScore = 0;
126
+ switch (currentSet) {
127
+ case 1:
128
+ currentHomeGameScore = Number(opticOddsScoresApiResponse.homePeriod1);
129
+ currentAwayGameScore = Number(opticOddsScoresApiResponse.awayPeriod1);
130
+ break;
131
+ case 2:
132
+ currentHomeGameScore = Number(opticOddsScoresApiResponse.homePeriod2);
133
+ currentAwayGameScore = Number(opticOddsScoresApiResponse.awayPeriod2);
134
+ break;
135
+ case 3:
136
+ currentHomeGameScore = Number(opticOddsScoresApiResponse.homePeriod3);
137
+ currentAwayGameScore = Number(opticOddsScoresApiResponse.awayPeriod3);
138
+ break;
139
+ case 4:
140
+ currentHomeGameScore = Number(opticOddsScoresApiResponse.homePeriod4);
141
+ currentAwayGameScore = Number(opticOddsScoresApiResponse.awayPeriod4);
142
+ break;
143
+ case 5:
144
+ currentHomeGameScore = Number(opticOddsScoresApiResponse.homePeriod5);
145
+ currentAwayGameScore = Number(opticOddsScoresApiResponse.awayPeriod5);
146
+ break;
147
+ }
148
+ return { home: currentHomeGameScore, away: currentAwayGameScore };
149
+ };
150
+
151
+ const checkResultConstraint = (homeTeam, awayTeam, currentResultInSet, currentSetsWon, setThreshold, resultLimit) => {
152
+ if (Number(currentSetsWon.home) == setThreshold || Number(currentSetsWon.away) == setThreshold) {
153
+ if (Number(currentSetsWon.home) == setThreshold && currentResultInSet.home >= resultLimit) {
154
+ return {
155
+ allow: false,
156
+ message: `Blocking game ${homeTeam} - ${awayTeam} due to current result: ${currentSetsWon.home} - ${currentSetsWon.away} (${currentResultInSet.home} - ${currentResultInSet.away})`,
157
+ };
158
+ }
159
+
160
+ if (Number(currentSetsWon.away) == setThreshold && currentResultInSet.away >= resultLimit) {
161
+ return {
162
+ allow: false,
163
+ message: `Blocking game ${homeTeam} - ${awayTeam} due to current result: ${currentSetsWon.home} - ${currentSetsWon.away} (${currentResultInSet.home} - ${currentResultInSet.away})`,
164
+ };
165
+ }
166
+ return {
167
+ allow: true,
168
+ message: '',
169
+ currentHomeGameScore: currentResultInSet.home,
170
+ currentAwayGameScore: currentResultInSet.away,
171
+ };
172
+ }
173
+ return {
174
+ allow: true,
175
+ message: '',
176
+ currentHomeGameScore: currentResultInSet.home,
177
+ currentAwayGameScore: currentResultInSet.away,
178
+ };
179
+ };
180
+
181
+ const VOLLEYBALL_SET_THRESHOLD = 2;
182
+ const VOLLEYBALL_POINTS_LIMIT = 20;
183
+ const VOLLEYBALL_FIFTH_SET_POINTS_LIMIT = 10;
184
+ const TENNIS_ATP_GRAND_SLAM_SET_THRESHOLD = 2;
185
+ const TENNIS_MASTERS_SET_THRESHOLD = 1;
186
+ const TENNIS_GEMS_LIMIT = 5;
@@ -1,88 +1,88 @@
1
- import { LEAGUES_NO_FORMAL_HOME_AWAY } from '../constants/sports';
2
- import { Sport } from '../enums/sports';
3
- import { getLeagueSport } from './sports';
4
-
5
- export const teamNamesMatching = (
6
- leagueId: number,
7
- marketHomeTeam: string,
8
- marketAwayTeam: string,
9
- apiHomeTeam: string,
10
- apiAwayTeam: string,
11
- teamsMap: Map<string, string>
12
- ) => {
13
- let homeTeamsMatch;
14
- let awayTeamsMatch;
15
-
16
- if (LEAGUES_NO_FORMAL_HOME_AWAY.includes(leagueId)) {
17
- homeTeamsMatch =
18
- apiHomeTeam.toLowerCase() == marketHomeTeam.toLowerCase() ||
19
- apiHomeTeam.toLowerCase() == marketAwayTeam.toLowerCase();
20
- awayTeamsMatch =
21
- apiAwayTeam.toLowerCase() == marketHomeTeam.toLowerCase() ||
22
- apiAwayTeam.toLowerCase() == marketAwayTeam.toLowerCase();
23
- } else {
24
- homeTeamsMatch = apiHomeTeam.toLowerCase() == marketHomeTeam.toLowerCase();
25
- awayTeamsMatch = apiAwayTeam.toLowerCase() == marketAwayTeam.toLowerCase();
26
- }
27
-
28
- if (homeTeamsMatch !== true) {
29
- const homeTeamOpticOdds = teamsMap.get(apiHomeTeam.toLowerCase());
30
- const gameHomeTeam = teamsMap.get(marketHomeTeam.toLowerCase());
31
- const gameAwayTeam = teamsMap.get(marketAwayTeam.toLowerCase());
32
- const hasUndefinedName = [homeTeamOpticOdds, gameHomeTeam].some((name) => name == undefined);
33
-
34
- if (hasUndefinedName) {
35
- return false;
36
- }
37
-
38
- if (LEAGUES_NO_FORMAL_HOME_AWAY.includes(leagueId)) {
39
- homeTeamsMatch = homeTeamOpticOdds == gameHomeTeam || homeTeamOpticOdds == gameAwayTeam;
40
- } else {
41
- homeTeamsMatch = homeTeamOpticOdds == gameHomeTeam;
42
- }
43
- }
44
-
45
- if (awayTeamsMatch !== true) {
46
- const awayTeamOpticOdds = teamsMap.get(apiAwayTeam.toLowerCase());
47
- const gameHomeTeam = teamsMap.get(marketHomeTeam.toLowerCase());
48
- const gameAwayTeam = teamsMap.get(marketAwayTeam.toLowerCase());
49
-
50
- const hasUndefinedName = [awayTeamOpticOdds, gameAwayTeam].some((name) => name == undefined);
51
-
52
- if (hasUndefinedName) {
53
- return false;
54
- }
55
-
56
- if (LEAGUES_NO_FORMAL_HOME_AWAY.includes(leagueId)) {
57
- awayTeamsMatch = awayTeamOpticOdds == gameHomeTeam || awayTeamOpticOdds == gameAwayTeam;
58
- } else {
59
- awayTeamsMatch = awayTeamOpticOdds == gameAwayTeam;
60
- }
61
- }
62
-
63
- return homeTeamsMatch && awayTeamsMatch;
64
- };
65
-
66
- export const gamesDatesMatching = (
67
- marketMaturityDate: Date,
68
- apiStartDate: Date,
69
- sportId: number,
70
- tennisDifferenceEnvVariable: number
71
- ) => {
72
- let datesMatch;
73
- const marketSport = getLeagueSport(sportId);
74
- if (marketSport == Sport.TENNIS) {
75
- const opticOddsTimestamp = apiStartDate.getTime();
76
- const marketTimestamp = marketMaturityDate.getTime();
77
- const differenceBetweenDates = Math.abs(marketTimestamp - opticOddsTimestamp);
78
- if (differenceBetweenDates <= Number(tennisDifferenceEnvVariable * 60 * 1000)) {
79
- datesMatch = true;
80
- } else {
81
- datesMatch = false;
82
- }
83
- } else {
84
- datesMatch = apiStartDate.toUTCString() == marketMaturityDate.toUTCString();
85
- }
86
-
87
- return datesMatch;
88
- };
1
+ import { LEAGUES_NO_FORMAL_HOME_AWAY } from '../constants/sports';
2
+ import { Sport } from '../enums/sports';
3
+ import { getLeagueSport } from './sports';
4
+
5
+ export const teamNamesMatching = (
6
+ leagueId: number,
7
+ marketHomeTeam: string,
8
+ marketAwayTeam: string,
9
+ apiHomeTeam: string,
10
+ apiAwayTeam: string,
11
+ teamsMap: Map<string, string>
12
+ ) => {
13
+ let homeTeamsMatch;
14
+ let awayTeamsMatch;
15
+
16
+ if (LEAGUES_NO_FORMAL_HOME_AWAY.includes(leagueId)) {
17
+ homeTeamsMatch =
18
+ apiHomeTeam.toLowerCase() == marketHomeTeam.toLowerCase() ||
19
+ apiHomeTeam.toLowerCase() == marketAwayTeam.toLowerCase();
20
+ awayTeamsMatch =
21
+ apiAwayTeam.toLowerCase() == marketHomeTeam.toLowerCase() ||
22
+ apiAwayTeam.toLowerCase() == marketAwayTeam.toLowerCase();
23
+ } else {
24
+ homeTeamsMatch = apiHomeTeam.toLowerCase() == marketHomeTeam.toLowerCase();
25
+ awayTeamsMatch = apiAwayTeam.toLowerCase() == marketAwayTeam.toLowerCase();
26
+ }
27
+
28
+ if (homeTeamsMatch !== true) {
29
+ const homeTeamOpticOdds = teamsMap.get(apiHomeTeam.toLowerCase());
30
+ const gameHomeTeam = teamsMap.get(marketHomeTeam.toLowerCase());
31
+ const gameAwayTeam = teamsMap.get(marketAwayTeam.toLowerCase());
32
+ const hasUndefinedName = [homeTeamOpticOdds, gameHomeTeam].some((name) => name == undefined);
33
+
34
+ if (hasUndefinedName) {
35
+ return false;
36
+ }
37
+
38
+ if (LEAGUES_NO_FORMAL_HOME_AWAY.includes(leagueId)) {
39
+ homeTeamsMatch = homeTeamOpticOdds == gameHomeTeam || homeTeamOpticOdds == gameAwayTeam;
40
+ } else {
41
+ homeTeamsMatch = homeTeamOpticOdds == gameHomeTeam;
42
+ }
43
+ }
44
+
45
+ if (awayTeamsMatch !== true) {
46
+ const awayTeamOpticOdds = teamsMap.get(apiAwayTeam.toLowerCase());
47
+ const gameHomeTeam = teamsMap.get(marketHomeTeam.toLowerCase());
48
+ const gameAwayTeam = teamsMap.get(marketAwayTeam.toLowerCase());
49
+
50
+ const hasUndefinedName = [awayTeamOpticOdds, gameAwayTeam].some((name) => name == undefined);
51
+
52
+ if (hasUndefinedName) {
53
+ return false;
54
+ }
55
+
56
+ if (LEAGUES_NO_FORMAL_HOME_AWAY.includes(leagueId)) {
57
+ awayTeamsMatch = awayTeamOpticOdds == gameHomeTeam || awayTeamOpticOdds == gameAwayTeam;
58
+ } else {
59
+ awayTeamsMatch = awayTeamOpticOdds == gameAwayTeam;
60
+ }
61
+ }
62
+
63
+ return homeTeamsMatch && awayTeamsMatch;
64
+ };
65
+
66
+ export const gamesDatesMatching = (
67
+ marketMaturityDate: Date,
68
+ apiStartDate: Date,
69
+ sportId: number,
70
+ tennisDifferenceEnvVariable: number
71
+ ) => {
72
+ let datesMatch;
73
+ const marketSport = getLeagueSport(sportId);
74
+ if (marketSport == Sport.TENNIS) {
75
+ const opticOddsTimestamp = apiStartDate.getTime();
76
+ const marketTimestamp = marketMaturityDate.getTime();
77
+ const differenceBetweenDates = Math.abs(marketTimestamp - opticOddsTimestamp);
78
+ if (differenceBetweenDates <= Number(tennisDifferenceEnvVariable * 60 * 1000)) {
79
+ datesMatch = true;
80
+ } else {
81
+ datesMatch = false;
82
+ }
83
+ } else {
84
+ datesMatch = apiStartDate.toUTCString() == marketMaturityDate.toUTCString();
85
+ }
86
+
87
+ return datesMatch;
88
+ };