Account   A
last analyzed

Complexity

Total Complexity 18

Size/Duplication

Total Lines 157
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 1 Features 0
Metric Value
wmc 18
eloc 30
dl 0
loc 157
ccs 40
cts 40
cp 1
c 4
b 1
f 0
rs 10

12 Methods

Rating   Name   Duplication   Size   Complexity  
A getVolume() 0 3 1
A getBalances() 0 3 1
A getOrder() 0 3 1
A setDepositAddress() 0 5 1
A getHistory() 0 8 3
A getOrderHistory() 0 9 4
A getBalance() 0 3 1
A getDepositHistory() 0 3 1
A headBalances() 0 4 1
A getDepositAddress() 0 3 1
A getWithdrawalHistory() 0 3 1
A withdraw() 0 14 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace R3bers\BittrexApi\Api;
6
7
use Exception;
8
use GuzzleHttp\Exception\GuzzleException;
9
use R3bers\BittrexApi\Exception\TransformResponseException;
10
11
/**
12
 * Class Account
13
 * @package R3bers\BittrexApi\Api
14
 */
15
class Account extends Api
16
{
17
    /** https://bittrex.github.io/api/v3#operation--account-volume-get
18
     * @return array
19
     * @throws GuzzleException
20
     * @throws TransformResponseException
21
     */
22 1
    public function getVolume(): array
23
    {
24 1
        return $this->rest('GET', '/account/volume');
25
    }
26
27
    /** https://bittrex.github.io/api/v3#operation--balances-get
28
     * @param bool|null $needSequence
29
     * @return array
30
     * @throws GuzzleException
31
     * @throws TransformResponseException
32
     */
33 1
    public function getBalances(?bool $needSequence = null): array
34
    {
35 1
        return $this->rest('GET', '/balances', [], $needSequence);
36
    }
37
38
    /** https://bittrex.github.io/api/v3#operation--balances-head
39
     * @return int
40
     * @throws GuzzleException
41
     * @throws TransformResponseException
42
     */
43 1
    public function headBalances(): int
44
    {
45 1
        $responseArray = $this->rest('HEAD', '/balances');
46 1
        return $responseArray['Sequence'];
47
    }
48
49
    /** https://bittrex.github.io/api/v3#operation--balances--currencySymbol--get
50
     * @param string $currency
51
     * @param bool|null $needSequence
52
     * @return array
53
     * @throws GuzzleException
54
     * @throws TransformResponseException
55
     */
56 1
    public function getBalance(string $currency, ?bool $needSequence = null): array
57
    {
58 1
        return $this->rest('GET', '/balances/' . $currency, [], $needSequence);
59
    }
60
61
    /** https://bittrex.github.io/api/v3#operation--addresses-get
62
     * @param string $currency
63
     * @return array
64
     * @throws Exception|GuzzleException
65
     */
66 1
    public function getDepositAddress(string $currency): array
67
    {
68 1
        return $this->rest('GET', '/addresses/' . $currency);
69
    }
70
71
    /** https://bittrex.github.io/api/v3#operation--addresses-post
72
     * @param string $currency
73
     * @return array
74
     * @throws Exception|GuzzleException
75
     */
76 1
    public function setDepositAddress(string $currency): array
77
    {
78 1
        $options = ['body' => json_encode(['currencySymbol' => $currency])];
79
80 1
        return $this->rest('POST', '/addresses', $options);
81
    }
82
83
    /** https://bittrex.github.io/api/v3#operation--withdrawals-post
84
     * @param string $currency
85
     * @param float $quantity
86
     * @param string $address
87
     * @param string|null $paymentId
88
     * @return array
89
     * @throws Exception|GuzzleException
90
     */
91 1
    public function withdraw(string $currency, float $quantity, string $address, ?string $paymentId = null): array
92
    {
93
        $newWithdrawal = [
94 1
            'currencySymbol' => $currency,
95 1
            'quantity' => $quantity,
96 1
            'cryptoAddress' => $address,
97
        ];
98
99 1
        if (!is_null($paymentId)) {
100 1
            $newWithdrawal['cryptoAddressTag'] = $paymentId;
101
        }
102
103 1
        $options = ['body' => json_encode($newWithdrawal)];
104 1
        return $this->rest('POST', '/withdrawals', $options);
105
    }
106
107
    /** https://bittrex.github.io/api/v3#operation--orders--orderId--get
108
     * @param string $uuid
109
     * @return array
110
     * @throws Exception|GuzzleException
111
     */
112 1
    public function getOrder(string $uuid): array
113
    {
114 1
        return $this->rest('GET', '/orders/' . $uuid);
115
    }
116
117
    /** https://bittrex.github.io/api/v3#operation--orders-closed-get
118
     * @param string|null $marketSymbol
119
     * @param array|null $pagination
120
     * @return array
121
     * @throws GuzzleException
122
     * @throws TransformResponseException
123
     */
124 1
    public function getOrderHistory(?string $marketSymbol = null, ?array $pagination = null): array
125
    {
126 1
        $options = [];
127 1
        if (!is_null($marketSymbol)) $options['query'] = ['marketSymbol' => $marketSymbol];
128 1
        if (is_array($pagination))
129 1
            foreach ($pagination as $key => $value)
130 1
                $options['query'][$key] = $value;
131
132 1
        return $this->rest('GET', '/orders/closed', $options);
133
    }
134
135
    /** https://bittrex.github.io/api/v3#operation--withdrawals-closed-get
136
     * @param string|null $currencySymbol
137
     * @param string|null $status
138
     * @return array
139
     * @throws Exception|GuzzleException
140
     */
141 1
    public function getWithdrawalHistory(?string $currencySymbol = null, ?string $status = null): array
142
    {
143 1
        return $this->getHistory('withdrawals', $currencySymbol, $status);
144
    }
145
146
    /**
147
     * @param string $whatHistory
148
     * @param string|null $currencySymbol
149
     * @param string|null $status
150
     * @return array
151
     * @throws GuzzleException | TransformResponseException
152
     */
153 2
    private function getHistory(string $whatHistory, ?string $currencySymbol, ?string $status): array
154
    {
155 2
        $options = [];
156
157 2
        if (!is_null($currencySymbol)) $options['query'] = ['currencySymbol' => $currencySymbol];
158 2
        if (!is_null($status)) $options['query'] = ['status' => $status];
159
160 2
        return $this->rest('GET', '/' . $whatHistory . '/closed', $options);
161
    }
162
163
    /** https://bittrex.github.io/api/v3#operation--deposits-closed-get
164
     * @param string|null $currencySymbol
165
     * @param string|null $status
166
     * @return array
167
     * @throws Exception|GuzzleException
168
     */
169 1
    public function getDepositHistory(?string $currencySymbol = null, ?string $status = null): array
170
    {
171 1
        return $this->getHistory('deposits', $currencySymbol, $status);
172
    }
173
}