IN DEVELOPMENT · FREE DURING BETA

Working with bet365 odds in Python

Copy-paste Python for the maths every odds project needs: format conversion, implied probability, margin removal, expected value and stake sizing.

Status: OddsDirect is in development and not live yet. This page explains the subject and what the API is being built to do. Endpoints, response formats and limits will be published in the docs when the beta opens.

Setup

The examples need Python 3.10 or newer and nothing outside the standard library. The WebSocket pattern on the WebSocket page uses the websockets package.

terminalshell
python3 --version   # 3.10+
pip install websockets   # only for streaming

Convert odds formats

bet365 shows odds as decimal, fractional or American depending on region. Normalise everything to decimal internally:

odds_formats.pypython
from fractions import Fraction

def fractional_to_decimal(frac: str) -> float:
    """'5/2' -> 3.5"""
    return float(Fraction(frac)) + 1

def american_to_decimal(us: int) -> float:
    """+150 -> 2.5, -200 -> 1.5"""
    return 1 + (us / 100 if us > 0 else 100 / -us)

def decimal_to_american(dec: float) -> int:
    return round((dec - 1) * 100) if dec >= 2 else round(-100 / (dec - 1))

print(fractional_to_decimal("5/2"))   # 3.5
print(american_to_decimal(-200))      # 1.5
print(decimal_to_american(2.5))       # 150

Implied probability and the margin

A bookmaker's prices imply probabilities that add up to more than 100%. The excess is the margin (overround). Removing it gives an estimate of the market's "fair" view:

margin.pypython
def implied(odds: list[float]) -> list[float]:
    """Implied probability of each outcome from decimal odds."""
    return [1 / o for o in odds]

def overround(odds: list[float]) -> float:
    """Bookmaker margin: how far the implied probabilities sum above 100%."""
    return sum(implied(odds)) - 1

def fair_odds(odds: list[float]) -> list[float]:
    """Remove the margin proportionally to get 'fair' (no-vig) odds."""
    total = sum(implied(odds))
    return [round(total / (1 / o), 3) for o in odds]

home_draw_away = [2.10, 3.40, 3.60]          # example prices, not live data
print(f"margin: {overround(home_draw_away):.2%}")   # margin: 4.81%
print(fair_odds(home_draw_away))                    # [2.201, 3.563, 3.773]

Expected value and stake sizing

If your model has its own probability for an outcome, expected value tells you whether a price is worth taking, and the Kelly criterion suggests a stake size:

value.pypython
def expected_value(decimal_odds: float, your_probability: float, stake: float = 1.0) -> float:
    """EV of a bet given your own estimate of the probability."""
    return stake * (your_probability * (decimal_odds - 1) - (1 - your_probability))

def kelly_fraction(decimal_odds: float, p: float) -> float:
    """Kelly stake as a fraction of bankroll (0 if there is no edge)."""
    b = decimal_odds - 1
    return max(0.0, (b * p - (1 - p)) / b)

print(round(expected_value(2.50, 0.45), 3))   # 0.125 per 1 unit staked
print(round(kelly_fraction(2.50, 0.45), 3))   # 0.083

Many people stake a fraction of Kelly (a quarter or half), because model errors make full Kelly very volatile.

Fetching odds from OddsDirect

Python client examples: coming soonAuthentication, requests and real responses will be documented when the beta opens.

Frequently asked questions

Is there an OddsDirect Python client?

Not yet. API-specific Python examples will be added to the docs when the beta opens. The examples on this page work without the API.

How do I convert fractional odds to decimal in Python?

Add 1 to the fraction: 5/2 becomes 3.5. Python's fractions.Fraction parses strings like '5/2' exactly.

How do I remove the bookmaker margin?

Convert each price to an implied probability (1 / odds), divide each by their sum so they total 100%, then convert back. The second example on this page does exactly that.

Is betting with a model profitable?

Usually not. Bookmaker margins and well-informed prices make it hard to beat the market. Use these tools for analysis, bet only what you can afford to lose, and remember the 18+ rule.

Be first in line for a beta key

The API will be free during the beta. Keys go out in our Discord first.

Related