|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Carpenstar\ByBitAPI\Derivatives\Contract\Position\MyPosition\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use Carpenstar\ByBitAPI\BybitAPI; |
|
6
|
|
|
use Carpenstar\ByBitAPI\Derivatives\Contract\Position\MyPosition\MyPosition; |
|
7
|
|
|
use Carpenstar\ByBitAPI\Derivatives\Contract\Position\MyPosition\Request\MyPositionRequest; |
|
8
|
|
|
use Carpenstar\ByBitAPI\Derivatives\Contract\Position\MyPosition\Response\MyPositionResponse; |
|
9
|
|
|
use PHPUnit\Framework\TestCase; |
|
10
|
|
|
|
|
11
|
|
|
class MyPositionTest extends TestCase |
|
12
|
|
|
{ |
|
13
|
|
|
public function testSuccessPosition() |
|
14
|
|
|
{ |
|
15
|
|
|
echo "\n //// --- //// \n"; |
|
16
|
|
|
|
|
17
|
|
|
$bybit = (new BybitAPI())->setCredentials('https://api-testnet.bybit.com', 'fL02oi5qo8i2jDxlum', 'Ne1EE35XTprIWrId9vGEAc1ZYJTmodA4qFzZ'); |
|
18
|
|
|
|
|
19
|
|
|
$response = $bybit->privateEndpoint(MyPosition::class, (new MyPositionRequest())->setSymbol('BTCUSDT'))->execute(); |
|
20
|
|
|
|
|
21
|
|
|
if ($response->getReturnCode() == 0) { |
|
22
|
|
|
echo "CODE: {$response->getReturnCode()}\n"; |
|
23
|
|
|
echo "MESSAGE: {$response->getReturnMessage()}\n"; |
|
24
|
|
|
|
|
25
|
|
|
/** @var MyPositionResponse $positionsListInfoResponse */ |
|
26
|
|
|
$positionsListInfoResponse = $response->getResult(); |
|
27
|
|
|
|
|
28
|
|
|
echo "Category: {$positionsListInfoResponse->getCategory()}\n"; |
|
29
|
|
|
echo "Next Page Cursor: {$positionsListInfoResponse->getNextPageCursor()}\n"; |
|
30
|
|
|
|
|
31
|
|
|
foreach ($positionsListInfoResponse->getPositionList() as $position) { |
|
32
|
|
|
echo "-----\n"; |
|
33
|
|
|
echo "Symbol: {$position->getSymbol()}\n"; |
|
34
|
|
|
echo "Side: {$position->getSide()}\n"; |
|
35
|
|
|
echo "Size: {$position->getSize()}\n"; |
|
36
|
|
|
echo "Entry Price: {$position->getEntryPrice()}\n"; |
|
37
|
|
|
echo "Leverage: {$position->getLeverage()}\n"; |
|
38
|
|
|
echo "Position Value: {$position->getPositionValue()}\n"; |
|
39
|
|
|
echo "Position Index: {$position->getPositionIdx()}\n"; |
|
40
|
|
|
echo "Risk ID: {$position->getRiskId()}\n"; |
|
41
|
|
|
echo "Risk Limit Value: {$position->getRiskLimitValue()}\n"; |
|
42
|
|
|
echo "Trade ModeL {$position->getTradeMode()}\n"; |
|
43
|
|
|
echo "Auto Add Margin: {$position->getAutoAddMargin()}\n"; |
|
44
|
|
|
echo "Position Balance: {$position->getPositionBalance()}\n"; |
|
45
|
|
|
echo "Liquidation Price: {$position->getLiqPrice()}\n"; |
|
46
|
|
|
echo "Bust Price: {$position->getBustPrice()}\n"; |
|
47
|
|
|
echo "TP/SL Mode: {$position->getTpSlMode()}\n"; |
|
48
|
|
|
echo "Take Profit: {$position->getTakeProfit()}\n"; |
|
49
|
|
|
echo "Stop-Loss: {$position->getStopLoss()}\n"; |
|
50
|
|
|
echo "Created time: {$position->getCreatedTime()->format('Y-m-d H:i:s')}\n"; |
|
51
|
|
|
echo "Update Time: {$position->getUpdatedTime()->format('Y-m-d H:i:s')}\n"; |
|
52
|
|
|
echo "Trailing Stop: {$position->getTrailingStop()}\n"; |
|
53
|
|
|
echo "Active Price: {$position->getActivePrice()}\n"; |
|
54
|
|
|
echo "Mark Price: {$position->getMarkPrice()}\n"; |
|
55
|
|
|
echo "Unrealised PnL: {$position->getUnrealisedPnl()}\n"; |
|
56
|
|
|
echo "Cumulative Realised PnL: {$position->getCumRealisedPnl()}\n"; |
|
57
|
|
|
echo "Maintenance Margin: {$position->getPositionMM()}\n"; |
|
58
|
|
|
echo "Initial Margin: {$position->getPositionIM()}\n"; |
|
59
|
|
|
echo "Position Status: {$position->getPositionStatus()}\n"; |
|
60
|
|
|
echo "Settlement Price: {$position->getSessionAvgPrice()}\n"; |
|
61
|
|
|
echo "Pre-occupancy Closing Fee: {$position->getOccClosingFee()}\n"; |
|
62
|
|
|
echo "Auto-deleverage Rank Indicator: {$position->getAdlRankIndicator()}\n"; |
|
63
|
|
|
} |
|
64
|
|
|
} else { |
|
65
|
|
|
echo "API ERORR: " . get_class($this) . "\n"; |
|
66
|
|
|
echo "CODE: {$response->getReturnCode()} \n"; |
|
67
|
|
|
echo "MESSAGE: {$response->getReturnMessage()} \n"; |
|
68
|
|
|
echo "EXTENDED:" . implode(";\n", $response->getExtendedInfo()) . "\n"; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
$this->assertTrue(true); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|