Test Failed
Pull Request — master (#22)
by Vladislav
02:33
created

GetClosedPnLTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A testSuccessEndpoint() 0 51 3
1
<?php
2
3
namespace Carpenstar\ByBitAPI\Derivatives\Contract\Position\GetClosedPnL\Tests;
4
5
use Carpenstar\ByBitAPI\BybitAPI;
6
use Carpenstar\ByBitAPI\Derivatives\Contract\Position\GetClosedPnL\GetClosedPnL;
7
use Carpenstar\ByBitAPI\Derivatives\Contract\Position\GetClosedPnL\Interfaces\IGetClosedPnLResponseInterface;
8
use Carpenstar\ByBitAPI\Derivatives\Contract\Position\GetClosedPnL\Request\GetClosedPnLRequest;
9
use PHPUnit\Framework\TestCase;
10
11
class GetClosedPnLTest extends TestCase
12
{
13
    public function testSuccessEndpoint()
14
    {
15
        echo "\n //// --- //// \n";
16
        
17
        $bybit = (new BybitAPI())->setCredentials('https://api-testnet.bybit.com', 'fL02oi5qo8i2jDxlum', 'Ne1EE35XTprIWrId9vGEAc1ZYJTmodA4qFzZ');
18
19
        $response = $bybit->privateEndpoint(
20
            GetClosedPnL::class,
21
            (new GetClosedPnLRequest())
22
            ->setSymbol('BTCUSDT')
23
            ->setLimit(2)
24
        )->execute();
25
26
        if ($response->getReturnCode()) {
27
            echo "CODE: {$response->getReturnCode()} \n";
28
            echo "MESSAGE: {$response->getReturnMessage()} \n";
29
    
30
            /** @var IGetClosedPnLResponseInterface $pnlInfoResponse */
31
            $pnlInfoResponse = $response->getResult();
32
            echo "Next page cursor: {$pnlInfoResponse->getNextPageCursor()}\n";
33
            echo "----\n";
34
            foreach ($pnlInfoResponse->getClosedPnlList() as $pnl) {
35
                echo "----\n";
36
                echo "Symbol: {$pnl->getSymbol()}\n";
37
                echo "Order ID: {$pnl->getOrderId()}\n";
38
                echo "Side: {$pnl->getSide()}\n";
39
                echo "Quantity: {$pnl->getQty()}\n";
40
                echo "Leverage: {$pnl->getLeverage()}\n";
41
                echo "Order Price: {$pnl->getOrderPrice()}\n";
42
                echo "Order Type: {$pnl->getOrderType()}\n";
43
                echo "Executed Type: {$pnl->getExecType()}\n";
44
                echo "Closed Size: {$pnl->getClosedSize()}\n";
45
                echo "Cumulative Entry Value: {$pnl->getCumEntryValue()}\n";
46
                echo "Average Entry Price: {$pnl->getAvgEntryPrice()}\n";
47
                echo "Cumulative Exit Value {$pnl->getCumExitValue()}\n";
48
                echo "Average Exit Price: {$pnl->getAvgExitPrice()}\n";
49
                echo "Closed PnL: {$pnl->getClosedPnl()}\n";
50
                echo "Filled Count: {$pnl->getFillCount()}\n";
51
                echo "Created At: {$pnl->getCreatedAt()->format('Y-m-d H:i:s')}\n";
52
                echo "Created Time: {$pnl->getCreatedTime()->format('Y-m-d H:i:s')}\n";
53
                echo "Updated Time: {$pnl->getUpdatedTime()->format('Y-m-d H:i:s')}\n";
54
            }
55
        } else {
56
            echo "API ERORR: " . get_class($this) . "\n";
57
            echo "CODE: {$response->getReturnCode()} \n"; 
58
            echo "MESSAGE: {$response->getReturnMessage()} \n"; 
59
            echo "EXTENDED:" . implode(";\n", $response->getExtendedInfo()) . "\n"; 
60
        }
61
62
63
        $this->assertTrue(true);
64
    }
65
}
66