Sample Code
Sample Code, Client Libraries & Tutorials
As well as sample code developed by Betfair, this page allows you to find sample code or documentation prepared by members of the Developer Program community.
If you would like to contribute to this space, please contact Developer Support
All Betfair-developed sample code follows a typical workflow:
Find the next UK Horse Racing Win market
Get prices for the market
Place a bet on the market
Handle the error returned by the API when the bet fails as it is below the minimum stake size.
Please Note: In order to aid ease of understanding, the basic Betfair samples are not intended to show certain best practices for speed and throughput. Well-designed applications should follow the best practices for client design of the application/language platform and should optimise on an HTTP request level with features such as requesting gzip'd responses and http connection keep alives. Please see Optimizing API Application Performance for further details.
The following samples are currently available:
Language | Documentation | Available From | Description | Developed By |
---|---|---|---|---|
Java | https://github.com/betfair/API-NG-sample-code/tree/master/java | Sample Code for Java | Betfair | |
Javascript | https://github.com/betfair/API-NG-sample-code/tree/master/javascript | Sample Code for Node.js | Betfair | |
Python | https://github.com/betfair/API-NG-sample-code/tree/master/python | Sample Code for Python | Betfair | |
PHP | https://github.com/betfair/API-NG-sample-code/tree/master/php | Sample Code for PHP | Betfair | |
Excel/VBA | https://github.com/betfair/API-NG-sample-code/tree/master/vba | Sample Code for Excel/VBA | Betfair | |
C# | https://github.com/betfair/API-NG-sample-code/tree/master/cSharp | Sample Code for C# | Betfair | |
Curl | https://github.com/betfair/API-NG-sample-code/tree/master/curl | Sample Curl Requests | Betfair | |
Perl | https://github.com/betfair/API-NG-sample-code/tree/master/perl | Sample Code for Perl | Betfair | |
Delphi | Sample Code for Delphi | Community member - jamiei | ||
Clojure | Sample Code for Clojure | Community member - jamiei |
Client Libraries & Sample Applications
Language | Available From | Description | Developed By |
---|---|---|---|
C# | API-NG Client Library for c# | Community member - joelpob | |
Java | Client library for Java | Community member - joelpob | |
Excel/VBA | Excel Sample Spreadsheet Application | Robin Barrett | |
Delphi | API-NG Client Library for Delphi | Community member - khughes | |
Javascript | API-NG Client Library for Node.js | Community member - Algotrader | |
Perl | Perl Library for API-NG | Community member - Merlin | |
PHP | API-NG Client Library for PHP | Community member - daniele8805 | |
Ruby | Ruby wrapper for API-NG | Community member - mikecmpbll | |
Python | Lightweight Python wrapper for Betfair API-NG (with streaming) | Community member - LiamP | |
Python | Betting Trading Framework | Community member - LiamP | |
Scala | Scala sample code for API-NG | Community member - theswan1 | |
R | Sample code for R | Community member - phill_c | |
C++ | C++ Betfair API Client | Community member - plachner | |
C++ | High-frequency trading framework for Betfair | Community member - tosin | |
Rust | Rust bindings for the Betfair API | Community member - esotericnonsense |
Stream API
Language | Available From | Description | Developed By |
---|---|---|---|
C# | https://github.com/betfair/stream-api-sample-code/tree/master/csharp | Sample application for Stream API | Betfair |
Java | https://github.com/betfair/stream-api-sample-code/tree/master/java | Sample application for Stream API | Betfair |
Node.js | https://github.com/betfair/stream-api-sample-code/tree/master/node.js | Sample application for Stream API | Betfair |
Historical Data
Code for processing the data provided by the Betfair Exchange historical data service available via https://historicdata.betfair.com
Language | Available From | Description | Developed By |
---|---|---|---|
Web Application | Simple web application for converting downloaded historical data files to CSV format. Click Betfair Historical Data Processor - Quick Guide.pdf for a user guide | Community member - LiamP | |
Python | Create visualisations of Betfair order books | Community member - mberk | |
Python | Parse/output historical data allowing back testing or with a custom listener, csv creation | Community member - LiamP | |
Excel/VBA | Simple Excel workbook for use with BASIC historical data Coverts files into Excel and provides basic custom reporting tools | Robin Barrett | |
Other Resources | Competition & Event Mapping Data for all historical markets from 2018-2023 (Please note: mapping data prior to 2018 isn't available) | Betfair |
Tutorials