Founded in 2000, Betfair operates the world’s largest online betting exchange, with its headquarters in London and satellite offices across the globe.
NautilusTrader provides an adapter for integrating with the Betfair REST API and Exchange Streaming API.
Install NautilusTrader with Betfair support via pip:
pip install --upgrade "nautilus_trader[betfair]"To build from source with Betfair extras:
uv sync --all-extrasYou can find live example scripts here.
For API details and troubleshooting, see the official Betfair Developer Documentation.
Betfair requires an Application Key to authenticate API requests. After registering and funding your account, obtain your key using the API-NG Developer AppKeys Tool.
:::info See also the Betfair Getting Started - Application Keys guide. :::
Supply your Betfair credentials via environment variables or client configuration:
export BETFAIR_USERNAME=<your_username>
export BETFAIR_PASSWORD=<your_password>
export BETFAIR_APP_KEY=<your_app_key>
export BETFAIR_CERTS_DIR=<path_to_certificate_dir>:::tip We recommend using environment variables to manage your credentials. :::
The Betfair adapter provides three primary components:
BetfairInstrumentProvider: loads Betfair markets and converts them into Nautilus instruments.BetfairDataClient: streams real-time market data from the Exchange Streaming API.BetfairExecutionClient: submits orders (bets) and tracks execution status via the REST API.
Betfair operates as a betting exchange with unique characteristics compared to traditional financial exchanges:
| Order Type | Betfair | Notes |
|---|---|---|
MARKET |
- | Not applicable to betting exchange. |
LIMIT |
✓ | Orders placed at specific odds. |
STOP_MARKET |
- | Not supported. |
STOP_LIMIT |
- | Not supported. |
MARKET_IF_TOUCHED |
- | Not supported. |
LIMIT_IF_TOUCHED |
- | Not supported. |
TRAILING_STOP_MARKET |
- | Not supported. |
| Instruction | Betfair | Notes |
|---|---|---|
post_only |
- | Not applicable to betting exchange. |
reduce_only |
- | Not applicable to betting exchange. |
| Time-in-Force | Betfair | Notes |
|---|---|---|
GTC |
- | Betting exchange uses different model. |
GTD |
- | Betting exchange uses different model. |
FOK |
- | Betting exchange uses different model. |
IOC |
- | Betting exchange uses different model. |
| Feature | Betfair | Notes |
|---|---|---|
| Order Modification | ✓ | Limited to non-exposure changing fields. |
| Bracket/OCO Orders | - | Not supported. |
| Iceberg Orders | - | Not supported. |
The following execution client configuration options affect order behavior:
| Option | Default | Description |
|---|---|---|
calculate_account_state |
True |
If True, calculates account state from events. |
request_account_state_secs |
300 |
Interval for account state checks in seconds (0 disables). |
reconcile_market_ids_only |
False |
If True, only reconciles orders for configured market IDs. |
ignore_external_orders |
False |
If True, silently ignores orders not found in cache. |
Here is a minimal example showing how to configure a live TradingNode with Betfair clients:
from nautilus_trader.adapters.betfair import BETFAIR
from nautilus_trader.adapters.betfair import BetfairLiveDataClientFactory
from nautilus_trader.adapters.betfair import BetfairLiveExecClientFactory
from nautilus_trader.config import TradingNodeConfig
from nautilus_trader.live.node import TradingNode
# Configure Betfair data and execution clients (using AUD account currency)
config = TradingNodeConfig(
data_clients={BETFAIR: {"account_currency": "AUD"}},
exec_clients={BETFAIR: {"account_currency": "AUD"}},
)
# Build the TradingNode with Betfair adapter factories
node = TradingNode(config)
node.add_data_client_factory(BETFAIR, BetfairLiveDataClientFactory)
node.add_exec_client_factory(BETFAIR, BetfairLiveExecClientFactory)
node.build()