overtime-live-trading-utils 2.1.44 → 2.1.45

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 (39) hide show
  1. package/.circleci/config.yml +32 -32
  2. package/.prettierrc +9 -9
  3. package/CLAUDE.md +84 -0
  4. package/codecov.yml +20 -20
  5. package/index.ts +26 -26
  6. package/jest.config.ts +16 -16
  7. package/main.js +1 -1
  8. package/package.json +30 -30
  9. package/resolution_live_markets.md +356 -0
  10. package/src/constants/common.ts +7 -7
  11. package/src/constants/errors.ts +6 -6
  12. package/src/constants/sports.ts +78 -78
  13. package/src/enums/sports.ts +109 -109
  14. package/src/tests/mock/MockLeagueMap.ts +170 -170
  15. package/src/tests/mock/MockOpticOddsEvents.ts +662 -662
  16. package/src/tests/mock/MockOpticSoccer.ts +9378 -9378
  17. package/src/tests/mock/MockSoccerRedis.ts +2308 -2308
  18. package/src/tests/unit/bookmakers.test.ts +79 -79
  19. package/src/tests/unit/markets.test.ts +156 -156
  20. package/src/tests/unit/odds.test.ts +92 -92
  21. package/src/tests/unit/resolution.test.ts +1489 -1489
  22. package/src/tests/unit/sports.test.ts +58 -58
  23. package/src/tests/unit/spread.test.ts +131 -131
  24. package/src/types/missing-types.d.ts +2 -2
  25. package/src/types/odds.ts +61 -61
  26. package/src/types/resolution.ts +660 -656
  27. package/src/types/sports.ts +19 -19
  28. package/src/utils/bookmakers.ts +159 -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 +918 -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
@@ -1,32 +1,32 @@
1
- orbs: # declare what orbs we are going to use
2
- node: circleci/node@5.0.3 # the node orb provides common node-related configuration
3
- codecov: codecov/codecov@3.2.3
4
-
5
- version: 2.1 # using 2.1 provides access to orbs and other features
6
-
7
- executors:
8
- node-executor:
9
- docker:
10
- - image: circleci/node:17.0.1 # Specify the Node.js version you need
11
-
12
- jobs:
13
- test:
14
- executor: node-executor
15
- steps:
16
- - checkout # Check out the code from your repository
17
-
18
- - run:
19
- name: Install dependencies
20
- command: npm install
21
-
22
- - run:
23
- name: Run tests
24
- command: npm test -- --coverage
25
-
26
- - codecov/upload
27
-
28
- workflows:
29
- version: 2
30
- test:
31
- jobs:
32
- - test
1
+ orbs: # declare what orbs we are going to use
2
+ node: circleci/node@5.0.3 # the node orb provides common node-related configuration
3
+ codecov: codecov/codecov@3.2.3
4
+
5
+ version: 2.1 # using 2.1 provides access to orbs and other features
6
+
7
+ executors:
8
+ node-executor:
9
+ docker:
10
+ - image: circleci/node:17.0.1 # Specify the Node.js version you need
11
+
12
+ jobs:
13
+ test:
14
+ executor: node-executor
15
+ steps:
16
+ - checkout # Check out the code from your repository
17
+
18
+ - run:
19
+ name: Install dependencies
20
+ command: npm install
21
+
22
+ - run:
23
+ name: Run tests
24
+ command: npm test -- --coverage
25
+
26
+ - codecov/upload
27
+
28
+ workflows:
29
+ version: 2
30
+ test:
31
+ jobs:
32
+ - test
package/.prettierrc CHANGED
@@ -1,9 +1,9 @@
1
- {
2
- "singleQuote": true,
3
- "printWidth": 120,
4
- "tabWidth": 4,
5
- "useTabs": false,
6
- "trailingComma": "es5",
7
- "semi": true,
8
- "endOfLine": "auto"
9
- }
1
+ {
2
+ "singleQuote": true,
3
+ "printWidth": 120,
4
+ "tabWidth": 4,
5
+ "useTabs": false,
6
+ "trailingComma": "es5",
7
+ "semi": true,
8
+ "endOfLine": "auto"
9
+ }
package/CLAUDE.md ADDED
@@ -0,0 +1,84 @@
1
+ # CLAUDE.md
2
+
3
+ This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+ ## Project Overview
6
+
7
+ This is a TypeScript utility library for live sports betting/trading. It processes odds data from multiple bookmakers, applies spreads, validates odds consistency, and generates child markets for various bet types (moneyline, spreads, totals). The library is designed to work with the Overtime sports betting platform.
8
+
9
+ ## Commands
10
+
11
+ ### Build & Compile
12
+
13
+ - `npm run compile` - Compile TypeScript to JavaScript
14
+ - `npm run pack` - Build production bundle with webpack
15
+
16
+ ### Testing
17
+
18
+ - `npm test` - Run all Jest tests
19
+ - `npm test -- --coverage` - Run tests with coverage report
20
+ - `npm test -- src/tests/unit/odds.test.ts` - Run a specific test file
21
+
22
+ ### Development
23
+
24
+ The library is published to npm. Run `npm run prepublish` to pack before publishing (runs automatically on npm publish).
25
+
26
+ ## Architecture
27
+
28
+ ### Core Processing Flow
29
+
30
+ The main processing pipeline:
31
+
32
+ 1. **Bookmaker Selection** (`src/utils/bookmakers.ts`) - Selects primary/secondary/tertiary bookmakers for a sport, validates odds consistency across providers
33
+ 2. **Odds Processing** (`src/utils/odds.ts`) - Converts odds formats (decimal ↔ implied probability), filters by market type and bookmaker, creates parent moneyline odds
34
+ 3. **Spread Adjustment** (`src/utils/spread.ts`) - Applies spread data to odds, handles Asian handicap, game/point/goal spreads, run/puck lines
35
+ 4. **Market Generation** (`src/utils/markets.ts`) - Main `processMarket()` function orchestrates the pipeline: gets moneyline odds → applies spread → creates child markets
36
+ 5. **Child Markets** (`src/utils/odds.ts`) - Generates derivative markets (spreads, totals, double chance, correct score) from parent moneyline odds
37
+
38
+ ### Key Concepts
39
+
40
+ **League Configuration**: Each league (sport) has a configuration defining enabled bet types, min/max odds, and added spreads. The `LeagueConfigInfo` type stores this data, typically loaded from CSV files like `live-markets-map.csv`.
41
+
42
+ **Two vs Three-Positional Sports**: The library distinguishes between sports with 2 positions (tennis, esports - no draw) and 3 positions (soccer, hockey - draw possible). This affects odds validation and market generation.
43
+
44
+ **Odds Validation**: The `checkOddsFromBookmakers()` function compares odds from multiple bookmakers using implied probability differences to detect discrepancies that might indicate stale or incorrect data.
45
+
46
+ **OpticOdds Integration**: `src/utils/opticOdds.ts` provides utilities for working with the OpticOdds API format, including filtering odds by market name/bookmaker and handling team name matching.
47
+
48
+ ### Type System
49
+
50
+ Key types in `src/types/`:
51
+
52
+ - `OddsObject` - Complete game data with odds array from API
53
+ - `Odds` - Array of individual odds entries with bookmaker, price, market name
54
+ - `LeagueConfigInfo` - League/market configuration (enabled status, min/max odds, spread)
55
+ - `ChildMarket` - Generated derivative market with line and odds
56
+ - `Fixture` & `ScoresObject` - Game metadata and live scores
57
+
58
+ ### Sports-Specific Logic
59
+
60
+ `src/constants/sports.ts` defines leagues without formal home/away designation (esports, tennis). `src/enums/sports.ts` defines comprehensive tennis subleague mappings and market type enums (`MoneylineTypes`, `SpreadTypes`, `TotalTypes`).
61
+
62
+ ### Error Handling
63
+
64
+ Error messages in `src/constants/errors.ts`:
65
+
66
+ - `NO_MATCHING_BOOKMAKERS_MESSAGE` - None of the specified bookmakers have odds
67
+ - `DIFF_BETWEEN_BOOKMAKERS_MESSAGE` - Bookmaker odds diverge beyond threshold
68
+ - `ZERO_ODDS_MESSAGE` - Zero odds detected (invalid)
69
+ - `ZERO_ODDS_AFTER_SPREAD_ADJUSTMENT` - Spread adjustment resulted in zero odds
70
+
71
+ ## Testing Notes
72
+
73
+ Tests use mock data from `src/tests/mock/`:
74
+
75
+ - `MockLeagueMap.ts` - League configuration fixtures
76
+ - `MockOpticSoccer.ts` - Sample OpticOdds API responses
77
+ - `MockSoccerRedis.ts` - Redis-cached odds data
78
+
79
+ Test files are organized by utility module: `odds.test.ts`, `sports.test.ts`, `spread.test.ts`, `markets.test.ts`, `bookmakers.test.ts`.
80
+
81
+ ## Dependencies
82
+
83
+ - `oddslib` - Odds format conversion (decimal, moneyline, implied probability)
84
+ - `overtime-utils` - Shared types and enums for the Overtime platform (League enum, MarketType)
package/codecov.yml CHANGED
@@ -1,20 +1,20 @@
1
- # codecov.yml
2
-
3
- # Specify the coverage rules
4
- coverage:
5
- precision: 2 # Number of decimal places for coverage percentages
6
- round: down # Round coverage percentages down
7
- range: '70...100' # Expected range of coverage (useful for enforcing quality gates)
8
-
9
- # Adjust how Codecov processes reports
10
- comment:
11
- layout: 'reach, diff, flags' # Format of the PR comments
12
- behavior: default # Default behavior for comments
13
- require_changes: false # Only comment if changes occur in coverage
14
- branches:
15
- - main # Restrict comments to specific branches
16
-
17
- # Custom CI configuration (if needed)
18
- ci:
19
- - circleci # Specify CircleCI as the CI provider
20
-
1
+ # codecov.yml
2
+
3
+ # Specify the coverage rules
4
+ coverage:
5
+ precision: 2 # Number of decimal places for coverage percentages
6
+ round: down # Round coverage percentages down
7
+ range: '70...100' # Expected range of coverage (useful for enforcing quality gates)
8
+
9
+ # Adjust how Codecov processes reports
10
+ comment:
11
+ layout: 'reach, diff, flags' # Format of the PR comments
12
+ behavior: default # Default behavior for comments
13
+ require_changes: false # Only comment if changes occur in coverage
14
+ branches:
15
+ - main # Restrict comments to specific branches
16
+
17
+ # Custom CI configuration (if needed)
18
+ ci:
19
+ - circleci # Specify CircleCI as the CI provider
20
+
package/index.ts CHANGED
@@ -1,26 +1,26 @@
1
- //utils
2
- export * from './src/utils/bookmakers';
3
- export * from './src/utils/constraints';
4
- export * from './src/utils/gameMatching';
5
- export * from './src/utils/markets';
6
- export * from './src/utils/odds';
7
- export * from './src/utils/opticOdds';
8
- export * from './src/utils/resolution';
9
- export * from './src/utils/sports';
10
- export * from './src/utils/spread';
11
-
12
- // constants
13
- export * from './src/constants/common';
14
- export * from './src/constants/errors';
15
- export * from './src/constants/sports';
16
-
17
- export * from './src/enums/sports';
18
-
19
- // types
20
- export * from './src/types/resolution';
21
- export {
22
- HALVES_PERIOD_TYPE_ID_MAPPING,
23
- QUARTERS_PERIOD_TYPE_ID_MAPPING,
24
- INNINGS_PERIOD_TYPE_ID_MAPPING,
25
- FULL_GAME_TYPE_IDS,
26
- } from './src/types/resolution';
1
+ //utils
2
+ export * from './src/utils/bookmakers';
3
+ export * from './src/utils/constraints';
4
+ export * from './src/utils/gameMatching';
5
+ export * from './src/utils/markets';
6
+ export * from './src/utils/odds';
7
+ export * from './src/utils/opticOdds';
8
+ export * from './src/utils/resolution';
9
+ export * from './src/utils/sports';
10
+ export * from './src/utils/spread';
11
+
12
+ // constants
13
+ export * from './src/constants/common';
14
+ export * from './src/constants/errors';
15
+ export * from './src/constants/sports';
16
+
17
+ export * from './src/enums/sports';
18
+
19
+ // types
20
+ export * from './src/types/resolution';
21
+ export {
22
+ HALVES_PERIOD_TYPE_ID_MAPPING,
23
+ QUARTERS_PERIOD_TYPE_ID_MAPPING,
24
+ INNINGS_PERIOD_TYPE_ID_MAPPING,
25
+ FULL_GAME_TYPE_IDS,
26
+ } from './src/types/resolution';
package/jest.config.ts CHANGED
@@ -1,16 +1,16 @@
1
- import { JestConfigWithTsJest } from 'ts-jest';
2
-
3
- const config: JestConfigWithTsJest = {
4
- preset: 'ts-jest',
5
- testEnvironment: 'node',
6
- transform: {
7
- '^.+\\.tsx?$': 'ts-jest',
8
- },
9
- globals: {
10
- 'ts-jest': {
11
- useESM: true, // Optional if you are using ES modules
12
- },
13
- },
14
- };
15
-
16
- export default config;
1
+ import { JestConfigWithTsJest } from 'ts-jest';
2
+
3
+ const config: JestConfigWithTsJest = {
4
+ preset: 'ts-jest',
5
+ testEnvironment: 'node',
6
+ transform: {
7
+ '^.+\\.tsx?$': 'ts-jest',
8
+ },
9
+ globals: {
10
+ 'ts-jest': {
11
+ useESM: true, // Optional if you are using ES modules
12
+ },
13
+ },
14
+ };
15
+
16
+ export default config;