OpenInterestTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 25
c 3
b 0
f 0
dl 0
loc 35
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A testOpenInterestEndpoint() 0 33 3
1
<?php
2
3
namespace Carpenstar\ByBitAPI\Derivatives\MarketData\OpenInterest\Tests;
4
5
use Carpenstar\ByBitAPI\BybitAPI;
6
use Carpenstar\ByBitAPI\Derivatives\MarketData\OpenInterest\OpenInterest;
7
use Carpenstar\ByBitAPI\Derivatives\MarketData\OpenInterest\Request\OpenInterestRequest;
8
use Carpenstar\ByBitAPI\Derivatives\MarketData\OpenInterest\Response\OpenInterestResponseItem;
9
use PHPUnit\Framework\TestCase;
10
11
class OpenInterestTest extends TestCase
12
{
13
    public function testOpenInterestEndpoint()
14
    {
15
        echo "\n //// --- //// \n";
16
17
        $bybit = (new BybitAPI())->setCredentials('https://api-testnet.bybit.com');
18
19
        $response = $bybit->publicEndpoint(
20
            OpenInterest::class,
21
            (new OpenInterestRequest())
22
            ->setSymbol('BTCUSDT')
23
            ->setInterval('5min')
24
            ->setStart('2024-07-11 10:00:00')
25
            ->setEnd('2024-07-12 11:00:00')
26
            ->setLimit(10)
27
        )->execute();
28
29
        if ($response->getReturnCode() == 0) {
30
            echo "CODE: {$response->getReturnCode()}\n";
31
            echo "MESSAGE: {$response->getReturnMessage()}\n";
32
33
            /** @var OpenInterestResponseItem $interest */
34
            foreach ($response->getResult()->getOpenInterestList() as $interest) {
0 ignored issues
show
Bug introduced by
The method getOpenInterestList() 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...se\OpenInterestResponse. ( Ignorable by Annotation )

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

34
            foreach ($response->getResult()->/** @scrutinizer ignore-call */ getOpenInterestList() as $interest) {
Loading history...
35
                echo " --- \n";
36
                echo "Time: {$interest->getTimestamp()->format('Y-m-d H:i:s')}\n";
37
                echo "Open Interest: {$interest->getOpenInterest()}\n";
38
            }
39
40
            $this->assertTrue(true);
41
        } else {
42
            echo "API ERORR: " . get_class($this) . "\n";
43
            echo "CODE: {$response->getReturnCode()} \n"; 
44
            echo "MESSAGE: {$response->getReturnMessage()} \n"; 
45
            echo "EXTENDED:" . implode(";\n", $response->getExtendedInfo()) . "\n"; 
46
        }
47
    }
48
}
49