Repository navigation
Expand file tree
/
Copy pathsample-v4.js
More file actions
66 lines (53 loc) · 2.03 KB
/
Copy pathsample-v4.js
File metadata and controls
66 lines (53 loc) · 2.03 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
const axios = require('axios')
// An api key is emailed to you when you sign up to a plan
// Get a free API key at https://api.the-odds-api.com/
const apiKey = process.argv[2] || 'YOUR_API_KEY'
const sportKey = 'upcoming' // use the sport_key from the /sports endpoint below, or use 'upcoming' to see the next 8 games across all sports
const regions = 'us' // uk | us | eu | au. Multiple can be specified if comma delimited
const markets = 'h2h' // h2h | spreads | totals. Multiple can be specified if comma delimited
const oddsFormat = 'decimal' // decimal | american
const dateFormat = 'iso' // iso | unix
/*
First get a list of in-season sports
the sport 'key' from the response can be used to get odds in the next request
*/
axios.get('https://api.the-odds-api.com/v4/sports', {
params: {
apiKey
}
})
.then(response => {
console.log(response.data)
})
.catch(error => {
console.log('Error status', error.response.status)
console.log(error.response.data)
})
/*
Now get a list of live & upcoming games for the sport you want, along with odds for different bookmakers
This will deduct from the usage quota
The usage quota cost = [number of markets specified] x [number of regions specified]
For examples of usage quota costs, see https://the-odds-api.com/liveapi/guides/v4/#usage-quota-costs
*/
axios.get(`https://api.the-odds-api.com/v4/sports/${sportKey}/odds`, {
params: {
apiKey,
regions,
markets,
oddsFormat,
dateFormat,
}
})
.then(response => {
// response.data.data contains a list of live and
// upcoming events and odds for different bookmakers.
// Events are ordered by start time (live events are first)
console.log(JSON.stringify(response.data))
// Check your usage
console.log('Remaining requests',response.headers['x-requests-remaining'])
console.log('Used requests',response.headers['x-requests-used'])
})
.catch(error => {
console.log('Error status', error.response.status)
console.log(error.response.data)
})