Betfair API PHP 5.4+ library

0.2.0 2015-03-01 01:30 UTC

This package is not auto-updated.

Last update: 2024-05-15 08:33:48 UTC


SensioLabsInsight Scrutinizer Code Quality

Latest Stable Version Total Downloads Latest Unstable Version License Monthly Downloads Daily Downloads

Protip: There was big chnages in the last days, please use the version 0.1.1 instead of dev-master for back compatibility. Have a look on: erlangb/betfair page to choose a stable version to use, instead of dev-master

This PHP 5.4+ library helps you to interact with the Betfair API via PHP. Menù


This library can be found on Packagist. The recommended way to install this is through composer.

Run these commands to install composer, the library and its dependencies:

$ curl -sS | php
$ php composer.phar require erlangb/betfair-php:dev-master

Or edit composer.json and add:

    "require": {
        "erlangb/betfair": "dev-master"

Protip: you should browse the erlangb/betfair page to choose a stable version to use, instead of dev-master

And install dependencies:

$ curl -sS | php
$ php composer.phar install

Now you can add the autoloader, and you will have access to the library:


require 'vendor/autoload.php';


Obtain an APP_KEY

To use this library you have to obtain an APP_KEY from Betfair

Obtain a Betfair Object

  • By using the factory interface
use Betfair\BetfairFactory;
require 'vendor/autoload.php';

$betfair = BetfairFactory::createBetfair(

The last parameters are the options, which you can customize the Betfair object. The following options are available:

  • loginEndpoint: array('loginEndpoint' => '') to change the login endpoint
  • responseAdapter: array('responseAdapter' => new ArrayAdapter()) to change the response adapter
  • The available adapters are: * ArrayAdapter * ArrayRpcAdapter * JsonRpcAdapter

Protip: You can also implement your own Adapter by implement the AdapterInterface and pass it as an option

Query the Betfair API with the helpers objects.

Once you got a Betfair object you can query the Betfair API.

There are several ways to do that.

The simplest one is just to use the available helpers methods. For instance, if you want to get all the events "filtered by event type ids" you can simply:

require 'vendor/autoload.php';

$eventBetfairHelper = $betfair->getBetfairEvent();

The available helpers are:

  • $betfair->getBetfairEvent();
  • $betfair->getBetfairEventType();
  • $betfair->getBetfairCompetition();
  • $betfair->getBetfairCountry();
  • $betfair->getBetfairMarketBook();
  • $betfair->getBetfairMarketCatalogue();
  • $betfair->getBetfairMarketType();
  • $betfair->getClearedOrder();
  • $betfair->getCurrentOrder();
  • $betfair->getVenues();

Protip: With the simple usage you can have access to the already existing helpers. Please feel free to contribute to this library by adding more helpers.

If an helper method is not present, you can simply use the object by specifying the parameters to execute a custom query:

$seriaACompetition = 81;

$betfairEvent = $betfair->getBetfairEvent();

$marketFilter = MarketFilter::create()


$events = $betfairEvent->getResults();

If an object doesn't require a Betfair Market Filter, you can simply specify the Param:

$betfair = BetfairFactory::createBetfair(

$clearedOrder = $betfair->getBetfairClearedOrder();

$param = $clearedOrder->createParam();


$results = $clearedOrder->getResults();

Query the Betfair API without the helpers

If in any case you want to query the API without using the helpers you can just use the "api" function on the Betfair object:

public function api(ParamInterface $param, $method);

It will accept a Param and a method name (listEevents, listMarketCatalogue ...)

To Obtain a Param object just use the proper factory:

$param = Param::create();

if you want to add a market filter to the Param Object, just use the factory and then set it as following:

$marketFilter = MarketFilter::create();

Both Param and MarketFilter object have a list of methods to set the properties in a "builder" style:

$marketFilter = MarketFilter::create()

Read carefully the Betfair documentation API to use the proper properties with these objects.

How to contribute

I'm very glad to be helped to maintain and extend this library. Please feeling free to clone the repository and collaborate with me.

Reporting Issues

I would love to hear your feedback. Report issues using the Github Issue Tracker or email me at


The library is actually "in dev" state and a lot of things to be done.

  • Enabling guzzle library
  • Implements more "Betfairs objects" to extend the API (priority on Order object)
  • Add more PHPspec test
  • PHPspec test refactoring
  • Handling login or app key errors in array and json RPC adapters (result is not set)
  • Integration tests after the last changes
  • Add more betfair Account API helpers