-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathpremier-league-odds.ts
More file actions
89 lines (75 loc) · 2.57 KB
/
Copy pathpremier-league-odds.ts
File metadata and controls
89 lines (75 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/**
* Premier League Odds Example
*
* Fetch odds for all upcoming Premier League matches from multiple
* bookmakers, including direct bet links.
*/
import { OddsAPIClient } from 'odds-api-io';
async function main() {
const client = new OddsAPIClient({
apiKey: process.env.ODDS_API_KEY || 'your-api-key-here',
});
try {
console.log('Fetching Premier League events...\n');
const events = await client.getEvents({
sport: 'football',
league: 'england-premier-league',
});
// Filter for pending/live events
const activeEvents = events.filter(
(e: any) => e.status === 'pending' || e.status === 'live'
);
console.log(`Found ${activeEvents.length} upcoming Premier League matches\n`);
console.log('='.repeat(100));
for (const event of activeEvents) {
console.log(`\n${event.home} vs ${event.away}`);
console.log(`Starts: ${event.date} | Status: ${event.status}`);
console.log('-'.repeat(100));
// Get odds from multiple bookmakers (names are case-sensitive!)
const oddsData = await client.getEventOdds({
eventId: event.id,
bookmakers: 'Bet365,SingBet,FanDuel',
});
const bookmakers = (oddsData as any).bookmakers || {};
if (Object.keys(bookmakers).length === 0) {
console.log('No odds available for this match');
console.log('='.repeat(100));
continue;
}
// Display odds table
console.log(
'Bookmaker'.padEnd(15) +
'Home'.padEnd(10) +
'Draw'.padEnd(10) +
'Away'.padEnd(10)
);
console.log('-'.repeat(100));
for (const [bookie, markets] of Object.entries(bookmakers)) {
// Find the ML (moneyline) market
const mlMarket = (markets as any[]).find((m: any) => m.name === 'ML');
if (mlMarket?.odds?.[0]) {
const odds = mlMarket.odds[0];
console.log(
bookie.padEnd(15) +
(odds.home || 'N/A').toString().padEnd(10) +
(odds.draw || 'N/A').toString().padEnd(10) +
(odds.away || 'N/A').toString().padEnd(10)
);
}
}
// Display direct bet links
const urls = (oddsData as any).urls || {};
const validUrls = Object.entries(urls).filter(([, url]) => url && url !== 'N/A');
if (validUrls.length > 0) {
console.log('\n Direct bet links:');
validUrls.forEach(([bookie, url]) => {
console.log(` ${bookie}: ${url}`);
});
}
console.log('='.repeat(100));
}
} catch (error) {
console.error('Error:', error);
}
}
main();