Explore this guide
Betfair Exchange API integration requires approved account access, the appropriate application key and authentication flow, then separate handling of market state and account orders. A working login is the start of the integration, not evidence that the application has reconstructed a usable market or resolved a submitted bet.
This is a technical implementation plan for authorized developers. It uses official public documentation and illustrative pseudocode; it does not supply access, proprietary credentials, a tested SDK implementation or permission for a particular commercial use. For project scoping, see Betfair integration services.
Confirm product and access before coding
Record the application purpose, account owner, operating scope and intended data use. Check the current Betfair requirements for that arrangement, including the applicable market/jurisdiction and any commercial permissions. Do not infer permission from a consumer account or a supplier's claim of access.
Betfair's getting-started guide identifies an account, application key and session token as setup requirements. Its documentation distinguishes delayed and live application-key access. Delayed access is useful for supported development tasks but must not be represented as equivalent live trading evidence.
Prepare a configuration record with environment, account identity, approved key type, required operations and escalation owner. Keep secret values out of that record's logs and screenshots. The document should let a reviewer assess intended scope without receiving credentials.
Choose the documented authentication flow
Betfair's login guidance distinguishes interactive and non-interactive login models, including certificate-based automation. Select the flow appropriate to the application's current access model instead of copying an unrelated login example.
Keep sensitive account credentials, private keys and privileged tokens in a controlled backend or the provider's explicitly supported application flow. Define expiry, renewal, rotation and permission-failure handling. An expired session should cause a clear integration state, not an endless retry loop that hides lost access.
For an unattended service, document who can rotate its credentials and how rotation is rehearsed. If multiple workers share account access, coordinate lifecycle and quotas according to account-level constraints rather than assuming each new session is an independent allowance.
Do not place real credentials into example code. The following describes responsibilities, not concrete SDK methods:
bootstrap(approved_configuration):
secrets = load_scoped_secret_material()
session = authenticate_using_documented_flow(secrets)
verify_required_operation_permissions(session)
record_nonsecret_access_state()
start_market_adapter(session)
start_account_order_adapter(session)
The exact flow and checks must come from the current official documentation for the selected account/application type.
Technical flow
- 01Approved access
Bind the approved application key and documented login/session model
- 02Discover markets
Select authorized markets and normalize identifiers
- 03Separate adapters
Keep native market streaming and account/order state distinct
- 04Reconcile orders
Resolve unknown instructions against authoritative account evidence
Keep discovery, market subscriptions, account orders and reconciliation as explicit responsibilities. They can share a deployment while retaining separate state and error handling.
| Responsibility | Evidence to retain |
|---|---|
| Discovery | Source event, market and selection identities |
| Market view | Subscription scope, image/update boundary and recovery state |
| Account order view | Authoritative references, matched/unmatched amounts and uncertainty |
| Commands | Durable intent, supported deduplication/reference fields and response |
| Reconciliation | Query/result evidence and financial-state resolution |
This division prevents a market-data reconnect from being mistaken for confirmation of an order outcome. The general exchange reliability guide explains that system boundary in depth.
Discover markets and preserve identity
Start with a deliberately narrow market set and obtain the relevant catalogue and dynamic data through documented operations. Keep provider market and selection identifiers throughout processing rather than reconstructing identity from labels.
Preserve market rules, periods and selection state. A canonical ID is useful for your platform, but support still needs the original identifiers to investigate an API response or settlement discrepancy.
Choose fields and projection depth for the actual consumer. A screen requiring a top-of-book view and an account reconciliation worker may need different data. Betfair's request-limit documentation describes weighted data limits; do not treat a request with more markets and projections as equivalent to a smaller one.
Maintain a discovery refresh policy for lifecycle changes such as new markets or removed selections. A successful earlier catalogue fetch is not a permanent declaration that the same market is open and available.
Subscribe using the actual stream protocol
Betfair explicitly states that its Stream API does not accept WebSocket connections. Do not point a browser WebSocket client at a native exchange stream address. Your backend can translate validated state into a separate supported browser-delivery interface.
The official market/order stream overview distinguishes public market data from account order data and describes an initial image followed by cache updates. Maintain those views according to their documented scopes.
Apply update semantics for each field, including removals and status changes. Do not append a replacement amount to an existing price level or interpret an omitted field as a deletion without the relevant contract.
Store documented continuity evidence and expose recovering state. A connection can be alive before subscriptions, image assembly and local processing are ready.
Reconnect with guarded state
Use the documented reconnect/resubscription behavior and supported cursor rules. Opaque tokens should remain opaque. If continuity cannot be established, obtain supported replacement state instead of guessing which messages were missed.
Introduce an application generation guard where previous workers can finish late. A recovered market should not be overwritten by a response or queued task from an older connection.
Publish market status and health alongside prices. Keep local processing progress separate from channel activity. An unrelated heartbeat should not silently re-enable an affected acceptance path.
Record restriction start, resubscription, state verification and resume separately in an incident timeline. This distinguishes a network recovery time from the time the product became usable again.
Keep order submission and financial evidence separate
Before submission, persist the intent and supported request references. Validate account permissions, funds/exposure and the requested constraints consistently. The precise trading instructions depend on the permitted operation and provider rules.
Betfair placeOrders documentation explains operation/instruction reporting and market-version behavior. Inspect the actual instruction outcome and matched size; an HTTP success or an accepted order is not proof that the complete requested stake matched.
If a response is lost, mark the outcome unresolved and reconcile through supported authoritative identifiers and queries. Preserve the relevant funds/exposure allowance. Do not create a replacement merely because the transport timed out.
For an illustrative 100-unit order with 40 matched and 60 still unmatched, cancellation of the remaining portion does not remove the matched 40 from exposure. Track confirmation of the cancellation separately from the original submission.
Error handling and operating limits
Classify failures by meaning: authentication, permission, request size, concurrency/quotas, transient connectivity, schema/continuity and uncertain commands. Each class needs an owner and a bounded response.
A new login or another worker should not be used to evade account restrictions. Reduce or reshape permitted work and follow current provider guidance. Where an SDK provides recovery, avoid layering competing infinite retry loops on top.
Monitor account-order reconciliation independently of market display. A green prices dashboard can coexist with unresolved financial outcomes. Record latency at named boundaries rather than importing marketing claims as an SLO.
Use the API rate-limit guide for scheduler/cache design, and the Diamond comparison only for its separate evidence-verification question.
Authorized acceptance checklist
| Exercise | Expected evidence |
|---|---|
| Wrong/expired access | Clear restricted integration state and nonsecret diagnosis |
| Unsupported market/projection scope | Documented rejection and corrected request plan |
| Initial image plus updates | Correct reconstructed state with source identities |
| Reconnect and delayed old work | Supported continuity and no stale overwrite |
| Partial match then cancel | Matched exposure retained; remainder resolved |
| Lost command response | Original outcome reconciled without blind duplication |
Run appropriate cases in authorized environments with controlled fixtures and documented limits. No live order or provider integration was executed for this article. Before production activation, confirm access, operations ownership and the actual provider-specific results.
Frequently asked questions
Does this guide provide Betfair API access?
No. Obtain account and application permissions directly through the appropriate provider process.
Can I use WebSockets to connect directly to the Stream API?
Betfair's cited documentation says no. Follow its native stream protocol; browser distribution is a separate application decision.
Does a market-data stream confirm my order outcome?
No. Use account order evidence and supported reconciliation. Market and order views serve different responsibilities.
Is a live application key enough to approve any commercial use?
Do not assume so. Confirm the actual account, operation, data-use and contractual permissions for the intended application.
What if a submission succeeds but the response is lost?
Treat it as unresolved until authoritative records establish the outcome. Retain relevant exposure and avoid blind replacement orders.
Further reading