WalletBalanceTest::testSuccessEndpoint()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 81
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 22
nc 2
nop 0
dl 0
loc 81
rs 9.568
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Carpenstar\ByBitAPI\Derivatives\Contract\Account\WalletBalance\Tests;
4
5
use Carpenstar\ByBitAPI\BybitAPI;
6
use Carpenstar\ByBitAPI\Derivatives\Contract\Account\WalletBalance\Interfaces\IWalletBalanceResponseItemInterface;
7
use Carpenstar\ByBitAPI\Derivatives\Contract\Account\WalletBalance\Request\WalletBalanceRequest;
8
use Carpenstar\ByBitAPI\Derivatives\Contract\Account\WalletBalance\WalletBalance;
9
use PHPUnit\Framework\TestCase;
10
11
class WalletBalanceTest extends TestCase
12
{
13
    public function testSuccessEndpoint()
14
    {
15
        $bybit = (new BybitAPI())->setCredentials('https://api-testnet.bybit.com', 'fL02oi5qo8i2jDxlum', 'Ne1EE35XTprIWrId9vGEAc1ZYJTmodA4qFzZ');
16
17
        $response = $bybit->privateEndpoint(WalletBalance::class, (new WalletBalanceRequest()))->execute();
18
19
        echo "Return code: {$response->getReturnCode()} \n";
20
        echo "Return message: {$response->getReturnMessage()} \n";
21
22
        $walletBalances = array_slice($response->getResult()->getBalances(), 0, 3);
0 ignored issues
show
Bug introduced by
The method getBalances() does not exist on Carpenstar\ByBitAPI\Core\Objects\AbstractResponse. It seems like you code against a sub-type of Carpenstar\ByBitAPI\Core\Objects\AbstractResponse such as Carpenstar\ByBitAPI\Deri...e\WalletBalanceResponse. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

22
        $walletBalances = array_slice($response->getResult()->/** @scrutinizer ignore-call */ getBalances(), 0, 3);
Loading history...
23
24
        /** @var IWalletBalanceResponseItemInterface $balance */
25
        foreach ($walletBalances as $balance) {
26
            echo "----- \n";
27
            echo "Coin: {$balance->getCoin()} \n";
28
            echo "Equity: {$balance->getEquity()} \n";
29
            echo "Wallet Balance: {$balance->getWalletBalance()} \n";
30
            echo "Position Margin: {$balance->getPositionMargin()} \n";
31
            echo "Available Balance: {$balance->getAvailableBalance()} \n";
32
            echo "Order Margin: {$balance->getOrderMargin()} \n";
33
            echo "Occ Closing Fee: {$balance->getOccClosingFee()} \n";
34
            echo "Occ Funding Fee: {$balance->getOccFundingFee()} \n";
35
            echo "Unrealised PnL: {$balance->getUnrealisedPnl()} \n";
36
            echo "Cumulative Realised PnL: {$balance->getCumRealisedPnl()} \n";
37
            echo "Given Cash: {$balance->getGivenCash()} \n";
38
            echo "Service Cash: {$balance->getServiceCash()} \n";
39
            echo "Account IM: {$balance->getAccountIM()} \n";
40
            echo "Account MM: {$balance->getAccountMM()} \n";
41
        }
42
43
        /**
44
         * Return code: 0
45
         * Return message: OK
46
         * -----
47
         * Coin: BTC
48
         * Equity: 0.2
49
         * Wallet Balance: 0.2
50
         * Position Margin: 0
51
         * Available Balance: 0.2
52
         * Order Margin: 0
53
         * Occ Closing Fee: 0
54
         * Occ Funding Fee: 0
55
         * Unrealised PnL: 0
56
         * Cumulative Realised PnL: 0
57
         * Given Cash: 0
58
         * Service Cash: 0
59
         * Account IM:
60
         * Account MM:
61
         * -----
62
         * Coin: ETH
63
         * Equity: 0
64
         * Wallet Balance: 0
65
         * Position Margin: 0
66
         * Available Balance: 0
67
         * Order Margin: 0
68
         * Occ Closing Fee: 0
69
         * Occ Funding Fee: 0
70
         * Unrealised PnL: 0
71
         * Cumulative Realised PnL: 0
72
         * Given Cash: 0
73
         * Service Cash: 0
74
         * Account IM:
75
         * Account MM:
76
         * -----
77
         * Coin: EOS
78
         * Equity: 0
79
         * Wallet Balance: 0
80
         * Position Margin: 0
81
         * Available Balance: 0
82
         * Order Margin: 0
83
         * Occ Closing Fee: 0
84
         * Occ Funding Fee: 0
85
         * Unrealised PnL: 0
86
         * Cumulative Realised PnL: 0
87
         * Given Cash: 0
88
         * Service Cash: 0
89
         * Account IM:
90
         * Account MM:
91
         */
92
93
        $this->assertTrue(true);
94
    }
95
96
}
97