https://github.com/nearhuscarl/the-odds-api
https://github.com/nearhuscarl/the-odds-api
Last synced: 5 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/nearhuscarl/the-odds-api
- Owner: NearHuscarl
- License: mit
- Created: 2019-05-29T03:31:45.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-03T22:54:08.000Z (almost 3 years ago)
- Last Synced: 2025-05-07T21:46:01.513Z (5 months ago)
- Language: TypeScript
- Size: 2.08 MB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 19
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# The Odds API

[![npm badge][npm-badge-png]][package-url]
## Installation
```bash
$ npm install the-odds-api
```Get the API key (free) from the [host website]
## Import
```js
import TheOddsAPI, { Market, Region, Sport } from 'the-odds-api';
const theOddsAPI = new TheOddsAPI(YOUR_API_KEY);
```## Usages
See [documentation] for more information about paramters
### Get header data
You can attach additional data from the API header response by adding `true` in the last argument in every methods below to get some meta info like remaining requests
```js
theOddsAPI.getOdds({
sport: 'soccer_epl',
}, true).then((data) => {
console.log(data);
});
```Result
```json
{
"data": [...],
"api": {
"requestsRemaining": 499,
"requestsUsed": 1
}
}
```### Get sports
```js
theOddsAPI.getSports({ all: true }).then((data) => {
console.log(JSON.stringify(data, null, 4));
});
```Result
```json
{
"data": [
{
"key": "americanfootball_ncaaf",
"active": true,
"group": "American Football",
"details": "US College Football",
"title": "NCAAF"
},
{
"key": "americanfootball_nfl",
"active": true,
"group": "American Football",
"details": "US Football",
"title": "NFL"
},
{
"key": "aussierules_afl",
"active": true,
"group": "Aussie Rules",
"details": "Aussie Football",
"title": "AFL"
},
...
]
}
```### Get odds
```js
theOddsAPI.getOdds({
mkt: Market.h2h,
region: Region.au,
sport: 'americanfootball_nfl',
}).then((data) => {
console.log(JSON.stringify(data, null, 4));
});
```Result
```json
{
"data": [
{
"sport_key": "americanfootball_nfl",
"sport_nice": "NFL",
"teams": [
"Chicago Bears",
"Green Bay Packers"
],
"commence_time": 1567729200,
"home_team": "Chicago Bears",
"sites": [
{
"site_key": "unibet",
"site_nice": "Unibet",
"last_update": 1559096349,
"odds": {
"h2h": [
1.55,
2.5
]
}
},
{
"site_key": "sportsbet",
"site_nice": "SportsBet",
"last_update": 1559096605,
"odds": {
"h2h": [
1.56,
2.49
]
}
},
{
"site_key": "neds",
"site_nice": "Neds",
"last_update": 1559096589,
"odds": {
"h2h": [
1.52,
2.6
]
}
},
{
"site_key": "tab",
"site_nice": "TAB",
"last_update": 1559096371,
"odds": {
"h2h": [
1.52,
2.55
]
}
},
{
"site_key": "ladbrokes",
"site_nice": "Ladbrokes",
"last_update": 1559096514,
"odds": {
"h2h": [
1.5,
2.6
]
}
}
],
"sites_count": 5
},
...
]
}
```## Testing
```bash
$ npm test
```## License
**[Mit License]**
[package-url]: https://www.npmjs.com/package/the-odds-api
[host website]: https://the-odds-api.com/
[documentation]: https://the-odds-api.com/liveapi/guides/v3/
[MIT License]: ./LICENSE.md
[npm-badge-png]: https://nodei.co/npm/the-odds-api.png?downloads=true&stars=true