canonical: https://jentic.com/apis/betfair.com/betfair

# Betfair Exchange Streaming API

The Betfair Exchange Streaming API provides a long-lived SSL socket connection delivering CRLF-delimited JSON messages for live market and order updates from the Betfair Exchange. It is used by trading bots, odds aggregators, and risk systems to receive low-latency price and order book changes without polling. The OpenAPI spec models the request and response message envelopes - authentication, market subscription, order subscription, and heartbeat operations are dispatched through a single /request entry point discriminated by an op field.

## For AI agents

Subscribe to live market and order updates from the Betfair Exchange over a streaming socket. Single request envelope dispatches authentication, market, and order subscriptions.

## Scope

Does not handle bet placement, account funding, or REST-style market browsing - use for live streaming market and order updates from the Betfair Exchange only.

## Capabilities

- Authenticate a streaming session against the Betfair Exchange using a session token and app key
- Subscribe to live market change updates for selected market ids
- Subscribe to order change updates scoped to a customer account
- Send heartbeats to keep the streaming socket alive
- Receive change message snapshots and incremental deltas over a single TCP connection

## Use cases

### Low-Latency Odds Feed

Power a trading dashboard with live Betfair Exchange prices by subscribing to market change messages over the streaming socket. The single /request endpoint accepts an authentication op followed by a marketSubscription op listing market ids of interest, and the server pushes snapshots and deltas back as CRLF-delimited JSON. Building a stable client with reconnect and resubscribe logic is typically 2 to 3 days of work.

Example prompt: POST /request with op=authentication and the session token, then POST /request with op=marketSubscription and the target market ids, and parse incoming change messages

### Real-Time Order Monitoring

Monitor placed orders on the Betfair Exchange without polling the REST betting API by subscribing to order change messages. The orderSubscription op streams matched, unmatched, and cancelled state transitions for the authenticated account. A risk system can react in under a second with this feed where REST polling would lag by several seconds.

Example prompt: POST /request with op=authentication, then POST /request with op=orderSubscription and emit each order change message to a downstream risk topic

### Connection Health Heartbeats

Keep a long-lived Betfair streaming connection alive and detect disconnects quickly by exchanging heartbeat messages. The heartbeat op is sent at a configurable interval and the server replies with the current connection clock, allowing the client to trigger a reconnect if responses lapse. Heartbeat handling is a small but essential part of any production integration.

Example prompt: POST /request with op=heartbeat every 5 seconds and trigger a full reconnect if no heartbeat response arrives within 10 seconds

### AI Agent for Live Markets

An AI agent uses Jentic to discover the streaming subscription operation and start a market feed without learning the protocol details by hand. The agent calls /request with the appropriate op envelope to authenticate and subscribe, and Jentic stores the Betfair app key and session token securely. Through Jentic, an agent can be streaming market data within an hour of starting integration work.

Example prompt: Search Jentic for 'subscribe to betfair markets' and execute the returned /request operation with op=marketSubscription to start a feed for the target event

## Key endpoints

| Method | Path | Description |
| --- | --- | --- |
| POST | /request | Single dispatch endpoint for authentication, marketSubscription, orderSubscription, and heartbeat operations discriminated by the op field |

## Key resources

- **Streaming Socket** — Single CRLF-delimited JSON channel to which all request and response messages are dispatched
- **Authentication** — Session token and app key authentication operation that opens a streaming session
- **Market Subscription** — Subscribe to market change messages for selected market ids
- **Order Subscription** — Subscribe to order change messages for the authenticated account
- **Heartbeat** — Keep-alive protocol exchange to detect disconnects

## Why Jentic

- **Setup:** Wiring the Betfair Exchange Streaming API by hand means opening the streaming connection, injecting your app key and session token into the in-protocol authentication message, and framing every subscription request yourself. Through Jentic you install once, import the Betfair Exchange Streaming API from the API Directory, store the credentials once, and your agent calls it.
- **Permission scoping:** Betfair Streaming exposes a single /request endpoint whose action is chosen in the message envelope rather than as a resource in the URL path, so scope the agent to the operations it needs, such as subscribing to market updates. You choose that operation set, and order subscription is not included unless you add it.
- **Credential handling:** Your Betfair app key and session token are stored once, encrypted, by your own Jentic One instance and injected into the in-protocol authentication message at execution time. They never enter the agent's prompt, logs, or context.
- **Discovery method:** Agents search Jentic by intent such as 'subscribe to Betfair markets', and Jentic returns the /request operation with its message envelope schema so the agent calls the right operation without learning the streaming protocol from the sample code.

## Related APIs

- **BetsAPI** — Aggregated odds and event data across multiple bookmakers via REST
- **The Odds API** — Polled odds aggregation across global sportsbooks
- **BetsAPI Events** — Pair sports event metadata with live Betfair Exchange prices

## FAQ

### What authentication does the Betfair Exchange Streaming API use?

The streaming API authenticates via an in-protocol authentication message that carries a Betfair session token and an application key. The OpenAPI spec does not declare a securityScheme because credentials are sent in the body of the first /request message rather than as HTTP headers. When called via Jentic, both values are stored encrypted in your Jentic One instance and injected into the auth message at execution time.

### How many endpoints does the Betfair Streaming API have?

The streaming API exposes a single HTTP-style endpoint, POST /request, which carries every protocol operation. Different operations such as authentication, marketSubscription, orderSubscription, and heartbeat are selected via the op discriminator in the request body.

### Can I receive live order updates without polling?

Yes. Send /request with op=orderSubscription after authentication and the server will push order change messages for matched, unmatched, and cancelled state transitions over the open socket. This is significantly faster than polling the REST listCurrentOrders operation on the betting API.

### How do I start a Betfair market stream through Jentic?

Run pip install jentic and search for 'subscribe to betfair market'. Jentic returns the /request operation, the agent loads the message schema, and executes first with op=authentication and then with op=marketSubscription specifying market ids. Subsequent change messages arrive on the same connection.

### What rate limits apply to the streaming API?

The streaming socket itself does not impose a per-message rate limit, but Betfair caps the number of concurrent streaming connections per app key and the breadth of market subscriptions. Consult the Betfair developer programme for the limits applicable to your app key tier before scaling fan-out.

### Can I connect to the streaming API over plain HTTP?

No. While the spec lists a stream-api.betfair.com URL on port 443, production traffic must run over the SSL socket connection - the protocol is CRLF-delimited JSON over TLS, not an HTTP REST exchange. Treat the OpenAPI spec as a model of the message envelopes rather than as a conventional REST contract.

### Can I limit what my agent is allowed to do with the Betfair Exchange Streaming API?

Yes. Because Jentic One is self-hosted, you run it and your own rules decide which operations and credentials your agent may use. The Betfair Exchange Streaming API dispatches every action through a single /request endpoint where the op field selects the operation, so you scope the agent to only the operations it needs, such as authentication and marketSubscription for reading live market updates. If you do not grant it, orderSubscription is left out, so an agent set up to read market prices cannot subscribe to your account's order changes or send arbitrary requests.
