Programming for Sports Betting

There are many areas in which programming can assist the sports trader. Automation of your trading allows you to remove emotion from your trades. An emotional trade can often be a losing trade. If your trading algorithms are profitable then they will succeed without human intervention.

Programming also permits you to trade markets in parallel thus allowing for a scaling up of your trading. Why trade only one market at a time when you can be trading and profiting from many markets simultaneously?

Listed here are areas in which programming can automate and assist the trader.

  • Manual trading
  • Automated trading
  • Web Scraping for data
  • Quantitative Analysis

Manual Trading

There is much third party software to assist the manual trader as listed in the Trading Software section of this website. However, you may want to progam your own software if you have security worries about third party software or wish to prevent your proprietary algorithms from reaching the public domain.

You can read more about programming your own software in Write Your Own Betfair Software

Automated Trading

As your skill as a trader improves you will want to scale up your trading through automation. A manual trader can only effectively trade one market at a time. By automating your trading, a bot can perform simple and/or repetitive tasks allowing the trader to free up time to trade on multiple markets with the possibility of increased return on investment.

Areas of automation include the following

  • Machine access to betting markets using price gathering and trading bots. 
  • Gathering of sports data from web sites by way of web scraping. 
  • Charting of time series data.
  • Pricing algorithms for determining fair odds. (See also Sports betting arbitrage)
  • Trading algorithms for routing trades to the exchange/bookmaker with the best price. Algorithmic Trading

Web Scraping

Although prices can easily be obtained through the betting exchange or bookmaker's website there maybe additional data that you require and for which there is no API to assist you. In horse racing there are many online publications where you can download race data for previous races. The Racing Post is one such site. Through use of RegEx or serialization it is possible to download a page from an online source and parse it into a database. (More on this to follow)

Quantitative Analysis

When you have collected your data you will want to analyse it to generate trading rules. Software for analysis could simply be a spreadsheet, to more mathematical software such as R. Programming in VBA can enhance the capabilities of Excel. The quant can also develop software such as a Monte Carlo simulator for simulating sports event prior to them taking place or develop software utilising machine learning techniques to discover trading rules. (More on this to follow)

Further Reading

I recommend the following texts

A guide to creating sports trading applications with API-NG. This book teaches you how to build sports trading applications, from gathering prices to placing bets into Betfair's exchange. The reader is also taught how to build a database of prices and volume for offline analysis, automating Betfair charts and a brief look at advanced techniques; trading indicators, volume weighted average price, arbitrage, machine learning, Monte Carlo methods and more.

A complete telling of one man's modelling of the sport of Jai Alai and his profitable automated betting on the sport. Full Review


  1. Would be interested to read more on web scraping in current RP format. A few years ago I was just using web queries in excel. Would use a tool to pull up all the URLs for the days racing then dump them into excel and run the vba to pull in the web query table for each link. Then automate the data clean up and formatting. Cannot do this now..

    1. My next book will have a little on web scraping. Due to copyright, I have to be careful not to make explicit mention of any website.

      Hopefully, people will know what "Chasing Toast" refers to.

  2. Is web scraping legal James?

    1. There might be copyright issues depending on what you do with the scraped data but not the actual scraping itself.

      Plenty of books teaching you how to scrape. No publishers being dragged through the courts.

  3. Hello,

    I bought the Programming for Betfair and at page 19, at the Betfair Visualisers section, the given link does not work.

    Can you please provide updated link?

    1. Obviously, you are reading the book too fast and have not found the support URL.

      Start again. Slowly.

  4. Hi James,

    Is there any way we can reach you via a personal message ? I.e an email address please?

    1. Leave your email address in a comment.

      I don't publish comments with email addresses.

      I will contact you when I get your email address.

  5. Hi James is there anyway a stoploss can be programmed for trading the football markets on betfair ,I have tried everything but when the market suspends my stoploss disappears.Rgards Billy

    1. Look through the literature for 'persistence'.

  6. Hi James,

    Working through your book and doing well so far, i have an issue though regarding the end result on P40. Hoping my email shows i can explain in more detail the issue.

    1. Look at the earliest pages of the book for the support web page. From there you will find errata and other help.