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

GetOrderListTest::testSuccessEndpoint()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 144
Code Lines 52

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 52
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 144
rs 9.0472

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\Contract\Order\GetOrderList\Tests;
4
5
use Carpenstar\ByBitAPI\BybitAPI;
6
use Carpenstar\ByBitAPI\Core\Interfaces\IResponseInterface;
7
use Carpenstar\ByBitAPI\Derivatives\Contract\Order\GetOrderList\GetOrderList;
8
use Carpenstar\ByBitAPI\Derivatives\Contract\Order\GetOrderList\Interfaces\IGetOrderListResponseItemInterface;
9
use Carpenstar\ByBitAPI\Derivatives\Contract\Order\GetOrderList\Request\GetOrderListRequest;
10
use Carpenstar\ByBitAPI\Derivatives\Contract\Order\GetOrderList\Response\GetOrderListResponse;
11
use PHPUnit\Framework\TestCase;
12
13
class GetOrderListTest extends TestCase
14
{
15
    public function testSuccessEndpoint()
16
    {
17
        echo "\n //// --- //// \n";
18
        
19
        $bybitApi = (new BybitAPI())->setCredentials('https://api-testnet.bybit.com', 'fL02oi5qo8i2jDxlum', 'Ne1EE35XTprIWrId9vGEAc1ZYJTmodA4qFzZ');
20
21
        /** @var IResponseInterface $endpointResponse */
22
        $response = $bybitApi->privateEndpoint(GetOrderList::class, (new GetOrderListRequest())->setSymbol('BTCUSDT')->setLimit(2))->execute();
23
24
25
        if ($response->getReturnCode() == 0) {
26
            echo "CODE: {$response->getReturnCode()} \n";
27
            echo "MESSAGE: {$response->getReturnMessage()} \n";
28
    
29
            /** @var GetOrderListResponse $getOrderListResponse */
30
            $getOrderListResponse = $response->getResult();
31
            echo "Product Category: {$getOrderListResponse->getCategory()}\n";
32
            echo "Next Page Cursor: {$getOrderListResponse->getNextPageCursor()}\n";
33
            echo "Order List:\n";
34
    
35
            /** @var IGetOrderListResponseItemInterface $order */
36
            foreach ($getOrderListResponse->getOrderList() as $order) {
37
                echo "-----\n";
38
                echo "Symbol: {$order->getSymbol()}\n";
39
                echo "Order ID: {$order->getOrderId()}\n";
40
                echo "Order Link ID: {$order->getOrderLinkId()}\n";
41
                echo "Side: {$order->getSide()}\n";
42
                echo "Order Type: {$order->getOrderType()}\n";
43
                echo "Order price: {$order->getPrice()}\n";
44
                echo "Order Quantity: {$order->getQty()}\n";
45
                echo "Time In Force: {$order->getTimeInForce()}\n";
46
                echo "Order Status: {$order->getOrderStatus()}\n";
47
                echo "Position Index: {$order->getPositionIdx()}\n";
48
                echo "Last Price On Created: {$order->getLastPriceOnCreated()}\n";
49
                echo "Created Time: {$order->getCreatedTime()->format('Y-m-d H:i:s')}\n";
50
                echo "Updated Time: {$order->getUpdatedTime()->format('Y-m-d H:i:s')}\n";
51
                echo "Cancel Type: {$order->getCancelType()}\n";
52
                echo "Reject Reason: {$order->getRejectReason()}\n";
53
                echo "Stop Order Price: {$order->getStopOrderType()}\n";
54
                echo "Trigger Direction: {$order->getTriggerDirection()}\n";
55
                echo "Trigger By: {$order->getTriggerBy()}\n";
56
                echo "Trigger Price: {$order->getTriggerPrice()}\n";
57
                echo "Cumulative Executed Fee: {$order->getCumExecFee()}\n";
58
                echo "Cumulative Executed Value: {$order->getCumExecValue()}\n";
59
                echo "Cumulative Executed Quantity: {$order->getCumExecQty()}\n";
60
                echo "Leaves Value {$order->getLeavesValue()}\n";
61
                echo "Leaves Quantity: {$order->getLeavesQty()}\n";
62
                echo "Take Profit: {$order->getTakeProfit()}\n";
63
                echo "Stop Loss: {$order->getStopLoss()}\n";
64
                echo "TP/SL Mode: {$order->getTpslMode()}\n";
65
                echo "Take Profit Limit Price: {$order->getTpLimitPrice()}\n";
66
                echo "Stop-Loss Limit Price: {$order->getSlLimitPrice()}\n";
67
                echo "Take Profit Trigger By {$order->getTpTriggerBy()}\n";
68
                echo "Stop-Loss Trigger By {$order->getSlTriggerBy()}\n";
69
                echo "Reduce Only: {$order->isReduceOnly()}\n";
70
                echo "Close On Trigger: {$order->isCloseOnTrigger()} {}\n";
71
                echo "Block Trade ID: {$order->getBlockTradeId()}\n";
72
            }
73
    
74
            /**
75
             * Return code: 0
76
             * Return message: OK
77
             * Product Category:
78
             * Next Page Cursor: eyJza2lwX2xvY2FsX3N5bWJvbCI6ZmFsc2UsInBhZ2VfdG9rZW4iOiIzODA1NCJ9
79
             * Order List:
80
             * -----
81
             *  Symbol: BTCUSDT
82
             *  Order ID: 55b6ef38-689e-46c0-a55b-e7124f90004a
83
             *  Order Link ID:
84
             *  Side: Sell
85
             *  Order Type: Limit
86
             *  Order price: 66037
87
             *  Order Quantity: 0.001
88
             *  Time In Force: GoodTillCancel
89
             *  Order Status: Filled
90
             *  Position Index: 0
91
             *  Last Price On Created: 0
92
             *  Created Time: 2024-06-18 21:11:47
93
             *  Updated Time: 2024-06-20 10:57:59
94
             *  Cancel Type: UNKNOWN
95
             *  Reject Reason: EC_NoError
96
             *  Stop Order Price: UNKNOWN
97
             *  Trigger Direction: 0
98
             *  Trigger By: UNKNOWN
99
             *  Trigger Price: 0
100
             *  Cumulative Executed Fee: 0.0132074
101
             *  Cumulative Executed Value: 66.037
102
             *  Cumulative Executed Quantity: 0.001
103
             *  Leaves Value 0
104
             *  Leaves Quantity: 0
105
             *  Take Profit: 0
106
             *  Stop Loss: 0
107
             *  TP/SL Mode:
108
             *  Take Profit Limit Price: 0
109
             *  Stop-Loss Limit Price: 0
110
             *  Take Profit Trigger By UNKNOWN
111
             *  Stop-Loss Trigger By UNKNOWN
112
             *  Reduce Only:
113
             *  Close On Trigger:  {}
114
             *  Block Trade ID:
115
             *  -----
116
             *  Symbol: BTCUSDT
117
             *  Order ID: 4f279264-6d38-46c1-8216-7e5a2f110c11
118
             *  Order Link ID:
119
             *  Side: Sell
120
             *  Order Type: Limit
121
             *  Order price: 67037
122
             *  Order Quantity: 0.001
123
             *  Time In Force: GoodTillCancel
124
             *  Order Status: New
125
             *  Position Index: 0
126
             *  Last Price On Created: 0
127
             *  Created Time: 2024-06-18 21:11:43
128
             *  Updated Time: 2024-06-18 21:11:43
129
             *  Cancel Type: UNKNOWN
130
             *  Reject Reason: EC_NoError
131
             *  Stop Order Price: UNKNOWN
132
             *  Trigger Direction: 0
133
             *  Trigger By: UNKNOWN
134
             *  Trigger Price: 0
135
             *  Cumulative Executed Fee: 0
136
             *  Cumulative Executed Value: 0
137
             *  Cumulative Executed Quantity: 0
138
             *  Leaves Value 67.037
139
             *  Leaves Quantity: 0.001
140
             *  Take Profit: 0
141
             *  Stop Loss: 0
142
             *  TP/SL Mode:
143
             *  Take Profit Limit Price: 0
144
             *  Stop-Loss Limit Price: 0
145
             *  Take Profit Trigger By UNKNOWN
146
             *  Stop-Loss Trigger By UNKNOWN
147
             *  Reduce Only:
148
             *  Close On Trigger:  {}
149
             *  Block Trade ID:
150
             **/            
151
        } else {
152
            echo "API ERORR: " . get_class($this) . "\n";
153
            echo "CODE: {$response->getReturnCode()} \n"; 
154
            echo "MESSAGE: {$response->getReturnMessage()} \n"; 
155
            echo "EXTENDED:" . implode(";\n", $response->getExtendedInfo()) . "\n"; 
156
        }
157
158
         $this->assertTrue(true);
159
    }
160
}
161