overtime-live-trading-utils 2.1.16 → 2.1.18
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/.circleci/config.yml +32 -32
- package/.prettierrc +9 -9
- package/CLAUDE.md +77 -0
- package/codecov.yml +20 -20
- package/index.ts +26 -16
- package/jest.config.ts +16 -16
- package/main.js +1 -1
- package/package.json +30 -30
- package/resolution_live_markets.md +351 -0
- package/src/constants/common.ts +7 -7
- package/src/constants/errors.ts +6 -6
- package/src/constants/sports.ts +78 -78
- package/src/enums/sports.ts +109 -109
- package/src/tests/mock/MockLeagueMap.ts +170 -159
- package/src/tests/mock/MockOpticOddsEvents.ts +518 -0
- package/src/tests/mock/MockOpticSoccer.ts +9378 -9342
- package/src/tests/mock/MockSoccerRedis.ts +2308 -2308
- package/src/tests/unit/bookmakers.test.ts +79 -79
- package/src/tests/unit/markets.test.ts +156 -152
- package/src/tests/unit/odds.test.ts +92 -92
- package/src/tests/unit/resolution.test.ts +1043 -0
- package/src/tests/unit/sports.test.ts +58 -58
- package/src/tests/unit/spread.test.ts +131 -131
- package/src/types/missing-types.d.ts +2 -2
- package/src/types/odds.ts +61 -61
- package/src/types/resolution.ts +78 -0
- package/src/types/sports.ts +19 -19
- package/src/utils/bookmakers.ts +159 -159
- package/src/utils/constraints.ts +210 -210
- package/src/utils/gameMatching.ts +81 -81
- package/src/utils/markets.ts +119 -119
- package/src/utils/odds.ts +674 -674
- package/src/utils/opticOdds.ts +71 -71
- package/src/utils/resolution.ts +221 -0
- package/src/utils/sports.ts +51 -51
- package/src/utils/spread.ts +97 -97
- package/tsconfig.json +16 -16
- package/webpack.config.js +24 -24
package/.circleci/config.yml
CHANGED
|
@@ -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,77 @@
|
|
|
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
|
+
- `npm run compile` - Compile TypeScript to JavaScript
|
|
13
|
+
- `npm run pack` - Build production bundle with webpack
|
|
14
|
+
|
|
15
|
+
### Testing
|
|
16
|
+
- `npm test` - Run all Jest tests
|
|
17
|
+
- `npm test -- --coverage` - Run tests with coverage report
|
|
18
|
+
- `npm test -- src/tests/unit/odds.test.ts` - Run a specific test file
|
|
19
|
+
|
|
20
|
+
### Development
|
|
21
|
+
The library is published to npm. Run `npm run prepublish` to pack before publishing (runs automatically on npm publish).
|
|
22
|
+
|
|
23
|
+
## Architecture
|
|
24
|
+
|
|
25
|
+
### Core Processing Flow
|
|
26
|
+
|
|
27
|
+
The main processing pipeline:
|
|
28
|
+
1. **Bookmaker Selection** (`src/utils/bookmakers.ts`) - Selects primary/secondary/tertiary bookmakers for a sport, validates odds consistency across providers
|
|
29
|
+
2. **Odds Processing** (`src/utils/odds.ts`) - Converts odds formats (decimal ↔ implied probability), filters by market type and bookmaker, creates parent moneyline odds
|
|
30
|
+
3. **Spread Adjustment** (`src/utils/spread.ts`) - Applies spread data to odds, handles Asian handicap, game/point/goal spreads, run/puck lines
|
|
31
|
+
4. **Market Generation** (`src/utils/markets.ts`) - Main `processMarket()` function orchestrates the pipeline: gets moneyline odds → applies spread → creates child markets
|
|
32
|
+
5. **Child Markets** (`src/utils/odds.ts`) - Generates derivative markets (spreads, totals, double chance, correct score) from parent moneyline odds
|
|
33
|
+
|
|
34
|
+
### Key Concepts
|
|
35
|
+
|
|
36
|
+
**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`.
|
|
37
|
+
|
|
38
|
+
**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.
|
|
39
|
+
|
|
40
|
+
**Odds Validation**: The `checkOddsFromBookmakers()` function compares odds from multiple bookmakers using implied probability differences to detect discrepancies that might indicate stale or incorrect data.
|
|
41
|
+
|
|
42
|
+
**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.
|
|
43
|
+
|
|
44
|
+
### Type System
|
|
45
|
+
|
|
46
|
+
Key types in `src/types/`:
|
|
47
|
+
- `OddsObject` - Complete game data with odds array from API
|
|
48
|
+
- `Odds` - Array of individual odds entries with bookmaker, price, market name
|
|
49
|
+
- `LeagueConfigInfo` - League/market configuration (enabled status, min/max odds, spread)
|
|
50
|
+
- `ChildMarket` - Generated derivative market with line and odds
|
|
51
|
+
- `Fixture` & `ScoresObject` - Game metadata and live scores
|
|
52
|
+
|
|
53
|
+
### Sports-Specific Logic
|
|
54
|
+
|
|
55
|
+
`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`).
|
|
56
|
+
|
|
57
|
+
### Error Handling
|
|
58
|
+
|
|
59
|
+
Error messages in `src/constants/errors.ts`:
|
|
60
|
+
- `NO_MATCHING_BOOKMAKERS_MESSAGE` - None of the specified bookmakers have odds
|
|
61
|
+
- `DIFF_BETWEEN_BOOKMAKERS_MESSAGE` - Bookmaker odds diverge beyond threshold
|
|
62
|
+
- `ZERO_ODDS_MESSAGE` - Zero odds detected (invalid)
|
|
63
|
+
- `ZERO_ODDS_AFTER_SPREAD_ADJUSTMENT` - Spread adjustment resulted in zero odds
|
|
64
|
+
|
|
65
|
+
## Testing Notes
|
|
66
|
+
|
|
67
|
+
Tests use mock data from `src/tests/mock/`:
|
|
68
|
+
- `MockLeagueMap.ts` - League configuration fixtures
|
|
69
|
+
- `MockOpticSoccer.ts` - Sample OpticOdds API responses
|
|
70
|
+
- `MockSoccerRedis.ts` - Redis-cached odds data
|
|
71
|
+
|
|
72
|
+
Test files are organized by utility module: `odds.test.ts`, `sports.test.ts`, `spread.test.ts`, `markets.test.ts`, `bookmakers.test.ts`.
|
|
73
|
+
|
|
74
|
+
## Dependencies
|
|
75
|
+
|
|
76
|
+
- `oddslib` - Odds format conversion (decimal, moneyline, implied probability)
|
|
77
|
+
- `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,16 +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/
|
|
9
|
-
export * from './src/utils/
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
export * from './src/constants/
|
|
14
|
-
export * from './src/constants/
|
|
15
|
-
|
|
16
|
-
|
|
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;
|