1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Codenixsv\KunaApi\Api; |
6
|
|
|
|
7
|
|
|
use Codenixsv\ApiClient\BaseClient; |
8
|
|
|
use Codenixsv\ApiClient\BaseClientInterface; |
9
|
|
|
use Codenixsv\KunaApi\Configurator\PrivateRequestConfigurator; |
10
|
|
|
use Codenixsv\KunaApi\KunaClient; |
11
|
|
|
use Codenixsv\KunaApi\Exception\TransformResponseException; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class PrivateApi |
15
|
|
|
* @package Codenixsv\KunaApi\Api |
16
|
|
|
*/ |
17
|
|
|
class PrivateApi extends Api |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* PrivateApi constructor. |
21
|
|
|
* @param KunaClient $client |
22
|
|
|
* @param BaseClientInterface|null $baseClient |
23
|
|
|
*/ |
24
|
6 |
|
public function __construct(KunaClient $client, ?BaseClientInterface $baseClient = null) |
25
|
|
|
{ |
26
|
6 |
|
$baseClient = $baseClient ?: new BaseClient(); |
27
|
6 |
|
$configurator = new PrivateRequestConfigurator($client->getPublicKey(), $client->getSecretKey()); |
28
|
6 |
|
$baseClient->addRequestConfigurator($configurator); |
29
|
6 |
|
parent::__construct($client, $baseClient); |
30
|
6 |
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @return array |
34
|
|
|
* @throws TransformResponseException |
35
|
|
|
*/ |
36
|
1 |
|
public function getMe() |
37
|
|
|
{ |
38
|
1 |
|
$response = $this->getBaseClient()->get('/members/me'); |
39
|
|
|
|
40
|
1 |
|
return $this->getTransformer()->transform($response); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param string $side |
45
|
|
|
* @param float $volume |
46
|
|
|
* @param string $market |
47
|
|
|
* @param float $price |
48
|
|
|
* @return array |
49
|
|
|
* @throws TransformResponseException |
50
|
|
|
*/ |
51
|
1 |
|
public function createOrder(string $side, float $volume, string $market, float $price) |
52
|
|
|
{ |
53
|
1 |
|
$body = http_build_query([ |
54
|
1 |
|
'side' => $side, |
55
|
1 |
|
'volume' => $volume, |
56
|
1 |
|
'market' => $market, |
57
|
1 |
|
'price' => $price |
58
|
|
|
]); |
59
|
|
|
|
60
|
1 |
|
$response = $this->getBaseClient()->post('/orders', $body); |
61
|
|
|
|
62
|
1 |
|
return $this->getTransformer()->transform($response); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param int $id |
68
|
|
|
* @return array |
69
|
|
|
* @throws TransformResponseException |
70
|
|
|
*/ |
71
|
1 |
|
public function deleteOrder(int $id) |
72
|
|
|
{ |
73
|
1 |
|
$body = http_build_query(['id' => $id]); |
74
|
1 |
|
$response = $this->getBaseClient()->post('/order/delete', $body); |
75
|
|
|
|
76
|
1 |
|
return $this->getTransformer()->transform($response); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @param string $market |
81
|
|
|
* @return array |
82
|
|
|
* @throws TransformResponseException |
83
|
|
|
*/ |
84
|
1 |
|
public function getOrders(string $market) |
85
|
|
|
{ |
86
|
1 |
|
$query = http_build_query(['market' => strtolower($market)]); |
87
|
1 |
|
$response = $this->getBaseClient()->get('/orders?' . $query); |
88
|
|
|
|
89
|
1 |
|
return $this->getTransformer()->transform($response); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @param string $market |
94
|
|
|
* @return array |
95
|
|
|
* @throws TransformResponseException |
96
|
|
|
*/ |
97
|
1 |
|
public function getMyTrades(string $market) |
98
|
|
|
{ |
99
|
1 |
|
$query = http_build_query(['market' => strtolower($market)]); |
100
|
1 |
|
$response = $this->getBaseClient()->get('/trades/my?' . $query); |
101
|
|
|
|
102
|
1 |
|
return $this->getTransformer()->transform($response); |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|