dcro/simple-betfair-php-api

对Betfair API (API-NG)的一个简单PHP实现

dev-master 2014-09-17 16:50 UTC

This package is not auto-updated.

Last update: 2024-09-24 03:13:54 UTC


README

这是一个对Betfair API (API-NG)的简单PHP实现。它处理针对SSO端点的身份验证以及对JSON-RPC端点的请求。

安装

您可以从GIT获取文件,或者通过Composer安装库。要使用Composer,只需将以下内容添加到您的composer.json文件中。

{
    "require": {
        "dcro/simple-betfair-php-api": "dev-master"
    }
}

如何使用它?

要初始化API,您需要传递一个数组,包含您的应用程序密钥(appKey)、usernamepassword和证书文件(cert)。有关如何获取这些信息的详细信息,请查看Betfair API文档。

// Set the API configuration
$configuration = array(
    'appKey'   => '<betfair-application-key>',
    'username' => '<betfair-api-username>',
    'password' => '<betfair-api-password>',
    'cert'     => '/path/to/your/certificate.pem',
)

$api = new Betfair\SimpleAPI($configuration);

要对API端点发起请求,调用request()方法如下

try {
    // List event types
    $response = $api->request('listEventTypes', '{"filter":{}}');

} catch (Exception $ex) {
    // handle the exception
}

更复杂的请求示例,获取来自大不列颠的特定赛事类型(<your-event-type-id>)和WIN市场的赛事目录。

try {
    // Define the parameters
    $params = '{
                   "filter" : {
                       "eventTypeIds" : ["<your-event-type-id>"],
                       "marketCountries" : ["GB"],
                       "marketTypeCodes" : ["WIN"],
                       "marketStartTime" : {"from":"' . date('c') . '"}
                   },
                   "sort" : "FIRST_TO_START",
                   "maxResults" : "1000",
                   "marketProjection" : ["EVENT","MARKET_START_TIME","RUNNER_DESCRIPTION","MARKET_DESCRIPTION"]
              }';

    // Get the market catalogue
    $response = $api->request('listMarketCatalogue', $params);

} catch (Exception $ex) {
    // handle the exception
}