Completed
Push — master ( e55ef7...9cf2a9 )
by Mikhail
01:33
created

Account::setDepositAddress()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace R3bers\BittrexApi\Api;
6
7
use Exception;
8
9
/**
10
 * Class Account
11
 * @package R3bers\BittrexApi\Api
12
 */
13
class Account extends Api
14
{
15
    /**
16
     * @return array
17
     * @throws Exception
18
     */
19 1
    public function getBalances(): array
20
    {
21 1
        return $this->get('/balances');
22
    }
23
24
    /**
25
     * @param string $currency
26
     * @return array
27
     * @throws Exception
28
     */
29 1
    public function getBalance(string $currency): array
30
    {
31 1
        return $this->get('/balances/' . $currency);
32
    }
33
34
    /**
35
     * @param string $currency
36
     * @return array
37
     * @throws Exception
38
     */
39 1
    public function getDepositAddress(string $currency): array
40
    {
41 1
        return $this->get('/addresses/' . $currency);
42
    }
43
44
    /**
45
     * @param string $currency
46
     * @return array
47
     * @throws Exception
48
     */
49 1
    public function setDepositAddress(string $currency): array
50
    {
51
        $NewAddress = [
52 1
            'currencySymbol' => $currency
53
        ];
54
55 1
        return $this->post('/addresses', json_encode($NewAddress));
56
    }
57
58
    /**
59
     * @param string $currency
60
     * @param float $quantity
61
     * @param string $address
62
     * @param string|null $paymentId
63
     * @return array
64
     * @throws Exception
65
     */
66 1
    public function withdraw(string $currency, float $quantity, string $address, ?string $paymentId = null): array
67
    {
68
        $newWithdrawal = [
69 1
            'currencySymbol' => $currency,
70 1
            'quantity' => $quantity,
71 1
            'cryptoAddress' => $address,
72
        ];
73
74 1
        if (!is_null($paymentId)) {
75 1
            $newWithdrawal['cryptoAddressTag'] = $paymentId;
76
        }
77
78 1
        return $this->post('/withdrawals', json_encode($newWithdrawal));
79
    }
80
81
    /**
82
     * @param string $uuid
83
     * @return array
84
     * @throws Exception
85
     */
86 1
    public function getOrder(string $uuid): array
87
    {
88 1
        return $this->get('/orders/' . $uuid);
89
    }
90
91
    /**
92
     * @param string|null $marketSymbol
93
     * @return array
94
     * @throws Exception
95
     */
96 1
    public function getOrderHistory(?string $marketSymbol = null): array
97
    {
98 1
        $parameters = [];
99
100 1
        if (!is_null($marketSymbol)) $parameters['marketSymbol'] = $marketSymbol;
101
102 1
        return $this->get('/orders/closed', $parameters);
103
    }
104
105
    /**
106
     * @param string|null $currencySymbol
107
     * @param string|null $status
108
     * @return array
109
     * @throws Exception
110
     */
111 1
    public function getWithdrawalHistory(?string $currencySymbol = null, ?string $status = null): array
112
    {
113 1
        return $this->getHistory('withdrawals', $currencySymbol, $status);
114
    }
115
116
    /**
117
     * @param string $whatHistory
118
     * @param string $currencySymbol
119
     * @param string $status
120
     * @return array
121
     * @throws Exception
122
     */
123 2
    private function getHistory(string $whatHistory, ?string $currencySymbol, ?string $status): array
124
    {
125 2
        $parameters = [];
126
127 2
        if (!is_null($currencySymbol)) $parameters['currencySymbol'] = $currencySymbol;
128 2
        if (!is_null($status)) $parameters['status'] = $status;
129
130 2
        return $this->get('/' . $whatHistory . '/closed', $parameters);
131
    }
132
133
    /**
134
     * @param string|null $currencySymbol
135
     * @param string|null $status
136
     * @return array
137
     * @throws Exception
138
     */
139 1
    public function getDepositHistory(?string $currencySymbol = null, ?string $status = null): array
140
    {
141 1
        return $this->getHistory('deposits', $currencySymbol, $status);
142
    }
143
}
144