Skip to content

Commit

Permalink
Default to using pinnacle sportsbook for odds, also display bookmaker
Browse files Browse the repository at this point in the history
  • Loading branch information
blchelle committed Nov 2, 2023
1 parent 80ae332 commit c5c294f
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 4 deletions.
2 changes: 2 additions & 0 deletions spec/picks/bestPicks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { GameData } from '@utils/game'
const testGames: GameData[] =
[
{
bookmaker: 'none',
gameIndex: 0,
early: false,
locked: false,
Expand All @@ -13,6 +14,7 @@ const testGames: GameData[] =
]
},
{
bookmaker: 'none',
gameIndex: 1,
early: false,
locked: false,
Expand Down
2 changes: 2 additions & 0 deletions spec/picks/bestSeasonPicks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { BestPicks } from './bestPicks'
const testGames: GameData[] =
[
{
bookmaker: 'none',
gameIndex: 0,
early: false,
locked: false,
Expand All @@ -14,6 +15,7 @@ const testGames: GameData[] =
]
},
{
bookmaker: 'none',
gameIndex: 1,
early: false,
locked: false,
Expand Down
2 changes: 2 additions & 0 deletions spec/picks/bestWeeklyPicks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ describe(getBestWeeklyPicks, () => {
beforeEach(() => {
testGames = [
{
bookmaker: 'none',
gameIndex: 0,
early: false,
locked: false,
Expand All @@ -17,6 +18,7 @@ describe(getBestWeeklyPicks, () => {
]
},
{
bookmaker: 'none',
gameIndex: 1,
early: false,
locked: false,
Expand Down
3 changes: 2 additions & 1 deletion spec/utils/display.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { BestPicks, BestProb } from '@picks/bestPicks'
const testGame: GameData[] =
[
{
bookmaker: 'none',
gameIndex: 0,
early: false,
locked: false,
Expand Down Expand Up @@ -41,7 +42,7 @@ describe(displayPicks, () => {
}

displayPicks(testGame, best)
const expected = ' Away Team over Home Team 16 confidence Prob: 0.25 Win: 8.00 Loss: -3.00 Net: 4.00' +
const expected = ' Away Team over Home Team 16 confidence Bookmaker: none Prob: 0.25 Win: 8.00 Loss: -3.00 Net: 4.00' +
'' +
'Net Points Gained: -2.00' +
'' +
Expand Down
5 changes: 5 additions & 0 deletions spec/utils/game.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { OfpData } from '@webscraper/getData'
import { OddsData } from '@service/odds'

const testGame: GameData = {
bookmaker: 'none',
gameIndex: 0,
early: false,
locked: false,
Expand Down Expand Up @@ -46,6 +47,7 @@ const testOddsData: OddsData = [
commence_time: '2020-12-20T18:05:00Z',
bookmakers: [
{
key: 'pinnacle',
markets: [
{
outcomes: [
Expand All @@ -65,6 +67,7 @@ describe(mergeOfpAndOddsData, () => {
beforeEach(() => {
expected = [
{
bookmaker: 'pinnacle',
gameIndex: 0,
early: false,
locked: false,
Expand Down Expand Up @@ -113,6 +116,7 @@ let testGames: GameData[] = []
beforeEach(() => {
testGames = [
{
bookmaker: 'none',
gameIndex: 0,
early: false,
locked: false,
Expand All @@ -122,6 +126,7 @@ beforeEach(() => {
]
},
{
bookmaker: 'none',
gameIndex: 1,
early: false,
locked: false,
Expand Down
3 changes: 2 additions & 1 deletion src/service/odds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ interface MarketData {
}

interface BookmakerData {
key: string
markets: MarketData[]
}

Expand All @@ -30,7 +31,7 @@ export const getOddsData = async (): Promise<OddsData> => {
const oddsApiUrl = buildUrl(
env.oddsApi.host,
'/v4/sports/americanfootball_nfl/odds',
{ regions: 'us', markets: 'h2h', oddsFormat: 'decimal', apiKey: env.oddsApi.apiKey }
{ regions: 'eu', markets: 'h2h', oddsFormat: 'decimal', apiKey: env.oddsApi.apiKey }
)
return (await axios.get(oddsApiUrl)).data
}
5 changes: 4 additions & 1 deletion src/utils/display.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { GameData } from '@utils/game'
import { BestProb } from '@picks/bestPicks'

export const displayPicks = (gamesData: GameData[], best: BestProb): void => {
const longestBookmakerName = gamesData.reduce((longest, game) => Math.max(longest, game.bookmaker.length), 0)

best.picks.forEach(({ netPoints, pick, rank }, i) => {
const pointsAvg = netPoints.avg.toFixed(2)
const pointsIfWin = netPoints.win.toFixed(2)
Expand All @@ -13,11 +15,12 @@ export const displayPicks = (gamesData: GameData[], best: BestProb): void => {

const teamsColumn = `${winningTeam.padStart(14)} over ${losingTeam.padEnd(14)}`
const rankColumn = `${rank.toString().padStart(2)} confidence`
const bookmakerColumn = `Bookmaker: ${gameData.bookmaker.padEnd(longestBookmakerName + 1)}`
const probColumn = `Prob: ${gameData.teams[pick].winProb.toString().padStart(7)}`
const winColumn = `Win: ${pointsIfWin.toString().padStart(7)}`
const lossColumn = `Loss: ${pointsIfLose.toString().padStart(7)}`
const netColumn = `Net: ${pointsAvg.toString().padStart(7)}`
const tableRow = [teamsColumn, rankColumn, probColumn, winColumn, lossColumn, netColumn].join(''.padStart(5))
const tableRow = [teamsColumn, rankColumn, bookmakerColumn, probColumn, winColumn, lossColumn, netColumn].join(''.padStart(5))

console.log(tableRow)
})
Expand Down
11 changes: 10 additions & 1 deletion src/utils/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface TeamData {
};

export interface GameData {
bookmaker: string
gameIndex: number
early: boolean
locked: boolean
Expand Down Expand Up @@ -44,6 +45,7 @@ export const mergeOfpAndOddsData = (ofpGames: OfpData, oddsGames: OddsData): Gam
// Some games have happened in the past (ie TNF), these games won't have odds
if (away.state === 'won' || home.state === 'won') {
return {
bookmaker: 'none',
gameIndex: i,
early: true,
locked: true,
Expand All @@ -63,14 +65,21 @@ export const mergeOfpAndOddsData = (ofpGames: OfpData, oddsGames: OddsData): Gam
throw new Error(`could not find a matching game for ${away.team} at ${home.team}`)
}

const mlPrices = matchingGame.bookmakers[0].markets[0].outcomes
// Use pinnable if they're available
const pinnacleIndex = matchingGame.bookmakers.findIndex((bookmaker) => bookmaker.key === 'pinnacle')
const bookmakerIndex = pinnacleIndex === -1 ? 0 : pinnacleIndex
const bookmakerName = matchingGame.bookmakers[bookmakerIndex].key

const mlPrices = matchingGame.bookmakers[bookmakerIndex].markets[0].outcomes

const early = isEarlyGame(new Date(matchingGame.commence_time))
const awaySpreadIndex = ofpTeamToOddsApiTeam(away.team) === mlPrices[0].name.toLowerCase() ? 0 : 1
const homeSpreadIndex = 1 - awaySpreadIndex

const [homeWinProb, awayWinProb] = noVigOdds(mlPrices[homeSpreadIndex].price, mlPrices[awaySpreadIndex].price)

const gameData: GameData = {
bookmaker: bookmakerName,
gameIndex: i,
early,
locked: false,
Expand Down

0 comments on commit c5c294f

Please sign in to comment.