PrivateApi::getMyTrades()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 1
rs 10
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