1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PeterColes\Betfair\Api; |
4
|
|
|
|
5
|
|
|
use PeterColes\Betfair\Http\Client as HttpClient; |
6
|
|
|
|
7
|
|
|
class Betting |
8
|
|
|
{ |
9
|
|
|
const ENDPOINT = 'https://api.betfair.com/exchange/betting/rest/v1.0/'; |
10
|
|
|
|
11
|
|
|
protected $httpClient; |
12
|
|
|
|
13
|
|
|
public function __construct(HttpClient $httpClient = null) |
14
|
|
|
{ |
15
|
|
|
$this->httpClient = $httpClient ?: new HttpClient; |
16
|
|
|
} |
17
|
|
|
|
18
|
|
View Code Duplication |
public function listMarketcatalogue($filter = [ ], $marketProjection = [ ], $sort = null, $maxResults = 100, $locale = null) |
|
|
|
|
19
|
|
|
{ |
20
|
|
|
return $this->httpClient |
21
|
|
|
->setMethod('post') |
22
|
|
|
->setEndPoint(self::ENDPOINT.'listMarketCatalogue/') |
23
|
|
|
->authHeaders() |
24
|
|
|
->addHeader([ 'Content-Type' => 'application/json' ]) |
25
|
|
|
->setFilter($filter) |
26
|
|
|
->setProjection('marketProjection', $marketProjection) |
27
|
|
|
->setSort($sort) |
28
|
|
|
->setMaxResults($maxResults) |
29
|
|
|
->setLocale($locale) |
30
|
|
|
->send(); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function listMarketBook($marketIds = [ ], $priceProjection = null, $orderProjection = null, $matchProjection = null, $currencyCode = null, $locale = null) |
34
|
|
|
{ |
35
|
|
|
return $this->httpClient |
36
|
|
|
->setMethod('post') |
37
|
|
|
->setEndPoint(self::ENDPOINT.'listMarketBook/') |
38
|
|
|
->authHeaders() |
39
|
|
|
->addHeader([ 'Content-Type' => 'application/json' ]) |
40
|
|
|
->setMarketIds($marketIds) |
41
|
|
|
->setProjection('priceProjection', $priceProjection) |
42
|
|
|
->setProjection('orderProjection', $orderProjection) |
43
|
|
|
->setProjection('matchProjection', $matchProjection) |
44
|
|
|
->setCurrencyCode($currencyCode) |
45
|
|
|
->setLocale($locale) |
46
|
|
|
->send(); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
View Code Duplication |
public function listMarketProfitAndLoss($marketIds = [ ], $includeSettledBets = false, $includeBspBets = false, $netOfCommission = false) |
|
|
|
|
50
|
|
|
{ |
51
|
|
|
return $this->httpClient |
52
|
|
|
->setMethod('post') |
53
|
|
|
->setEndPoint(self::ENDPOINT.'listMarketProfitAndLoss/') |
54
|
|
|
->authHeaders() |
55
|
|
|
->addHeader([ 'Content-Type' => 'application/json' ]) |
56
|
|
|
->setMarketIds($marketIds) |
57
|
|
|
->setFlag('includeSettledBets', $includeSettledBets) |
|
|
|
|
58
|
|
|
->setFlag('includeBspBets', $includeBspBets) |
|
|
|
|
59
|
|
|
->setFlag('netOfCommission', $netOfCommission) |
|
|
|
|
60
|
|
|
->send(); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function listTimeRanges($marketFilter, $timeGranularity) |
64
|
|
|
{ |
65
|
|
|
return $this->httpClient |
66
|
|
|
->setMethod('post') |
67
|
|
|
->setEndPoint(self::ENDPOINT.'listTimeRanges/') |
68
|
|
|
->authHeaders() |
69
|
|
|
->addHeader([ 'Content-Type' => 'application/json' ]) |
70
|
|
|
->setFilter($marketFilter) |
71
|
|
|
->setTimeGranularity($timeGranularity) |
72
|
|
|
->send(); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Six Exchange methods have an identical API, so we bundle them into a single magic call e.g. |
77
|
|
|
* @method listCompetitions(array $filters, string $locale) |
78
|
|
|
* @return array |
79
|
|
|
*/ |
80
|
|
|
public function __call($method, $params) |
81
|
|
|
{ |
82
|
|
|
if (in_array($method, [ 'listCompetitions', 'listCountries', 'listEvents', 'listEventTypes', 'listMarketTypes', 'listVenues' ])) { |
83
|
|
|
|
84
|
|
|
$filter = isset($params[ 0 ]) ? $params[ 0 ] : [ ]; |
85
|
|
|
$locale = isset($params[ 1 ]) ? $params[ 1 ] : [ ]; |
86
|
|
|
|
87
|
|
|
return $this->httpClient |
88
|
|
|
->setMethod('post') |
89
|
|
|
->setEndPoint(self::ENDPOINT.$method.'/') |
90
|
|
|
->authHeaders() |
91
|
|
|
->addHeader([ 'Content-Type' => 'application/json' ]) |
92
|
|
|
->setFilter($filter) |
93
|
|
|
->setLocale($locale) |
94
|
|
|
->send(); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.