-
Notifications
You must be signed in to change notification settings - Fork 1
/
Client.php
executable file
·513 lines (445 loc) · 13.1 KB
/
Client.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
<?php
namespace Santran\Livecoin;
class Client implements ClientContract
{
/**
* @var string
*/
private $apiUrl;
/**
* @var string
*/
private $apiKey;
/**
* @var string
*/
private $apiSecret;
public function __construct(array $auth, $api_url)
{
$this->apiUrl = $api_url;
$this->apiKey = array_get($auth, 'key');
$this->apiSecret = array_get($auth, 'secret');
}
/**
* PUBLIC DATA
*
* Documentation https://www.livecoin.net/api/public
*/
/**
* To retrieve information on a particular currency pair for the last 24 hours.
*
* @param array $params
* @return array
*/
public function exchangeTicker($params = [])
{
return $this->getRequest('exchange/ticker', $params, false);
}
/**
* To retrieve information on the latest transactions for a specified currency pair.
* You may receive data within the last hour or the last minute.
*
* @param array $params
* @return array
*/
public function exchangeLastTrades($params)
{
return $this->getRequest('exchange/last_trades', $params, false);
}
/**
* Used to get the orderbook for a given market (the grouping attribute can be set by price)
*
* @param array $params
* @return array
*/
public function exchangeOrderBook($params)
{
return $this->getRequest('exchange/order_book', $params, false);
}
/**
* Returns orderbook for every currency pair
*
* @param array $params
* @return array
*/
public function exchangeAllOrderBook($params)
{
return $this->getRequest('exchange/all/order_book', $params, false);
}
/**
* Returns maximum bid and minimum ask in current orderbook
*
* @param array $params
* @return array
*/
public function exchangeMaxbidMinask($params)
{
return $this->getRequest('exchange/maxbid_minask', $params, false);
}
/**
* Returns limits for minimum amount to open order, for each pair.
* Also returns maximum number of digits after the decimal point for price.
*
* @param array $params
* @return array
*/
public function exchangeRestrictions($params)
{
return $this->getRequest('exchange/restrictions', $params, false);
}
/**
* Returns public data for currencies
*
* @return array
*/
public function infoCoinInfo()
{
return $this->getRequest('info/coinInfo', [], false);
}
/**
* PRIVATE USER DATA
*
* Documentation https://www.livecoin.net/api/userdata
*/
/**
* To retrieve information on your latest transactions. The result may be determined by the parameters below.
*
* @param array $params
* @return array
*/
public function exchangeTrades($params = [])
{
return $this->getRequest('exchange/trades');
}
/**
* To retrieve full information on your trade-orders for the specified currency pair.
* You can optionally limit the response to orders of a certain type (open, closed, expired, etc.)
*
* @param array $params
* @return array
*/
public function exchangeClientOrders($params = [])
{
return $this->getRequest('exchange/client_orders', $params);
}
/**
* To retrieve an order's information by its ID
*
* @param array $params
* @return array
*/
public function exchangeOrder($params)
{
return $this->getRequest('exchange/order', $params);
}
/**
* Returns an array with your balances.
* There are four types of balances for every currency: total, available (for trading), trade (in open orders),
* available_withdrawal (available for withdrawal)
*
* @param array $params
* @return array
*/
public function paymentBalances($params = [])
{
return $this->getRequest('payment/balances', $params);
}
/**
* Returns available balance for selected currency
*
* @param array $params
* @return array
*/
public function paymentBalance($params)
{
return $this->getRequest('payment/balance', $params);
}
/**
* Returns a list of your transactions
*
* @param array $params
* @return array
*/
public function paymentHistoryTransactions($params)
{
return $this->getRequest('payment/history/transaction', $params);
}
/**
* Returns your transaction count for the specified period
*
* @param array $params
* @return integer
*/
public function paymentHistorySize($params)
{
return $this->getRequest('payment/history/size', $params);
}
/**
* Returns actual trading fee for client
*
* @return array
*/
public function exchangeCommissions()
{
return $this->getRequest('exchange/commission', []);
}
/**
* Returns actual trading fee and volume for the last 30 days in USD
*
* @return array
*/
public function exchangeCommissionCommonInfo()
{
return $this->getRequest('exchange/commissionCommonInfo', []);
}
/**
* OPEN / CANCEL ORDERS
*
* Documentation https://www.livecoin.net/api/orders
*/
/**
* To set a buy order (limit) for a particular currency.
*
* @param array $params
* @return array
*/
public function exchangeBuylimit($params)
{
return $this->postRequest('exchange/buylimit', $params);
}
/**
* To set a sell order (limit) for a specific currency pair.
* Additional parameters are similar to those for buy orders.
*
* @param array $params
* @return array
*/
public function exchangeSelllimit($params)
{
return $this->postRequest('exchange/selllimit', $params);
}
/**
* Open a buy order (market) of the specified amount for a specific currency pair.
*
* @param array $params
* @return array
*/
public function exchangeBuymarket($params)
{
return $this->postRequest('exchange/buymarket', $params);
}
/**
* To set a sell order (market) of the specified amount for a specific currency pair.
*
* @param array $params
* @return array
*/
public function exchangeSellmarket($params)
{
return $this->postRequest('exchange/sellmarket', $params);
}
/**
* Cancel limit order.
*
* @param array $params
* @return array
*/
public function exchangeCancellimit($params)
{
return $this->postRequest('exchange/cancellimit', $params);
}
/**
* DEPOSIT AND WITHDRAWAL
*
* Documentation https://www.livecoin.net/api/withdrawal
*/
/**
* Get deposit address for selected cryptocurrency.
* Wallet field contains delimiter "::" in case if you need more data to deposit coins besides the wallet itself
* (For example for coins: XMR, BTS, THS, STEEM).
* In this case wallet is located before delimiter, when Memo/Payment ID after.
*
* @param array $params
* @return array
*/
public function paymentGetAddress($params)
{
return $this->getRequest('payment/get/address', $params);
}
/**
* Submit a request to withdraw to a cryptocurrency wallet.
* After successful withdrawal request, field "fault" will contain a "NULL" value,
* while field "state" will contain "APPROVED" or "IN PROCESS".
*
* @param array $params
* @return array
*/
public function paymentOutCoin($params)
{
return $this->postRequest('payment/out/coin', $params);
}
/**
* Submit a request to withdraw to a Payeer account.
* After successful withdrawal request, field "fault" will contain a "NULL" value,
* while field "state" will contain "APPROVED" or "IN PROCESS".
*
* @param array $params
* @return array
*/
public function paymentOutPayeer($params)
{
return $this->postRequest('payment/out/payeer', $params);
}
/**
* Submit a request to withdraw to a Capitalist account.
* After successful withdrawal request, field "fault" will contain a "NULL" value,
* while field "state" will contain "APPROVED" or "IN PROCESS".
*
* @param array $params
* @return array
*/
public function paymentOutCapitalist($params)
{
return $this->postRequest('payment/out/capitalist', $params);
}
/**
* Submit a request to withdraw to an Advcash account.
* After successful withdrawal request, field "fault" will contain a "NULL" value,
* while field "state" will contain "APPROVED" or "IN PROCESS".
*
* @param array $params
* @return array
*/
public function paymentOutAdvcah($params)
{
return $this->postRequest('payment/out/advcah', $params);
}
/**
* Submit a request to withdraw to a bank card.
* After successful withdrawal request, field "fault" will contain a "NULL" value,
* while field "state" will contain "APPROVED" or "IN PROCESS".
*
* @param array $params
* @return array
*/
public function paymentOutCard($params)
{
return $this->postRequest('payment/out/card', $params);
}
/**
* Submit a request to withdraw to Okpay account.
* After successful withdrawal request, field "fault" will contain a "NULL" value,
* while field "state" will contain "APPROVED" or "IN PROCESS".
*
* @param array $params
* @return array
*/
public function paymentOutOkpay($params)
{
return $this->postRequest('payment/out/okpay', $params);
}
/**
* Submit a request to withdraw to a PerfectMoney account.
* After successful withdrawal request, field "fault" will contain a "NULL" value,
* while field "state" will contain "APPROVED" or "IN PROCESS".
*
* @param $params
* @return array
*/
public function paymentOutPerfectmoney($params)
{
return $this->postRequest('payment/out/perfectmoney', $params);
}
/**
* VOUCHERS
*
* Documentation https://www.livecoin.net/api/vouchers
*/
/**
* Creates a new voucher. In case of success returns a voucher code as a string.
*
* @param array $params
* @return string
*/
public function paymentVoucherMake($params)
{
return $this->postRequest('payment/voucher/make', $params, true, false);
}
/**
* Returns a voucher amount from a code
*
* @param array $params
* @return float
*/
public function paymentVoucherAmount($params)
{
return $this->postRequest('/payment/voucher/amount', $params, true, false);
}
/**
* Redeem a voucher
*
* @param array $params
* @return array
*/
public function paymentVoucherRedeem($params)
{
return $this->postRequest('/payment/voucher/redeem', $params);
}
private function getRequest($api_method, $params, $private = true, $json_decode = true)
{
ksort($params);
$fields = http_build_query($params, '', '&');
$headers = [];
if ($private === true) {
$signature = strtoupper(hash_hmac('sha256', $fields, $this->apiSecret));
$headers = [
"Api-Key: $this->apiKey",
"Sign: $signature"
];
}
$ch = curl_init($this->apiUrl . $api_method . "?" . $fields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($statusCode != 200) {
throw new \Exception("Status code: $statusCode, response: $response");
}
if($json_decode === true){
$res = json_decode($response, true);
} else {
$res = $response;
}
return $res;
}
private function postRequest($api_method, $params, $private = true, $json_decode = true)
{
ksort($params);
$fields = http_build_query($params, '', '&');
$signature = strtoupper(hash_hmac('sha256', $fields, $this->secretKey));
$headers = [];
if ($private === true) {
$signature = strtoupper(hash_hmac('sha256', $fields, $this->apiSecret));
$headers = [
"Api-Key: $this->apiKey",
"Sign: $signature"
];
}
$ch = curl_init($this->apiUrl . $api_method);
curl_setopt($ch, CURLOPT_POST, 'POST');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($statusCode != 200) {
throw new \Exception("Status code: $statusCode, response: $response");
}
if($json_decode === true){
$res = json_decode($response, true);
} else {
$res = $response;
}
return $res;
}
}