erlangb/betfair
Composer 安装命令:
composer require erlangb/betfair
包简介
Betfair API PHP 5.4+ library
关键字:
README 文档
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
erlangb/betfair 适用场景与选型建议
erlangb/betfair 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.57k 次下载、GitHub Stars 达 47, 最近一次更新时间为 2014 年 04 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「betfair」 「betting」 「bet」 「betting api」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 erlangb/betfair 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 erlangb/betfair 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 erlangb/betfair 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP package for dealing with different formats of betting odds: decimal (European), fractional (British), and moneyline (American)
Betfair Exchange API wrapper
A PSR-7 compatible library for making CRUD API endpoints
Api client for pinnaclesports
Simple integration with Goalserve API for Laravel
Betfair API PHP 5.4+ library
统计信息
- 总下载量: 1.57k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 47
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-04-19