Codex commited on
Commit
f4ae272
·
1 Parent(s): 069236b

Allow strikeout book ladders in player odds

Browse files
Files changed (2) hide show
  1. src/market-scanner.js +18 -11
  2. test/market-scanner.test.js +77 -0
src/market-scanner.js CHANGED
@@ -2917,6 +2917,7 @@ const DIRECT_ODDS_MARKET_CONFIG = {
2917
  apiMarketType: 'pitcher_strikeouts',
2918
  circaMarketType: 'pitcher_strikeouts_generic',
2919
  preferredSide: 'over',
 
2920
  },
2921
  };
2922
 
@@ -3716,31 +3717,37 @@ export class MarketScanner {
3716
  ? decoratedEntries.filter((entry) => allowedBooks.includes(normalizeBookFilter(entry.book)))
3717
  : decoratedEntries;
3718
 
3719
- const primaryEntries = selectPrimaryBookEntries(scopedEntries, {
3720
- preferredSide: marketConfig.preferredSide,
3721
- preferredLine: marketConfig.preferredLine ?? null,
3722
- });
3723
-
3724
  const dedupedEntries = dedupeBy(
3725
- primaryEntries,
3726
- (entry) => `${normalizeBookFilter(entry.book) ?? entry.book}|${entry.side}|${entry.lineValue ?? 'na'}`,
3727
  );
3728
 
3729
  const filteredEntries = requestedBook
3730
  ? dedupedEntries.filter((entry) => normalizeBookFilter(entry.book) === requestedBook)
3731
- : dedupedEntries;
 
 
 
 
 
 
 
 
 
 
 
3732
 
3733
- if (filteredEntries.length === 0) {
3734
  throw new Error(requestedBook
3735
  ? `No ${requestedBook} ${marketConfig.marketLabel} odds were found for ${playerQuery}.`
3736
  : `No ${marketConfig.marketLabel} odds were found for ${playerQuery}.`);
3737
  }
3738
 
3739
- const canonicalName = filteredEntries[0].playerName;
3740
  return {
3741
  playerName: canonicalName,
3742
  marketLabel: marketConfig.marketLabel,
3743
- entries: filteredEntries,
3744
  bookFilter: requestedBook,
3745
  };
3746
  }
 
2917
  apiMarketType: 'pitcher_strikeouts',
2918
  circaMarketType: 'pitcher_strikeouts_generic',
2919
  preferredSide: 'over',
2920
+ includeBookLadders: true,
2921
  },
2922
  };
2923
 
 
3717
  ? decoratedEntries.filter((entry) => allowedBooks.includes(normalizeBookFilter(entry.book)))
3718
  : decoratedEntries;
3719
 
 
 
 
 
 
3720
  const dedupedEntries = dedupeBy(
3721
+ scopedEntries,
3722
+ (entry) => `${normalizeBookFilter(entry.book) ?? entry.book}|${entry.side}|${entry.lineValue ?? 'na'}|${entry.oddsInput}`,
3723
  );
3724
 
3725
  const filteredEntries = requestedBook
3726
  ? dedupedEntries.filter((entry) => normalizeBookFilter(entry.book) === requestedBook)
3727
+ : selectPrimaryBookEntries(dedupedEntries, {
3728
+ preferredSide: marketConfig.preferredSide,
3729
+ preferredLine: marketConfig.preferredLine ?? null,
3730
+ });
3731
+
3732
+ const finalEntries = requestedBook && marketConfig.includeBookLadders
3733
+ ? [...filteredEntries].sort((left, right) =>
3734
+ (left.lineValue ?? 0) - (right.lineValue ?? 0)
3735
+ || String(left.side).localeCompare(String(right.side))
3736
+ || Number(left.oddsInput) - Number(right.oddsInput)
3737
+ )
3738
+ : filteredEntries;
3739
 
3740
+ if (finalEntries.length === 0) {
3741
  throw new Error(requestedBook
3742
  ? `No ${requestedBook} ${marketConfig.marketLabel} odds were found for ${playerQuery}.`
3743
  : `No ${marketConfig.marketLabel} odds were found for ${playerQuery}.`);
3744
  }
3745
 
3746
+ const canonicalName = finalEntries[0].playerName;
3747
  return {
3748
  playerName: canonicalName,
3749
  marketLabel: marketConfig.marketLabel,
3750
+ entries: finalEntries,
3751
  bookFilter: requestedBook,
3752
  };
3753
  }
test/market-scanner.test.js CHANGED
@@ -8,6 +8,7 @@ import {
8
  extractCircaFileCandidatesFromHtml,
9
  extractSupplementalStrikeoutEntries,
10
  fetchOddsApiEntries,
 
11
  matchesCircaMlbFilename,
12
  normalizeOddsApiEntries,
13
  parseCircaOcrText,
@@ -589,6 +590,82 @@ test('filters event-level odds to configured books after regional fetch', async
589
  }
590
  });
591
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
592
  test('matches expected circa mlb filenames', () => {
593
  assert.equal(matchesCircaMlbFilename('MLB Props - 2026-4-3.pdf'), true);
594
  assert.equal(matchesCircaMlbFilename('MLB Props - 2026-04-03.pdf'), true);
 
8
  extractCircaFileCandidatesFromHtml,
9
  extractSupplementalStrikeoutEntries,
10
  fetchOddsApiEntries,
11
+ MarketScanner,
12
  matchesCircaMlbFilename,
13
  normalizeOddsApiEntries,
14
  parseCircaOcrText,
 
590
  }
591
  });
592
 
593
+ test('book-specific pitcher strikeout lookup keeps alt ladder entries', async () => {
594
+ const scanner = new MarketScanner({
595
+ client: {},
596
+ store: {},
597
+ embeds: {},
598
+ config: {
599
+ enabled: true,
600
+ oddsWorkflowEnabled: true,
601
+ circaWorkflowEnabled: false,
602
+ oddsApiBaseUrl: 'https://api.the-odds-api.com/v4',
603
+ oddsApiSportKey: 'baseball_mlb',
604
+ oddsApiKey: 'test-key',
605
+ oddsApiRegions: 'us',
606
+ oddsApiBookmakers: ['draftkings'],
607
+ oddsApiMarkets: ['pitcher_strikeouts'],
608
+ scanHttpTimeoutMs: 15000,
609
+ },
610
+ });
611
+
612
+ const originalFetch = global.fetch;
613
+ global.fetch = async (input) => {
614
+ const asString = String(input);
615
+
616
+ if (asString.includes('/events?')) {
617
+ return {
618
+ ok: true,
619
+ status: 200,
620
+ json: async () => [{ id: 'event-1', away_team: 'Padres', home_team: 'Pirates' }],
621
+ };
622
+ }
623
+
624
+ if (asString.includes('/events/event-1/odds')) {
625
+ return {
626
+ ok: true,
627
+ status: 200,
628
+ headers: new Headers(),
629
+ json: async () => ({
630
+ id: 'event-1',
631
+ away_team: 'Padres',
632
+ home_team: 'Pirates',
633
+ bookmakers: [
634
+ {
635
+ key: 'draftkings',
636
+ title: 'DraftKings',
637
+ markets: [
638
+ {
639
+ key: 'pitcher_strikeouts',
640
+ outcomes: [
641
+ { name: 'Over', description: 'Paul Skenes', point: 5.5, price: 180 },
642
+ { name: 'Under', description: 'Paul Skenes', point: 5.5, price: -230 },
643
+ { name: 'Over', description: 'Paul Skenes', point: 6.5, price: -130 },
644
+ { name: 'Under', description: 'Paul Skenes', point: 6.5, price: 100 },
645
+ { name: 'Over', description: 'Paul Skenes', point: 7.5, price: 135 },
646
+ { name: 'Under', description: 'Paul Skenes', point: 7.5, price: -165 },
647
+ ],
648
+ },
649
+ ],
650
+ },
651
+ ],
652
+ }),
653
+ };
654
+ }
655
+
656
+ throw new Error(`Unexpected fetch URL: ${asString}`);
657
+ };
658
+
659
+ try {
660
+ const result = await scanner.getPlayerMarketOdds('pitcher_strikeouts', 'Paul Skenes', { book: 'DraftKings' });
661
+ assert.equal(result.entries.length, 6);
662
+ assert.ok(result.entries.some((entry) => entry.side === 'over' && entry.lineValue === 6.5 && entry.oddsInput === '-130'));
663
+ assert.ok(result.entries.some((entry) => entry.side === 'under' && entry.lineValue === 7.5 && entry.oddsInput === '-165'));
664
+ } finally {
665
+ global.fetch = originalFetch;
666
+ }
667
+ });
668
+
669
  test('matches expected circa mlb filenames', () => {
670
  assert.equal(matchesCircaMlbFilename('MLB Props - 2026-4-3.pdf'), true);
671
  assert.equal(matchesCircaMlbFilename('MLB Props - 2026-04-03.pdf'), true);