TickerInfoTest::testRiskLimitEndpoint()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 71
Code Lines 35

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
eloc 35
c 2
b 0
f 0
nc 2
nop 0
dl 0
loc 71
rs 9.36

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

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

26
            $tickerInfo = $response->getResult()->/** @scrutinizer ignore-call */ getTickerInfo();
Loading history...
27
    
28
            echo "Symbol: {$tickerInfo->getSymbol()}\n";
29
            echo "Bid Price: {$tickerInfo->getBidPrice()}\n";
30
            echo "Ask Price: {$tickerInfo->getAskPrice()}\n";
31
            echo "Last Price: {$tickerInfo->getLastPrice()}\n";
32
            echo "Last Tick Direction: {$tickerInfo->getLastTickDirection()}\n";
33
            echo "Prev Price 24 hours: {$tickerInfo->getPrevPrice24h()}\n";
34
            echo "Prev Price 24 hours(%): {$tickerInfo->getPrice24hPcnt()}\n";
35
            echo "High Price 24 hours: {$tickerInfo->getHighPrice24h()}\n";
36
            echo "Low Price 24 hours: {$tickerInfo->getLowPrice24h()}\n";
37
            echo "Prev price 1 hour: {$tickerInfo->getPrevPrice1h()}\n";
38
            echo "Mark Price: {$tickerInfo->getMarkPrice()}\n";
39
            echo "Index Price: {$tickerInfo->getIndexPrice()}\n";
40
            echo "Open Interest: {$tickerInfo->getOpenInterests()}\n";
41
            echo "Open Interest Value: {$tickerInfo->getOpenInterestValue()}\n";
42
            echo "Turnover 24 hours: {$tickerInfo->getTurnover24h()}\n";
43
            echo "Volume 24 hours: {$tickerInfo->getVolume24h()}\n";
44
            echo "Funding Rate: {$tickerInfo->getFundingRate()}\n";
45
            echo "Next Funding Time: {$tickerInfo->getNextFundingTime()->format("Y-m-d H:i:s")}\n";
46
            echo "Predicted Delivery Price: {$tickerInfo->getPredictedDeliveryPrice()}\n";
47
            echo "Basis Rate: {$tickerInfo->getBasisRate()}\n";
48
            echo "Delivery Fee Rate: {$tickerInfo->getDeliveryFeeRate()}\n";
49
            echo "Open Interests Value: {$tickerInfo->getOpenInterestValue()}\n";
50
    
51
            /**
52
             * Return code: 0
53
             * Return message: OK
54
             * Symbol: BTCUSDT
55
             * Bid Price: 59933.6
56
             * Ask Price: 59935.7
57
             * Last Price: 59938
58
             * Last Tick Direction: ZeroMinusTick
59
             * Prev Price 24 hours: 58627.5
60
             * Prev Price 24 hours(%): 0.022352
61
             * High Price 24 hours: 63074.5
62
             * Low Price 24 hours: 58267.4
63
             * Prev price 1 hour: 59997
64
             * Mark Price: 59938
65
             * Index Price: 59957.26
66
             * Open Interest: 208384.158
67
             * Open Interest Value: 12490129662.2
68
             * Turnover 24 hours: 2907929540.5417
69
             * Volume 24 hours: 48504.964
70
             * Funding Rate: 8.407E-5
71
             * Next Funding Time: 2024-07-15 00:00:00
72
             * Predicted Delivery Price: 0
73
             * Basis Rate: 0
74
             * Delivery Fee Rate: 0
75
             * Open Interests Value: 12490129662.2
76
             */
77
    
78
            $this->assertTrue(true);
79
        } else {
80
            echo "API ERORR: " . get_class($this) . "\n";
81
            echo "CODE: {$response->getReturnCode()} \n"; 
82
            echo "MESSAGE: {$response->getReturnMessage()} \n"; 
83
            echo "EXTENDED:" . implode(";\n", $response->getExtendedInfo()) . "\n"; 
84
        }
85
    }
86
}
87