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