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.

Sample Code

The following samples are currently available:

Client Libraries & Sample Applications

Language
Available From
Description
Developed By
C#https://github.com/joelpob/betfairngAPI-NG Client Library for c#Community member - joelpob
Javahttps://github.com/joelpob/jbetfairngClient library for JavaCommunity member - joelpob
Excel/VBAhttps://github.com/betfair/API-NG-Excel-ToolkitExcel Sample Spreadsheet ApplicationRobin Barrett
Delphihttps://github.com/betfair/API-NG-Delphi-ClientAPI-NG Client Library for DelphiCommunity member - khughes
Javascripthttps://github.com/AlgoTrader/betfairAPI-NG Client Library for Node.jsCommunity member - Algotrader
Perlhttps://github.com/MyrddinWyllt/WWW-BetfairNGPerl Library for API-NGCommunity member - Merlin
PHPhttps://github.com/danieledangeli/betfair-phpAPI-NG Client Library for PHPCommunity member - daniele8805
Rubyhttps://github.com/mikecmpbll/betfairRuby wrapper for API-NGCommunity member - mikecmpbll 
Pythonhttps://github.com/betcode-org/betfairLightweight Python wrapper for Betfair API-NG (with streaming)Community member - LiamP
Pythonhttps://github.com/betcode-org/flumineBetting Trading FrameworkCommunity member - LiamP
Scalahttps://github.com/city81/betfair-service-ngScala sample code for API-NGCommunity member - theswan1
Rhttps://github.com/phillc73/abettorSample code for RCommunity member - phill_c
C++https://github.com/captain-igloo/greentopC++ Betfair API ClientCommunity member - plachner
C++https://github.com/tosinalagbe/hedgHigh-frequency trading framework for BetfairCommunity member - tosin
Rusthttps://docs.rs/botfair/0.3.0/botfair/Rust bindings for the Betfair APICommunity member - esotericnonsense

Stream API

Language
Available From
Description
Developed By
C#https://github.com/betfair/stream-api-sample-code/tree/master/csharpSample application for Stream APIBetfair 
Javahttps://github.com/betfair/stream-api-sample-code/tree/master/javaSample application for Stream APIBetfair
Node.jshttps://github.com/betfair/stream-api-sample-code/tree/master/node.jsSample application for Stream APIBetfair

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 Applicationhttps://www.betfairhistoricdata.co.uk/

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
Pythonhttps://github.com/mberk/betfairvizCreate visualisations of Betfair order booksCommunity member - mberk
Pythonhttps://github.com/betcode-org/betfairParse/output historical data allowing back testing or with a custom listener, csv creationCommunity 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

Language

Available From

Description

Developed By

Rhttps://betfair-datascientists.github.io/tutorials/apiRtutorial/Betfair API R TutorialBetfair Australia
Pythonhttps://betfair-datascientists.github.io/tutorials/jsonToCsvRevisited/Historical data - Json to Csv Tutorial using PythonBetfair Australia
Pythonhttps://betfair-datascientists.github.io/tutorials/apiPythontutorial/Betfair API Python TutorialBetfair Australia
Pythonhttps://betfair-datascientists.github.io/historicData/backtestingRatingsTutorial/#complete-codeBacktesting wagering models with Betfair JSON stream dataTom Bishop
Pythonhttps://betfair-datascientists.github.io/tutorials/How_to_Automate_1/

How to Automate I: Understanding Flumine

Betfair Australia
Pythonhttps://betfair-datascientists.github.io/tutorials/How_to_Automate_2/

How to Automate II: Backing or laying the 1st/2nd/.../nth favorite shot

Betfair Australia
         Pythonhttps://betfair-datascientists.github.io/tutorials/How_to_Automate_3/

How to Automate III: Betfair Data Scientist's Models

Betfair Australia
         Python

https://betfair-datascientists.github.io/tutorials/How_to_Automate_4/

How to Automate IV: Automate your own Model

Betfair Australia
Pythonhttps://betfair-datascientists.github.io/tutorials/How_to_Automate_5/

How to Automate 5

Betfair Australia

Books

Language
Available From
Description
Author
Visual Basichttp://www.amazon.co.uk/Programming-Betfair-Creating-Trading-Applications/dp/151143211XA Guide to Creating Trading Application for API-NG James Butler