InstrumentInfoTest::testInstrumentInfoResponse()   B
last analyzed

Complexity

Conditions 5
Paths 9

Size

Total Lines 57
Code Lines 45

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 5
eloc 45
c 3
b 0
f 0
nc 9
nop 0
dl 0
loc 57
rs 8.8888

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\MarketData\InstrumentInfo\Tests;
4
5
use Carpenstar\ByBitAPI\BybitAPI;
6
use Carpenstar\ByBitAPI\Derivatives\MarketData\InstrumentInfo\InstrumentInfo;
7
use Carpenstar\ByBitAPI\Derivatives\MarketData\InstrumentInfo\Interfaces\IInstrumentInfoResponseItemInterface;
8
use Carpenstar\ByBitAPI\Derivatives\MarketData\InstrumentInfo\Request\InstrumentInfoRequest;
9
use PHPUnit\Framework\TestCase;
10
11
class InstrumentInfoTest extends TestCase
12
{
13
    public function testInstrumentInfoResponse()
14
    {
15
        echo "\n //// --- //// \n";
16
17
        $bybit = (new BybitAPI())->setCredentials('https://api-testnet.bybit.com');
18
19
        $response = $bybit->publicEndpoint(
20
            InstrumentInfo::class,
21
            (new InstrumentInfoRequest())
22
            ->setSymbol('BTCUSDT')
23
        )->execute();
24
25
        if ($response->getReturnCode() == 0) {
26
            echo "CODE: {$response->getReturnCode()}\n";
27
            echo "MESSAGE: {$response->getReturnMessage()}\n";
28
    
29
            /** @var IInstrumentInfoResponseItemInterface $instrumentInfo */
30
            $instrumentInfo = $response->getResult()->getInstrumentInfoList();
0 ignored issues
show
Bug introduced by
The method getInstrumentInfoList() 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...\InstrumentInfoResponse. ( Ignorable by Annotation )

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

30
            $instrumentInfo = $response->getResult()->/** @scrutinizer ignore-call */ getInstrumentInfoList();
Loading history...
31
    
32
            echo "Next Page Cursor: {$instrumentInfo->getNextPageCursor()} \n";
33
            echo "Symbol: {$instrumentInfo->getSymbol()}\n";
34
            echo "Contract Type: {$instrumentInfo->getContractType()}\n";
35
            echo "Status: {$instrumentInfo->getStatus()}\n";
36
            echo "Base Coin: {$instrumentInfo->getBaseCoin()}\n";
37
            echo "Settle Coin: {$instrumentInfo->getSettleCoin()} \n";
38
            echo "Quote Coin: {$instrumentInfo->getQuoteCoin()}\n";
39
            echo "Launch Time: {$instrumentInfo->getLaunchTime()->format('Y-m-d H:i:s')}\n";
40
            echo "Delivery Time: {$instrumentInfo->getDeliveryTime()->format('Y-m-d H:i:s')} {}\n";
41
            echo "Delivery Fee Rate: {$instrumentInfo->getDeliveryFeeRate()} {}\n";
42
            echo "Price Scale: {$instrumentInfo->getPriceScale()}\n";
43
            echo "Unified Margin Trade: {$instrumentInfo->getUnifiedMarginTrade()}\n";
44
            echo "Funding Interval: {$instrumentInfo->getFundingInterval()}\n";
45
            echo "Leverage Filter: \n";
46
            foreach ($instrumentInfo->getLeverageFilter()->all() as $filterItem) {
47
                echo "  - Minimal Leverage: {$filterItem->getMinLeverage()} \n";
48
                echo "  - Maximal Leverage: {$filterItem->getMaxLeverage()} \n";
49
                echo "  - Leverage Step: {$filterItem->getLeverageStep()} \n";
50
            }
51
            echo "Price Filter: \n";
52
            foreach ($instrumentInfo->getPriceFilter()->all() as $priceFilter) {
53
                echo "  - Minimal Price: {$priceFilter->getMinPrice()} \n";
54
                echo "  - Maximal Price: {$priceFilter->getMaxPrice()} \n";
55
                echo "  - Tick Size: {$priceFilter->getTickSize()} \n";
56
            }
57
            echo "Lot Size Filter: \n";
58
            foreach ($instrumentInfo->getLotSizeFilter()->all() as $lotSizeFilter) {
59
                echo "  - Maximal Order Quantity: {$lotSizeFilter->getMaxOrderQty()} \n";
60
                echo "  - Minimal Order Quantity: {$lotSizeFilter->getMinOrderQty()} \n";
61
                echo "  - Quantity Step: {$lotSizeFilter->getQtyStep()} \n";
62
            }
63
    
64
            $this->assertTrue(true);
65
        } else {
66
            echo "API ERORR: " . get_class($this) . "\n";
67
            echo "CODE: {$response->getReturnCode()} \n"; 
68
            echo "MESSAGE: {$response->getReturnMessage()} \n"; 
69
            echo "EXTENDED:" . implode(";\n", $response->getExtendedInfo()) . "\n"; 
70
        }
71
    }
72
}
73