overtime-live-trading-utils 2.0.57 → 2.1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "overtime-live-trading-utils",
3
- "version": "2.0.57",
3
+ "version": "2.1.0",
4
4
  "description": "",
5
5
  "main": "main.js",
6
6
  "scripts": {
@@ -13,9 +13,8 @@
13
13
  "license": "MIT",
14
14
  "dependencies": {
15
15
  "@types/node": "^20.8.10",
16
- "bytes32": "^0.0.3",
17
16
  "oddslib": "^2.1.1",
18
- "overtime-utils": "^0.0.102",
17
+ "overtime-utils": "^0.1.0",
19
18
  "react": "^17.0.1"
20
19
  },
21
20
  "devDependencies": {
@@ -5,6 +5,3 @@ export const MIN_ODDS_FOR_DIFF_CHECKING = 0.2;
5
5
  export const TAG_CHILD_SPREAD = 10001;
6
6
  export const TAG_CHILD_TOTALS = 10002;
7
7
  export const MULTIPLIER_100 = 100;
8
-
9
- export const OPTIC_ODDS_ID_SEPARATOR = ':';
10
- export const OVERTIME_ID_SEPARATOR = '_';
@@ -1,2 +1 @@
1
1
  declare module 'oddslib';
2
- declare module 'bytes32';
@@ -1,6 +1,3 @@
1
- import bytes32 from 'bytes32';
2
- import { getLeagueOpticOddsName, LeagueMap } from 'overtime-utils';
3
- import { OPTIC_ODDS_ID_SEPARATOR, OVERTIME_ID_SEPARATOR } from '../constants/common';
4
1
  import { Fixture, OddsObject, ScoresObject } from '../types/odds';
5
2
 
6
3
  export const mapOpticOddsApiFixtures = (fixturesData: any[]): Fixture[] =>
@@ -72,42 +69,3 @@ const mapScorePeriods = (periods: any, homeAwayType: string) =>
72
69
  [`${homeAwayType}Period${periodKey}`]: periodValue,
73
70
  };
74
71
  }, {});
75
-
76
- export const convertFromBytes32 = (value: string) => {
77
- const result = bytes32({ input: value });
78
- return result.replace(/\0/g, '');
79
- };
80
-
81
- export const formatOpticOddsLeagueName = (leagueName: string) => leagueName.replaceAll(' ', '_').toLowerCase();
82
-
83
- export const mapFromOpticOddsToOvertimeFormat = (fixtureId: string) => {
84
- if (!fixtureId.includes(OPTIC_ODDS_ID_SEPARATOR)) {
85
- return fixtureId;
86
- }
87
- const [leagueName, id] = fixtureId.split(OPTIC_ODDS_ID_SEPARATOR);
88
- const overtimeLeagueId = Object.values(LeagueMap).find(
89
- (league) => formatOpticOddsLeagueName(league.opticOddsName || '') === leagueName
90
- )?.id;
91
- if (!overtimeLeagueId) {
92
- throw `Optic Odds league ${leagueName} not mapped.`;
93
- }
94
- return `${overtimeLeagueId}${OVERTIME_ID_SEPARATOR}${id}`;
95
- };
96
-
97
- export const mapFromOvertimeToOpticOddsFormat = (gameId: string) => {
98
- if (!gameId.includes(OVERTIME_ID_SEPARATOR)) {
99
- return gameId;
100
- }
101
- const [leagueId, id] = gameId.split(OVERTIME_ID_SEPARATOR);
102
- const opticOddsLeagueName = getLeagueOpticOddsName(Number(leagueId));
103
- if (!opticOddsLeagueName) {
104
- throw `Overtime league ID ${leagueId} not mapped.`;
105
- }
106
- return `${formatOpticOddsLeagueName(opticOddsLeagueName)}${OPTIC_ODDS_ID_SEPARATOR}${id}`;
107
- };
108
-
109
- export const mapFromOpticOddsFormatToBytes32 = (fixtureId: string) =>
110
- bytes32({ input: mapFromOpticOddsToOvertimeFormat(fixtureId) });
111
-
112
- export const mapFromBytes32ToOpticOddsFormat = (gameId: string) =>
113
- mapFromOvertimeToOpticOddsFormat(convertFromBytes32(gameId));
@@ -1,296 +0,0 @@
1
- import {
2
- mapFromOpticOddsToOvertimeFormat,
3
- formatOpticOddsLeagueName,
4
- mapFromOvertimeToOpticOddsFormat,
5
- mapFromOpticOddsFormatToBytes32,
6
- mapFromBytes32ToOpticOddsFormat,
7
- convertFromBytes32
8
- } from '../../utils/opticOdds';
9
- import { OPTIC_ODDS_ID_SEPARATOR, OVERTIME_ID_SEPARATOR } from '../../constants/common';
10
-
11
- // Mock the overtime-utils module
12
- jest.mock('overtime-utils', () => ({
13
- LeagueMap: {
14
- 9002: {
15
- id: 9002,
16
- name: 'Premier League',
17
- opticOddsName: 'English Premier League',
18
- },
19
- 9001: {
20
- id: 9001,
21
- name: 'Bundesliga',
22
- opticOddsName: 'German Bundesliga',
23
- },
24
- 9003: {
25
- id: 9003,
26
- name: 'La Liga',
27
- opticOddsName: 'Spanish La Liga',
28
- },
29
- 9005: {
30
- id: 9005,
31
- name: 'Champions League',
32
- opticOddsName: 'UEFA Champions League',
33
- },
34
- 9006: {
35
- id: 9006,
36
- name: 'NBA',
37
- opticOddsName: 'National Basketball Association',
38
- }
39
- },
40
- getLeagueOpticOddsName: jest.fn((leagueId: number) => {
41
- const leagueMap: { [key: number]: string } = {
42
- 9002: 'English Premier League',
43
- 9001: 'German Bundesliga',
44
- 9003: 'Spanish La Liga',
45
- 9005: 'UEFA Champions League',
46
- 9006: 'National Basketball Association',
47
- };
48
- return leagueMap[leagueId];
49
- }),
50
- }));
51
-
52
- // Mock bytes32 module
53
- jest.mock('bytes32', () => {
54
- return jest.fn((options: { input: string }) => {
55
- // Simple mock that converts string to a padded format
56
- const paddedString = options.input.padEnd(32, '\0');
57
- return paddedString;
58
- });
59
- });
60
-
61
- describe('OpticOdds Utils', () => {
62
- beforeEach(() => {
63
- jest.clearAllMocks();
64
- });
65
-
66
- describe('formatOpticOddsLeagueName', () => {
67
- it('should convert spaces to underscores and make lowercase', () => {
68
- expect(formatOpticOddsLeagueName('English Premier League')).toBe('english_premier_league');
69
- expect(formatOpticOddsLeagueName('UEFA Champions League')).toBe('uefa_champions_league');
70
- expect(formatOpticOddsLeagueName('German Bundesliga')).toBe('german_bundesliga');
71
- });
72
-
73
- it('should handle empty string', () => {
74
- expect(formatOpticOddsLeagueName('')).toBe('');
75
- });
76
-
77
- it('should handle single words', () => {
78
- expect(formatOpticOddsLeagueName('NBA')).toBe('nba');
79
- });
80
- });
81
-
82
- describe('mapFromOpticOddsToOvertimeFormat', () => {
83
- describe('when fixture ID does not contain separator', () => {
84
- it('should return the fixture ID unchanged', () => {
85
- const fixtureId = 'simple-fixture-id-123';
86
- const result = mapFromOpticOddsToOvertimeFormat(fixtureId);
87
- expect(result).toBe(fixtureId);
88
- });
89
-
90
- it('should return numeric fixture ID unchanged', () => {
91
- const fixtureId = '12345';
92
- const result = mapFromOpticOddsToOvertimeFormat(fixtureId);
93
- expect(result).toBe(fixtureId);
94
- });
95
- });
96
-
97
- describe('when fixture ID contains separator and league is mapped', () => {
98
- it('should convert Premier League fixture ID correctly', () => {
99
- const leagueName = formatOpticOddsLeagueName('English Premier League');
100
- const fixtureId = `${leagueName}${OPTIC_ODDS_ID_SEPARATOR}12345`;
101
- const result = mapFromOpticOddsToOvertimeFormat(fixtureId);
102
- expect(result).toBe(`9002${OVERTIME_ID_SEPARATOR}12345`);
103
- });
104
-
105
- it('should convert Bundesliga fixture ID correctly', () => {
106
- const leagueName = formatOpticOddsLeagueName('German Bundesliga');
107
- const fixtureId = `${leagueName}${OPTIC_ODDS_ID_SEPARATOR}67890`;
108
- const result = mapFromOpticOddsToOvertimeFormat(fixtureId);
109
- expect(result).toBe(`9001${OVERTIME_ID_SEPARATOR}67890`);
110
- });
111
-
112
- it('should convert Champions League fixture ID correctly', () => {
113
- const leagueName = formatOpticOddsLeagueName('UEFA Champions League');
114
- const fixtureId = `${leagueName}${OPTIC_ODDS_ID_SEPARATOR}match-001`;
115
- const result = mapFromOpticOddsToOvertimeFormat(fixtureId);
116
- expect(result).toBe(`9005${OVERTIME_ID_SEPARATOR}match-001`);
117
- });
118
- });
119
-
120
- describe('when fixture ID contains separator but league is not mapped', () => {
121
- it('should throw error for unmapped league name', () => {
122
- const unmappedLeague = 'unknown_league';
123
- const fixtureId = `${unmappedLeague}${OPTIC_ODDS_ID_SEPARATOR}12345`;
124
-
125
- expect(() => {
126
- mapFromOpticOddsToOvertimeFormat(fixtureId);
127
- }).toThrow('Optic Odds league unknown_league not mapped.');
128
- });
129
-
130
- it('should throw error for empty league name', () => {
131
- const fixtureId = `${OPTIC_ODDS_ID_SEPARATOR}12345`;
132
-
133
- expect(() => {
134
- mapFromOpticOddsToOvertimeFormat(fixtureId);
135
- }).toThrow('Optic Odds league not mapped.');
136
- });
137
- });
138
- });
139
-
140
- describe('mapFromOvertimeToOpticOddsFormat', () => {
141
- describe('when game ID does not contain separator', () => {
142
- it('should return the game ID unchanged', () => {
143
- const gameId = 'simple-game-id-123';
144
- const result = mapFromOvertimeToOpticOddsFormat(gameId);
145
- expect(result).toBe(gameId);
146
- });
147
-
148
- it('should return numeric game ID unchanged', () => {
149
- const gameId = '12345';
150
- const result = mapFromOvertimeToOpticOddsFormat(gameId);
151
- expect(result).toBe(gameId);
152
- });
153
- });
154
-
155
- describe('when game ID contains separator and league is mapped', () => {
156
- it('should convert Premier League game ID correctly', () => {
157
- const gameId = `9002${OVERTIME_ID_SEPARATOR}12345`;
158
- const result = mapFromOvertimeToOpticOddsFormat(gameId);
159
- const expectedLeagueName = formatOpticOddsLeagueName('English Premier League');
160
- expect(result).toBe(`${expectedLeagueName}${OPTIC_ODDS_ID_SEPARATOR}12345`);
161
- });
162
-
163
- it('should convert Bundesliga game ID correctly', () => {
164
- const gameId = `9001${OVERTIME_ID_SEPARATOR}67890`;
165
- const result = mapFromOvertimeToOpticOddsFormat(gameId);
166
- const expectedLeagueName = formatOpticOddsLeagueName('German Bundesliga');
167
- expect(result).toBe(`${expectedLeagueName}${OPTIC_ODDS_ID_SEPARATOR}67890`);
168
- });
169
-
170
- it('should convert Champions League game ID correctly', () => {
171
- const gameId = `9005${OVERTIME_ID_SEPARATOR}match-001`;
172
- const result = mapFromOvertimeToOpticOddsFormat(gameId);
173
- const expectedLeagueName = formatOpticOddsLeagueName('UEFA Champions League');
174
- expect(result).toBe(`${expectedLeagueName}${OPTIC_ODDS_ID_SEPARATOR}match-001`);
175
- });
176
- });
177
-
178
- describe('when game ID contains separator but league is not mapped', () => {
179
- it('should throw error for unmapped league ID', () => {
180
- const gameId = `9999${OVERTIME_ID_SEPARATOR}12345`;
181
-
182
- expect(() => {
183
- mapFromOvertimeToOpticOddsFormat(gameId);
184
- }).toThrow('Overtime league ID 9999 not mapped.');
185
- });
186
-
187
- it('should throw error for invalid league ID', () => {
188
- const gameId = `invalid${OVERTIME_ID_SEPARATOR}12345`;
189
-
190
- expect(() => {
191
- mapFromOvertimeToOpticOddsFormat(gameId);
192
- }).toThrow('Overtime league ID invalid not mapped.');
193
- });
194
- });
195
- });
196
-
197
- describe('convertFromBytes32', () => {
198
- it('should remove null characters from bytes32 string', () => {
199
- const input = 'test\0\0\0\0';
200
- const result = convertFromBytes32(input);
201
- expect(result).toBe('test');
202
- });
203
-
204
- it('should handle string without null characters', () => {
205
- const input = 'teststring';
206
- const result = convertFromBytes32(input);
207
- expect(result).toBe('teststring');
208
- });
209
-
210
- it('should handle empty string', () => {
211
- const input = '';
212
- const result = convertFromBytes32(input);
213
- expect(result).toBe('');
214
- });
215
- });
216
-
217
- describe('mapFromOpticOddsFormatToBytes32', () => {
218
- it('should convert optic odds format to bytes32', () => {
219
- const leagueName = formatOpticOddsLeagueName('English Premier League');
220
- const fixtureId = `${leagueName}${OPTIC_ODDS_ID_SEPARATOR}12345`;
221
- const result = mapFromOpticOddsFormatToBytes32(fixtureId);
222
-
223
- // Should first convert to overtime format, then to bytes32
224
- const expectedOvertimeFormat = `9002${OVERTIME_ID_SEPARATOR}12345`;
225
- const expectedBytes32 = expectedOvertimeFormat.padEnd(32, '\0');
226
- expect(result).toBe(expectedBytes32);
227
- });
228
-
229
- it('should handle fixture ID without separator', () => {
230
- const fixtureId = '12345';
231
- const result = mapFromOpticOddsFormatToBytes32(fixtureId);
232
-
233
- const expectedBytes32 = fixtureId.padEnd(32, '\0');
234
- expect(result).toBe(expectedBytes32);
235
- });
236
- });
237
-
238
- describe('mapFromBytes32ToOpticOddsFormat', () => {
239
- it('should convert bytes32 to optic odds format', () => {
240
- const overtimeFormat = `9002${OVERTIME_ID_SEPARATOR}12345`;
241
- const bytes32Input = overtimeFormat.padEnd(32, '\0');
242
- const result = mapFromBytes32ToOpticOddsFormat(bytes32Input);
243
-
244
- const expectedLeagueName = formatOpticOddsLeagueName('English Premier League');
245
- const expectedResult = `${expectedLeagueName}${OPTIC_ODDS_ID_SEPARATOR}12345`;
246
- expect(result).toBe(expectedResult);
247
- });
248
-
249
- it('should handle bytes32 without separator', () => {
250
- const gameId = '12345';
251
- const bytes32Input = gameId.padEnd(32, '\0');
252
- const result = mapFromBytes32ToOpticOddsFormat(bytes32Input);
253
-
254
- expect(result).toBe(gameId);
255
- });
256
- });
257
-
258
- describe('integration tests', () => {
259
- it('should convert from optic odds to bytes32 and back', () => {
260
- const leagueName = formatOpticOddsLeagueName('English Premier League');
261
- const originalFixtureId = `${leagueName}${OPTIC_ODDS_ID_SEPARATOR}12345`;
262
-
263
- // Convert to bytes32
264
- const bytes32Result = mapFromOpticOddsFormatToBytes32(originalFixtureId);
265
-
266
- // Convert back to optic odds format
267
- const backToOpticOdds = mapFromBytes32ToOpticOddsFormat(bytes32Result);
268
-
269
- expect(backToOpticOdds).toBe(originalFixtureId);
270
- });
271
-
272
- it('should convert between optic odds and overtime formats', () => {
273
- const leagueName = formatOpticOddsLeagueName('German Bundesliga');
274
- const opticOddsId = `${leagueName}${OPTIC_ODDS_ID_SEPARATOR}67890`;
275
-
276
- // Convert to overtime format
277
- const overtimeFormat = mapFromOpticOddsToOvertimeFormat(opticOddsId);
278
- expect(overtimeFormat).toBe(`9001${OVERTIME_ID_SEPARATOR}67890`);
279
-
280
- // Convert back to optic odds format
281
- const backToOpticOdds = mapFromOvertimeToOpticOddsFormat(overtimeFormat);
282
- expect(backToOpticOdds).toBe(opticOddsId);
283
- });
284
-
285
- it('should handle round trip conversion with NBA league', () => {
286
- const leagueName = formatOpticOddsLeagueName('National Basketball Association');
287
- const originalId = `${leagueName}${OPTIC_ODDS_ID_SEPARATOR}game-456`;
288
-
289
- // Optic Odds -> Overtime -> Optic Odds
290
- const overtimeFormat = mapFromOpticOddsToOvertimeFormat(originalId);
291
- const backToOpticOdds = mapFromOvertimeToOpticOddsFormat(overtimeFormat);
292
-
293
- expect(backToOpticOdds).toBe(originalId);
294
- });
295
- });
296
- });