1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace IndependentReserve; |
4
|
|
|
|
5
|
|
|
use GuzzleHttp\Client as GuzzleClient; |
6
|
|
|
use GuzzleHttp\Message\Response; |
7
|
|
|
use IndependentReserve\Object\FxRate; |
8
|
|
|
use IndependentReserve\Object\MarketSummary; |
9
|
|
|
use IndependentReserve\Object\OrderBook; |
10
|
|
|
use IndependentReserve\Object\RecentTrades; |
11
|
|
|
use IndependentReserve\Object\TradeHistorySummary; |
12
|
|
|
use stdClass; |
13
|
|
|
|
14
|
|
|
class PublicClient |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var GuzzleClient |
18
|
|
|
*/ |
19
|
|
|
protected $client; |
20
|
|
|
|
21
|
14 |
|
public function __construct() |
22
|
|
|
{ |
23
|
14 |
|
$this->client = new GuzzleClient(); |
24
|
14 |
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @param string $url |
28
|
|
|
* @return mixed |
29
|
|
|
*/ |
30
|
9 |
|
protected function get($url) |
31
|
|
|
{ |
32
|
|
|
/** @noinspection PhpVoidFunctionResultUsedInspection */ |
33
|
|
|
/** @var Response $response */ |
34
|
9 |
|
$response = $this->client->get($url); |
35
|
9 |
|
return json_decode($response->getBody()); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param string $endpoint The public endpoint name. |
40
|
|
|
* @param array $params Optional named parameters. |
41
|
|
|
* @param string $visibility `Public` or `Private`. |
42
|
|
|
* @param string $method |
43
|
|
|
* @return mixed |
44
|
|
|
*/ |
45
|
13 |
|
public function getEndpoint($endpoint, array $params = array(), $visibility = 'Public', |
46
|
|
|
$method = 'GET') |
47
|
|
|
{ |
48
|
13 |
|
$url = "https://api.independentreserve.com/$visibility/$endpoint"; |
49
|
13 |
|
if ('GET' === $method) { |
50
|
9 |
|
$query = http_build_query($params); |
51
|
9 |
|
return $this->get("$url?$query"); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** @var \GuzzleHttp\Message\Response $response */ |
55
|
|
|
/** @noinspection PhpVoidFunctionResultUsedInspection */ |
56
|
4 |
|
$response = $this->client->post($url, [ 'json' => $params ]); |
57
|
4 |
|
return $response->getBody()->getContents(); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Returns a list of valid primary currency codes. These are the digital currencies which can be |
62
|
|
|
* traded on Independent Reserve. |
63
|
|
|
* @return array |
64
|
|
|
*/ |
65
|
1 |
|
public function getValidPrimaryCurrencyCodes() |
66
|
|
|
{ |
67
|
1 |
|
return $this->getEndpoint('GetValidPrimaryCurrencyCodes'); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Returns a list of valid secondary currency codes. These are the fiat currencies which are |
72
|
|
|
* supported by Independent Reserve for trading purposes. |
73
|
|
|
* @return array |
74
|
|
|
*/ |
75
|
1 |
|
public function getValidSecondaryCurrencyCodes() |
76
|
|
|
{ |
77
|
1 |
|
return $this->getEndpoint('GetValidSecondaryCurrencyCodes'); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Returns a list of valid limit order types which can be placed onto the Independent Reserve |
82
|
|
|
* exchange platform. |
83
|
|
|
* @return array |
84
|
|
|
*/ |
85
|
1 |
|
public function getGetValidLimitOrderTypes() |
86
|
|
|
{ |
87
|
1 |
|
return $this->getEndpoint('GetValidLimitOrderTypes'); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Returns a list of valid market order types which can be placed onto the Independent Reserve |
92
|
|
|
* exchange platform. |
93
|
|
|
* @return array |
94
|
|
|
*/ |
95
|
1 |
|
public function getValidMarketOrderTypes() |
96
|
|
|
{ |
97
|
1 |
|
return $this->getEndpoint('GetValidMarketOrderTypes'); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Returns a current snapshot of the Independent Reserve market for a given currency pair. |
102
|
|
|
* @param string $primaryCurrencyCode The digital currency for which to retrieve market summary. |
103
|
|
|
* Must be a valid primary currency, which can be checked via the |
104
|
|
|
* getValidPrimaryCurrencyCodes() method. |
105
|
|
|
* @param string $secondaryCurrencyCode The fiat currency in which to retrieve market summary. |
106
|
|
|
* Must be a valid secondary currency, which can be checked via the |
107
|
|
|
* getValidSecondaryCurrencyCodes() method. |
108
|
|
|
* @return MarketSummary |
109
|
|
|
*/ |
110
|
1 |
|
public function getMarketSummary($primaryCurrencyCode, $secondaryCurrencyCode) |
111
|
|
|
{ |
112
|
1 |
|
return MarketSummary::createFromObject($this->getEndpoint('GetMarketSummary', [ |
113
|
1 |
|
'primaryCurrencyCode' => $primaryCurrencyCode, |
114
|
1 |
|
'secondaryCurrencyCode' => $secondaryCurrencyCode, |
115
|
1 |
|
])); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Returns the Order Book for a given currency pair. |
120
|
|
|
* @param string $primaryCurrencyCode The digital currency for which to retrieve order book. |
121
|
|
|
* Must be a valid primary currency, which can be checked via the |
122
|
|
|
* getValidPrimaryCurrencyCodes() method. |
123
|
|
|
* @param string $secondaryCurrencyCode The fiat currency in which to retrieve order book. Must |
124
|
|
|
* be a valid secondary currency, which can be checked via the |
125
|
|
|
* getValidSecondaryCurrencyCodes() method. |
126
|
|
|
* @return OrderBook |
127
|
|
|
*/ |
128
|
1 |
|
public function getOrderBook($primaryCurrencyCode, $secondaryCurrencyCode) |
129
|
|
|
{ |
130
|
1 |
|
return OrderBook::createFromObject($this->getEndpoint('GetOrderBook', [ |
131
|
1 |
|
'primaryCurrencyCode' => $primaryCurrencyCode, |
132
|
1 |
|
'secondaryCurrencyCode' => $secondaryCurrencyCode, |
133
|
1 |
|
])); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* Returns summarised historical trading data for a given currency pair. Data is summarised into |
138
|
|
|
* 1 hour intervals. |
139
|
|
|
* @note This method caches return values for 30 minutes. Calling it more than once per 30 |
140
|
|
|
* minutes will result in cached data being returned. |
141
|
|
|
* @param string $primaryCurrencyCode The digital currency for which to retrieve the trade |
142
|
|
|
* history summary. Must be a valid primary currency, which can be checked via the |
143
|
|
|
* getValidPrimaryCurrencyCodes() method. |
144
|
|
|
* @param string $secondaryCurrencyCode The fiat currency in which to retrieve the trade history |
145
|
|
|
* summary. Must be a valid secondary currency, which can be checked via the |
146
|
|
|
* getValidSecondaryCurrencyCodes() method. |
147
|
|
|
* @param int $numberOfHoursInThePastToRetrieve How many past hours of historical summary data |
148
|
|
|
* to retrieve (maximum is 240). |
149
|
|
|
* @return TradeHistorySummary |
150
|
|
|
*/ |
151
|
1 |
|
public function getTradeHistorySummary($primaryCurrencyCode, $secondaryCurrencyCode, |
152
|
|
|
$numberOfHoursInThePastToRetrieve) |
153
|
|
|
{ |
154
|
1 |
|
return TradeHistorySummary::createFromObject($this->getEndpoint('GetTradeHistorySummary', [ |
155
|
1 |
|
'primaryCurrencyCode' => $primaryCurrencyCode, |
156
|
1 |
|
'secondaryCurrencyCode' => $secondaryCurrencyCode, |
157
|
1 |
|
'numberOfHoursInThePastToRetrieve' => $numberOfHoursInThePastToRetrieve, |
158
|
1 |
|
])); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* Returns a list of most recently executed trades for a given currency pair. |
163
|
|
|
* @note This method caches return values for 1 second. Calling it more than once per second |
164
|
|
|
* will result in cached data being returned. |
165
|
|
|
* @param string $primaryCurrencyCode The digital currency for which to retrieve recent trades. |
166
|
|
|
* Must be a valid primary currency, which can be checked via the |
167
|
|
|
* getValidPrimaryCurrencyCodes() method. |
168
|
|
|
* @param string $secondaryCurrencyCode The fiat currency in which to retrieve recent trades. |
169
|
|
|
* Must be a valid secondary currency, which can be checked via the |
170
|
|
|
* getValidPrimaryCurrencyCodes() method. |
171
|
|
|
* @param integer $numberOfRecentTradesToRetrieve How many recent trades to retrieve (maximum |
172
|
|
|
* is 50). |
173
|
|
|
* @return RecentTrades |
174
|
|
|
*/ |
175
|
1 |
|
public function getRecentTrades($primaryCurrencyCode, $secondaryCurrencyCode, |
176
|
|
|
$numberOfRecentTradesToRetrieve) |
177
|
|
|
{ |
178
|
1 |
|
return RecentTrades::createFromObject($this->getEndpoint('GetRecentTrades', [ |
179
|
1 |
|
'primaryCurrencyCode' => $primaryCurrencyCode, |
180
|
1 |
|
'secondaryCurrencyCode' => $secondaryCurrencyCode, |
181
|
1 |
|
'numberOfRecentTradesToRetrieve' => $numberOfRecentTradesToRetrieve, |
182
|
1 |
|
])); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* Returns a list of exchange rates used by Independent Reserve when depositing funds or |
187
|
|
|
* withdrawing funds from accounts. |
188
|
|
|
* @note The rates represent the amount of Currency Code B that can be bought with 1 unit of |
189
|
|
|
* Currency Code A. |
190
|
|
|
* @note This method caches return values for 1 minute. Calling it more than once per minute |
191
|
|
|
* will result in cached data being returned. |
192
|
|
|
* @return FxRate[] |
193
|
|
|
*/ |
194
|
|
|
public function getFxRates() |
195
|
|
|
{ |
196
|
1 |
|
return array_map(function (stdClass $object) { |
197
|
1 |
|
return FxRate::createFromObject($object); |
198
|
1 |
|
}, $this->getEndpoint('GetFxRates')); |
199
|
|
|
} |
200
|
|
|
} |
201
|
|
|
|