Giter Club home page Giter Club logo

betfair-php's Introduction

betfair-php

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ù

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 [email protected].

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 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

betfair-php's People

Contributors

daaahhnuh avatar danieledangeli avatar giuliogatto avatar simoheinonen avatar violuke avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

betfair-php's Issues

Example of place bet

Hi!
Can you give me example of place bets?
I have tried , but without success.
thanks

Get the score

Hi. Is there a method to get the score of a in play event ?

For example the live score of soccer game?

Thank you

Fatal error: Uncaught Error: Class 'Betfair\Credential' not found in E:\xampp\htdocs\dashboard\angel_game\main_page.php:15 Stack trace: #0 {main} thrown in E:\xampp\htdocs\dashboard\angel_game\main_page.php on line 15

I have uploaded SSL certificate in Betfair website on and I don't know why this error occurs.

require 'vendor/autoload.php';
use Betfair\Credential;
use Betfair\Dependency\BetfairContainer;
use Betfair\Betfair;
use Betfair\Client\BetfairClient;
use Betfair\Client\JsonRpcClient;
use Betfair\Adapter\ArrayAdapter;

$credential = new Credential("s3NsobeDubtATjhy", $username,$password);
$container = new BetfairContainer();
$betfairClient = new BetfairClient($credential, new JsonRpcClient());

$betfair = new Betfair($betfairClient, $container, new ArrayAdapter());

Problem with setMarketProjection

Hello there:

Even when using original code I get this error when trying to get some data:

Catchable fatal error: Argument 1 passed to Betfair\Model\Param::setMarketProjection() must be an instance of Betfair\Model\MarketProjection, null given

Can someone help me? Tried to do:

->setMarketProjection( new MarketProjection\Betfair\Model\MarketProjection::COMPETITION )

Without any luck

Issue after install composer

Hello, i downloaded source code keeping compose.json details and then i installed composer in xampp server, it created vendor and other folders with files. I checked in browser and there are two issues.

Deprecated: The ability to pass file names to the Symfony\Component\Yaml\Yaml::parse method is deprecated since version 2.2 and will be removed in 3.0. Pass the YAML contents of the file instead. in C:\xampp\htdocs\betfair\vendor\symfony\yaml\Symfony\Component\Yaml\Yaml.php on line 58

Fatal error: Unsupported operand types in C:\xampp\htdocs\betfair\vendor\guzzlehttp\guzzle-services\src\GuzzleClient.php on line 72

I fixed first one installing "symfony/yaml": "2.6.5" but the second one i could not figure out.

Thank you for your help.

Error DSC-0018 with getMarketCatalogueFilteredBy()

MarketCatalogue::getMarketCatalogueFilteredBy()
gives an error from BetFair:

DSC-0018 - MandatoryNotDefined

maxResults in $param remains null because of this condition:

if ($this->maxResults === null) {
    $param->setMaxResults(self::MAX_RESULT);
}

library needs updating to reflect new guzzle

Package guzzlehttp/ringphp is abandoned, you should avoid using it. No replacement was suggested.
Package guzzlehttp/streams is abandoned, you should avoid using it. No replacement was suggested.

Issue while installing

E:\xampp\htdocs\practice\betfair>curl -sS https://getcomposer.org/installer | php
PHP Warning: Module 'mongo' already loaded in Unknown on line 0

Warning: Module 'mongo' already loaded in Unknown on line 0
PHP Parse error: syntax error, unexpected ''Disabling it when using Compo' (T_ENCAPSED_AND_WHITESPACE), expecting ')' in - on line 358

Parse error: syntax error, unexpected ''Disabling it when using Compo' (T_ENCAPSED_AND_WHITESPACE), expecting ')' in - on line 358
curl: (23) Failed writing body (274 != 16384)

E:\xampp\htdocs\practice\betfair>

E:\xampp\htdocs\practice\betfair>php composer.phar require erlangb/betfair-php:dev-master
PHP Warning: Module 'mongo' already loaded in Unknown on line 0

Warning: Module 'mongo' already loaded in Unknown on line 0
Could not open input file: composer.phar

Filters are not working

I have been trying out this library and i can not seem to get the filters or any parameters to work properly. Meaning, if i for example add a market filter, i still get results unaffected by the filter - all of them. Maybe i am doing something wrong, but i have spent quite some time trying this and that and it is just not working..

Small configuration:

$MARKETS = ["MATCH_ODDS", "CORRECT_SCORE", "HALF_TIME", "HALF_TIME_SCORE", "ASIAN_HANDICAP", "TOTAL_GOALS", "FIRST_HALF_GOALS_05", "FIRST_HALF_GOALS_15", "FIRST_HALF_GOALS_25", "OVER_UNDER_05", "OVER_UNDER_15", "OVER_UNDER_25", "OVER_UNDER_35", "OVER_UNDER_45", "OVER_UNDER_55"];
$COMPETITIONS = [7317506, 164952, 15, 3126267, 888275, 3085749, 892425, 4848838, 862638, 21, 1987477, 158146, 63, 840808, 1242586, 119, 121, 123, 125, 127, 2901699, 862545, 873203, 57, 111, 13051, 6294086, 3992967, 1985077, 219, 6301, 943450, 907589, 3126286, 83, 1587980, 1661891, 887178, 2609677, 827754, 836645, 5449376, 403085, 876442, 9513, 863810, 862579, 3006957, 880458, 101, 891179, 8141281, 920223, 4608865, 872215, 1888360, 1658999, 139, 3089001, 908196, 7897688, 3061353, 895129, 5618298, 857992, 844197, 65, 853948, 852459, 4556663, 4556656, 3792498, 3221481, 4040072, 17, 1842928, 311575, 4556576, 905441, 3127737, 879221, 827078, 1327393, 920858, 868392, 872270, 2938065, 115, 6103298, 175680, 7946082, 4732508, 1065530, 4517491, 1478090, 97807, 4431442, 821269, 2356065, 97, 32246, 103, 113, 194215, 843454, 7942109, 309948, 3729355, 13, 803690, 6566654, 887158, 7616742, 3242305, 839575, 842258, 4905, 4802204, 5448752, 1079277, 318343, 984404, 7197874, 3037492, 856134, 2079376, 59, 886734, 4802285, 1062024, 8053761, 7138694, 61351, 97855];
$IN_PLAY_ONLY = true;
$EVENT_TYPES = [1];

Queries:

(create betfair object) 
....
$marketCatalogue = $betfair->getBetfairMarketCatalogue();
$marketFilter = MarketFilter::create()
    ->setCompetitionIds($COMPETITIONS)
    ->setMarketBettingTypes($MARKETS)
    ->setInPlayOnly($IN_PLAY_ONLY);
return $marketCatalogue
    ->withMarketProjections(array(MarketProjection::EVENT))
    ->withMarketFilter($marketFilter)
    ->withMaxResult(1000)
    ->listMarketCatalogue($EVENT_TYPES);

Result:

This returns 99 results without event info (market projection), not in play events, not the specified competitions and all of the markets

....
[95] => Array
    (
        [marketId] => 1.118280148
        [marketName] => 2015/16 Winner
        [totalMatched] => 5419764.80794
    )

[96] => Array
    (
        [marketId] => 1.118280287
        [marketName] => Top 5 Finish 2015/16
        [totalMatched] => 19885.955712
    )

[97] => Array
    (
        [marketId] => 1.118280285
        [marketName] => Team to Score Most Goals 2015/16
        [totalMatched] => 11338.361174
    )

[98] => Array
    (
        [marketId] => 1.118280283
        [marketName] => Straight Tricast 2015/16
        [totalMatched] => 9909.808496
    )

[99] => Array
    (
        [marketId] => 1.118880359
        [marketName] => Top London Club 2015/16 - Please Read Rules
        [totalMatched] => 3020.681958
    )

Could not find a matching version of package erlangb/betfair-php

Hi, when I run the command "php composer.phar require erlangb/betfair-php:dev-master" I receive this error: [InvalidArgumentException]
Could not find a matching version of package erlangb/betfair-php. Check the
package spelling, your version constraint and that the package is availabl
e in a stability which matches your minimum-stability (stable).

Why?

Get markets ids

Hi, how do i get the markets ids from an event? And after i have the market id, how can i get the odds of that market?

Place bets

What is the simpler way to place and remove bets on betfair via api?

SSL certificate problem

Hello and tahnk you for this project.

I installed project with composer with follow composer.json
{
"name": "Alex",
"description": "My app",
"require": {
"php": ">=5.4",
"erlangb/betfair": "0.2.*",
"symfony/yaml": "~2.6",
"symfony/finder": "~2.6"
},
"autoload": {
"psr-0" : { "betfair" : "src" }
}
}

Now, i'm reciving this issue. I tried to install original json file but i still gets operator += issue
This is issue i'm geting. Thank you

Fatal error: Uncaught exception 'GuzzleHttp\Ring\Exception\RingException' with message 'cURL error 60: SSL certificate problem: unable to get local issuer certificate' in C:\xampp\htdocs\betfair\vendor\guzzlehttp\ringphp\src\Client\CurlFactory.php:126 Stack trace: #0 C:\xampp\htdocs\betfair\vendor\guzzlehttp\ringphp\src\Client\CurlFactory.php(90): GuzzleHttp\Ring\Client\CurlFactory::createErrorResponse(Object(GuzzleHttp\Ring\Client\CurlHandler), Array, Array) #1 C:\xampp\htdocs\betfair\vendor\guzzlehttp\ringphp\src\Client\CurlHandler.php(78): GuzzleHttp\Ring\Client\CurlFactory::createResponse(Object(GuzzleHttp\Ring\Client\CurlHandler), Array, Array, Array, Resource id #152) #2 C:\xampp\htdocs\betfair\vendor\guzzlehttp\ringphp\src\Client\Middleware.php(54): GuzzleHttp\Ring\Client\CurlHandler->__invoke(Array) #3 C:\xampp\htdocs\betfair\vendor\guzzlehttp\ringphp\src\Client\Middleware.php(30): GuzzleHttp\Ring\Client\Middleware::GuzzleHttp\Ring\Client{closure}(Array) #4 C:\xampp\htdocs\betfair\vendor\guzzlehttp\guzzle\src\Req in C:\xampp\htdocs\betfair\vendor\guzzlehttp\command\src\AbstractClient.php on line 171

Locale does not work

I printed events result like this but time zone is for Europe/London.

[0] => Array
(
[event] => Array
(
[id] => 27417270
[name] => Carpi v Brescia
[countryCode] => IT
[timezone] => Europe/London
[openDate] => 2015-04-18T13:00:00.000Z
)

        [marketCount] => 8
    )

I checked API docummentation in Betfair website and i found i can change with LOCALE param.
In your function getAllEventFilteredByEventTypeIds i added ->setLocale("ES"); for a spanish timezone but it still shows same result Europe/London.

public function getAllEventFilteredByEventTypeIds(array $eventTypeIds)
{
$marketFilter = $this->createMarketFilter();
$marketFilter->setEventTypeIds($eventTypeIds);
$param = $this->createParam($marketFilter)
->setLocale("ES");

    return $this->adapter->adaptResponse(
        $this->apiNgRequest(self::API_METHOD_NAME, $param)
    );
}

Do you know how can i change language, timezone and country?
I want deploy it in Colombia.
Thank you for your help, API and you time.
I hope contribute soon as possible when i get ideas after play with it.
Alex

Proxy Support

My server is on a blocked location and I need to use a VPN to change the entire server network just to access betfair, it would be cool to implement a proxy on future versions.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.