geniv / betfair
Betfair API PHP 5.4+ library
Requires
- php: >=5.4.0
- guzzlehttp/command: 0.7.*
- guzzlehttp/guzzle: ~5.0
- guzzlehttp/guzzle-services: 0.5.*
- symfony/finder: ~2.6
- symfony/yaml: ~2.6
Requires (Dev)
- fabpot/php-cs-fixer: @stable
- phpspec/phpspec: 2.1.1
This package is auto-updated.
Last update: 2021-01-13 12:09:11 UTC
README
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ù
Installation
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 https://getcomposer.org/installer | 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 https://getcomposer.org/installer | php
$ php composer.phar install
Now you can add the autoloader, and you will have access to the library:
<?php require 'vendor/autoload.php';
Usage
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( $appKey, $username, $pwd, array() );
The last parameters are the options, which you can customize the Betfair object. The following options are available:
- loginEndpoint: array('loginEndpoint' => 'https://identitysso.betfair.it/api/login') 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(); $eventBetfairHelper->getAllEventFilteredByEventTypeIds(array(1,2));
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() ->setTextQuery("Lazio") ->setCompetitionIds(array($seriaACompetition)); $betfairEvent->withMarketFilter($marketFilter); $events = $betfairEvent->getResults();
If an object doesn't require a Betfair Market Filter, you can simply specify the Param:
$betfair = BetfairFactory::createBetfair( $appKey, $username, $pwd ); $clearedOrder = $betfair->getBetfairClearedOrder(); $param = $clearedOrder->createParam(); $param->setBetStatus(BetStatus::SETTLED); $clearedOrder->withParam($param); $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(); $param->setMarketFilter($marketFilter);
Both Param and MarketFilter object have a list of methods to set the properties in a "builder" style:
$marketFilter = MarketFilter::create() ->setEventIds(array($events)) ->setCompetitionIds(array($competitions)) ->setBspOnly(true) ->setInPlayOnly(true);
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 dangeli88.daniele@gmail.com.
Todo
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 testPHPspec test refactoringHandling 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