Skip to main content
Version: nightly

Betfair

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.

Installation

Install NautilusTrader with Betfair support via pip:

pip install --upgrade "nautilus_trader[betfair]"

To build from source with Betfair extras:

uv sync --all-extras

Examples

You can find live example scripts here.

Betfair documentation

For API details and troubleshooting, see the official Betfair Developer Documentation.

Application keys

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.

API credentials

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.

Overview

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.

Orders capability

Betfair operates as a betting exchange with unique characteristics compared to traditional financial exchanges:

Order types

Order TypeSupportedNotes
MARKET-Not applicable to betting exchange.
LIMITOrders 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.

Execution instructions

InstructionSupportedNotes
post_only-Not applicable to betting exchange.
reduce_only-Not applicable to betting exchange.

Time in force options

Time in forceSupportedNotes
GTC-Betting exchange uses different model.
GTD-Betting exchange uses different model.
FOK-Betting exchange uses different model.
IOC-Betting exchange uses different model.

Advanced order features

FeatureSupportedNotes
Order ModificationLimited to non-exposure changing fields.
Bracket/OCO Orders-Not supported.
Iceberg Orders-Not supported.

Batch operations

OperationSupportedNotes
Batch Submit-Not supported.
Batch Modify-Not supported.
Batch Cancel-Not supported.

Position management

FeatureSupportedNotes
Query positions-Betting exchange model differs.
Position mode-Not applicable to betting exchange.
Leverage control-No leverage in betting exchange.
Margin mode-No margin in betting exchange.

Order querying

FeatureSupportedNotes
Query open ordersList all active bets.
Query order historyHistorical betting data.
Order status updatesReal-time bet state changes.
Trade historyBet matching and settlement reports.

Contingent orders

FeatureSupportedNotes
Order lists-Not supported.
OCO orders-Not supported.
Bracket orders-Not supported.
Conditional orders-Basic bet conditions only.

Configuration

Data client configuration options

OptionDefaultDescription
account_currencyRequiredBetfair account currency for data and price feeds.
usernameNoneBetfair account username; taken from environment when omitted.
passwordNoneBetfair account password; taken from environment when omitted.
app_keyNoneBetfair application key used for API authentication.
certs_dirNoneDirectory containing Betfair SSL certificates for login.
instrument_configNoneOptional BetfairInstrumentProviderConfig to scope available markets.
subscription_delay_secs3Delay (seconds) before initial market subscription request is sent.
keep_alive_secs36,000Keep-alive interval (seconds) for the Betfair session.
stream_conflate_msNoneExplicit stream conflation interval in milliseconds (0 disables conflation).

Execution client configuration options

OptionDefaultDescription
account_currencyRequiredBetfair account currency for order placement and balances.
usernameNoneBetfair account username; taken from environment when omitted.
passwordNoneBetfair account password; taken from environment when omitted.
app_keyNoneBetfair application key used for API authentication.
certs_dirNoneDirectory containing Betfair SSL certificates for login.
instrument_configNoneOptional BetfairInstrumentProviderConfig to scope reconciliation.
calculate_account_stateTrueCalculate account state locally from events when True.
request_account_state_secs300Interval (seconds) to poll Betfair for account state (0 disables).
reconcile_market_ids_onlyFalseWhen True, reconciliation requests only cover configured market IDs.
ignore_external_ordersFalseWhen True, ignore stream orders missing from the local 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()
info

For additional features or to contribute to the Betfair adapter, please see our contributing guide.