# Connecting a Real Odds Provider

## The Odds API / Unibet FR

Zirabet includes a production adapter for [The Odds API](https://the-odds-api.com/liveapi/guides/v4/) configured to ingest Unibet France odds only.

```env
ODDS_PROVIDER=the-odds-api
ODDS_PROVIDER_BASE_URL=https://api.the-odds-api.com
ODDS_PROVIDER_API_KEY=replace-with-secret
ODDS_PROVIDER_BOOKMAKERS=unibet_fr
ODDS_PROVIDER_REGIONS=fr
ODDS_PROVIDER_MARKETS=h2h,spreads,totals
ODDS_PROVIDER_SPORTS=upcoming
```

`ODDS_PROVIDER_SPORTS=upcoming` is recommended for local testing because it fetches live games and the next upcoming games without draining quota. Use `ODDS_PROVIDER_SPORTS=auto` for a broader production sync across every active non-outright sport exposed by The Odds API. You can also set a comma-separated list of The Odds API sport keys, for example:

```env
ODDS_PROVIDER_SPORTS=soccer_france_ligue_one,soccer_epl,tennis_atp_wimbledon,basketball_nba
```

The adapter maps:

- `h2h` to `1X2` when a draw outcome is present, otherwise `Vainqueur`.
- `spreads` to `Handicap`.
- `totals` to `Total {line}`.

Live status is detected from The Odds API `commence_time`: if it is earlier than the current server time, the event is considered in-play. The Odds API documents that `/odds` includes upcoming and live events and does not return completed events.

Run a one-shot sync:

```bash
npx tsx -e 'import { syncOddsFromProvider } from "./src/server/sync/odds-sync"; syncOddsFromProvider().then(console.log)'
```

Run continuous sync:

```bash
npm run worker:providers
```

## Generic HTTP Provider

Set these variables:

```env
ODDS_PROVIDER=your-provider-key
ODDS_PROVIDER_BASE_URL=https://api.provider.example
ODDS_PROVIDER_API_KEY=...
ODDS_PROVIDER_WEBHOOK_SECRET=...
```

Implement or adapt the HTTP endpoints expected by `HttpOddsProvider`:

- `GET /sports`
- `GET /events?live=true&sport=football`
- `GET /health`

The normalized event payload is defined in `src/server/providers/odds/types.ts`.

Run sync:

```bash
npm run worker:providers
```

Production must not use `ODDS_PROVIDER=local`.
