1 | <?php |
||
16 | class PrivateClient extends PublicClient |
||
17 | { |
||
18 | /** |
||
19 | * @var string |
||
20 | */ |
||
21 | protected $apiKey; |
||
22 | |||
23 | /** |
||
24 | * @var string |
||
25 | */ |
||
26 | protected $apiSecret; |
||
27 | |||
28 | /** |
||
29 | * @param string $apiKey |
||
30 | * @param string $apiSecret |
||
31 | */ |
||
32 | 5 | public function __construct($apiKey, $apiSecret) |
|
38 | |||
39 | /** |
||
40 | * Get the components required to make private API calls. |
||
41 | * @return array |
||
42 | */ |
||
43 | 4 | public function getSignature($url, $params) |
|
44 | { |
||
45 | 4 | $nonce = str_pad(str_replace('.', '', microtime(true)), 19, 0); |
|
46 | |||
47 | 4 | $params = array_merge(['apiKey' => $this->apiKey, 'nonce' => $nonce], $params); |
|
48 | 4 | $strToSign = $this->mapToKeyValue($url,$params); |
|
49 | 4 | $signature = strtoupper(hash_hmac('sha256', utf8_encode($strToSign), utf8_encode($this->apiSecret))); |
|
50 | |||
51 | return [ |
||
52 | 4 | 'apiKey' => $this->apiKey, |
|
53 | 4 | 'nonce' => $nonce, |
|
54 | 4 | 'signature' => $signature, |
|
55 | 4 | ]; |
|
56 | } |
||
57 | |||
58 | 4 | private function mapToKeyValue($url, $data) { |
|
59 | 4 | $res = $url; |
|
60 | 4 | foreach ($data as $key => $value) { |
|
61 | 4 | if (is_array($value)) { |
|
62 | $res .= ",$key=".array_values($value)[0]; // works only for case when array has one value. And no docs how to use for array with more then one value |
||
63 | } else { |
||
64 | 4 | $res .= ",$key=$value"; |
|
65 | } |
||
66 | 4 | } |
|
67 | 4 | return $res; |
|
68 | } |
||
69 | /** |
||
70 | * Fetch a private API. |
||
71 | * @param string $endpoint |
||
72 | * @param array $params |
||
73 | * @return mixed |
||
74 | */ |
||
75 | 4 | public function getPrivateEndpoint($endpoint, array $params = array()) |
|
76 | { |
||
77 | 4 | return $this->getEndpoint($endpoint, $this->getSignature($this->getEndpointUrl($endpoint,'Private'), $params) + $params, 'Private', 'POST'); |
|
78 | } |
||
79 | |||
80 | /** |
||
81 | * Retrieves your currently Open and Partially Filled orders. |
||
82 | * @param string $primaryCurrencyCode The primary currency of orders. |
||
83 | * @param string $secondaryCurrencyCode The secondary currency of orders. |
||
84 | * @return OpenOrder[] |
||
85 | */ |
||
86 | 1 | public function getOpenOrders($primaryCurrencyCode, $secondaryCurrencyCode) |
|
87 | { |
||
88 | 1 | return new PagedIterator($this, 'GetOpenOrders', [ |
|
89 | 1 | 'primaryCurrencyCode' => $primaryCurrencyCode, |
|
90 | 1 | 'secondaryCurrencyCode' => $secondaryCurrencyCode, |
|
91 | 1 | 'pageSize' => 25, |
|
92 | ], function (stdClass $object) { |
||
93 | return OpenOrder::createFromObject($object); |
||
94 | 1 | }); |
|
95 | } |
||
96 | |||
97 | /** |
||
98 | * Places new limit bid / offer order. A Limit Bid is a buy order and a Limit Offer is a sell |
||
99 | * order. |
||
100 | * @param string $primaryCurrencyCode The digital currency code of limit order. Must be a valid |
||
101 | * primary currency, which can be checked via the getValidPrimaryCurrencyCodes() method. |
||
102 | * @param string $secondaryCurrencyCode The fiat currency of limit order. Must be a valid |
||
103 | * secondary currency, which can be checked via the getValidSecondaryCurrencyCodes() |
||
104 | * method. |
||
105 | * @param string $orderType The type of limit order. Must be a valid limit order type, which can |
||
106 | * be checked via the getValidLimitOrderTypes() method. |
||
107 | * @param double $price The price in secondary currency to buy/sell. |
||
108 | * @param double $volume The volume to buy/sell in primary currency. |
||
109 | * @return Order |
||
110 | */ |
||
111 | public function placeLimitOrder($primaryCurrencyCode, $secondaryCurrencyCode, $orderType, |
||
112 | $price, $volume) |
||
113 | { |
||
114 | return Order::createFromObject(json_decode($this->getPrivateEndpoint('PlaceLimitOrder', [ |
||
115 | 'primaryCurrencyCode' => $primaryCurrencyCode, |
||
116 | 'secondaryCurrencyCode' => $secondaryCurrencyCode, |
||
117 | 'price' => $price, |
||
118 | 'volume' => $volume, |
||
119 | 'orderType' => $orderType, |
||
120 | ]))); |
||
121 | } |
||
122 | |||
123 | /** |
||
124 | * Place new market bid / offer order. A Market Bid is a buy order and a Market Offer is a sell |
||
125 | * order. |
||
126 | * @param string $primaryCurrencyCode The digital currency code of market order. Must be a valid |
||
127 | * primary currency, which can be checked via the getValidPrimaryCurrencyCodes() method. |
||
128 | * @param string $secondaryCurrencyCode The fiat currency of market order. Must be a valid |
||
129 | * secondary currency, which can be checked via the getValidSecondaryCurrencyCodes() |
||
130 | * method. |
||
131 | * @param string $orderType The type of market order. Must be a valid market order type, which |
||
132 | * can be checked via the getValidMarketOrderTypes() method. |
||
133 | * @param double $volume The volume to buy/sell in primary currency. |
||
134 | * @return Order |
||
135 | */ |
||
136 | public function placeMarketOrder($primaryCurrencyCode, $secondaryCurrencyCode, $orderType, |
||
137 | $volume) |
||
138 | { |
||
139 | return Order::createFromObject(json_decode($this->getPrivateEndpoint('PlaceMarketOrder', [ |
||
140 | 'primaryCurrencyCode' => $primaryCurrencyCode, |
||
141 | 'secondaryCurrencyCode' => $secondaryCurrencyCode, |
||
142 | 'volume' => $volume, |
||
143 | 'orderType' => $orderType, |
||
144 | ]))); |
||
145 | } |
||
146 | |||
147 | /** |
||
148 | * Cancels a previously placed order. |
||
149 | * @note The order must be in either 'Open' or 'PartiallyFilled' status to be valid for |
||
150 | * cancellation. You can retrieve list of Open and Partially Filled orders via the |
||
151 | * getOpenOrders() method. You can also check an individual order's status by calling the |
||
152 | * getOrderDetails() method. |
||
153 | * @param string $guid The guid of currently open or partially filled order. |
||
154 | * @return Order |
||
155 | */ |
||
156 | public function cancelOrder($guid) |
||
162 | |||
163 | /** |
||
164 | * Retrieves your Closed and Cancelled orders. |
||
165 | * @param string $primaryCurrencyCode The primary currency of orders. |
||
166 | * @param string $secondaryCurrencyCode The secondary currency of orders. |
||
167 | * @return ClosedOrder[] |
||
168 | */ |
||
169 | public function getClosedOrders($primaryCurrencyCode, $secondaryCurrencyCode) |
||
179 | |||
180 | /** |
||
181 | * Retrieves your Closed orders which have had some or all of their outstanding volume filled. |
||
182 | * @param string $primaryCurrencyCode The primary currency of orders. |
||
183 | * @param string $secondaryCurrencyCode The secondary currency of orders. |
||
184 | * @return ClosedOrder[] |
||
185 | */ |
||
186 | public function getClosedFilledOrders($primaryCurrencyCode, $secondaryCurrencyCode) |
||
196 | |||
197 | /** |
||
198 | * Retrieves a single order. |
||
199 | * @param string $guid |
||
200 | * @return Order |
||
201 | */ |
||
202 | 1 | public function getOrder($guid) |
|
208 | |||
209 | /** |
||
210 | * Retrieves information about your Independent Reserve accounts in digital and fiat currencies. |
||
211 | * @return Account[] |
||
212 | */ |
||
213 | 1 | public function getAccounts() |
|
219 | |||
220 | /** |
||
221 | * @param $accountGuid Account GUID. |
||
222 | * @param DateTime $from Optional start time. |
||
223 | * @param DateTime $to Optional end time. |
||
224 | * @return Transaction[] |
||
225 | */ |
||
226 | 1 | public function getTransactions($accountGuid, DateTime $from = null, DateTime $to = null) |
|
238 | |||
239 | /** |
||
240 | * Retrieves the Bitcoin address which should be used for new Bitcoin deposits. |
||
241 | * @return BitcoinDepositAddress |
||
242 | */ |
||
243 | 1 | public function getBitcoinDepositAddress() |
|
248 | |||
249 | /** |
||
250 | * Creates a withdrawal request for a Fiat currency withdrawal from your Independent Reserve |
||
251 | * account to an external bank account. |
||
252 | * |
||
253 | * Withdrawals to Australian bank accounts will be converted into AUD by Independent Reserve at |
||
254 | * a competitive exchange rate. International withdrawals will be transmitted in USD, and |
||
255 | * converted into the appropriate currency by the receiving bank. Minimum withdrawal amount is |
||
256 | * USD 50.00, except where the available balance is less than this amount. In all cases, the |
||
257 | * withdrawal amount must be greater than the withdrawal fee (only applies to international |
||
258 | * withdrawals). Withdrawals are manually approved. Please allow 2-3 business days for the funds |
||
259 | * to arrive in your bank account. Withdrawals to Australian accounts are usually faster. |
||
260 | * Independent Reserve can only process withdrawals to bank accounts that match the name of the |
||
261 | * Independent Reserve account holder. |
||
262 | * |
||
263 | * @param string $secondaryCurrencyCode The Independent Reserve fiat currency account to |
||
264 | * withdraw from (currently only USD accounts are supported). |
||
265 | * @param double $withdrawalAmount Amount of fiat currency to withdraw. |
||
266 | * @param string $withdrawalBankAccountName A pre-configured bank account you've already linked |
||
267 | * to your Independent Reserve account. |
||
268 | * @return FiatWithdrawal |
||
269 | */ |
||
270 | public function requestFiatWithdrawal($secondaryCurrencyCode, $withdrawalAmount, |
||
280 | } |
||
281 |