Completed
Push — master ( e0e78e...af88bd )
by Mikhail
01:50 queued 15s
created

Account::getHistory()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 9.9666
c 0
b 0
f 0
cc 3
nc 4
nop 3
crap 3
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
     * @param float $quantity
47
     * @param string $address
48
     * @param string|null $paymentId
49
     * @return array
50
     * @throws Exception
51
     */
52 1
    public function withdraw(string $currency, float $quantity, string $address, ?string $paymentId = null): array
53
    {
54
        $newWithdrawal = [
55 1
            'currencySymbol' => $currency,
56 1
            'quantity' => $quantity,
57 1
            'cryptoAddress' => $address,
58
        ];
59
60 1
        if (!is_null($paymentId)) {
61 1
            $newWithdrawal['cryptoAddressTag'] = $paymentId;
62
        }
63
64 1
        return $this->post('/withdrawals', json_encode($newWithdrawal));
65
    }
66
67
    /**
68
     * @param string $uuid
69
     * @return array
70
     * @throws Exception
71
     */
72 1
    public function getOrder(string $uuid): array
73
    {
74 1
        return $this->get('/orders/' . $uuid);
75
    }
76
77
    /**
78
     * @param string|null $marketSymbol
79
     * @return array
80
     * @throws Exception
81
     */
82 1
    public function getOrderHistory(?string $marketSymbol = null): array
83
    {
84 1
        $parameters = [];
85
86 1
        if (!is_null($marketSymbol)) $parameters['marketSymbol'] = $marketSymbol;
87
88 1
        return $this->get('/orders/closed', $parameters);
89
    }
90
91
92
    /**
93
     * @param string $whatHistory
94
     * @param string $currencySymbol
95
     * @param string $status
96
     * @return array
97
     * @throws Exception
98
     */
99 2
    private function getHistory(string $whatHistory, ?string  $currencySymbol, ?string $status): array
100
    {
101 2
        $parameters = [];
102
103 2
        if (!is_null($currencySymbol)) $parameters['currencySymbol'] = $currencySymbol;
104 2
        if (!is_null($status)) $parameters['status'] = $status;
105
106 2
        return $this->get('/'.$whatHistory.'/closed', $parameters);
107
     }
108
    /**
109
     * @param string|null $currencySymbol
110
     * @param string|null $status
111
     * @return array
112
     * @throws Exception
113
     */
114 1
    public function getWithdrawalHistory(?string $currencySymbol = null, ?string $status = null): array
115
    {
116 1
        return $this->getHistory('withdrawals', $currencySymbol, $status);
117
    }
118
119
    /**
120
     * @param string|null $currencySymbol
121
     * @param string|null $status
122
     * @return array
123
     * @throws Exception
124
     */
125 1
    public function getDepositHistory(?string $currencySymbol = null, ?string $status = null): array
126
    {
127 1
        return $this->getHistory('deposits', $currencySymbol, $status);
128
    }
129
}
130