Test Failed
Pull Request — master (#13)
by Vladislav
09:26 queued 01:13
created

PlaceOrderTest::testPlaceBuyMarketOrderEndpoint()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 28
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 21
nc 1
nop 0
dl 0
loc 28
rs 9.584
c 0
b 0
f 0
1
<?php
2
namespace Carpenstar\ByBitAPI\Spot\Trade\PlaceOrder\Tests;
3
4
use Carpenstar\ByBitAPI\BybitAPI;
5
use Carpenstar\ByBitAPI\Core\Enums\EnumOrderType;
6
use Carpenstar\ByBitAPI\Core\Enums\EnumSide;
7
use Carpenstar\ByBitAPI\Core\Exceptions\SDKException;
8
use Carpenstar\ByBitAPI\Spot\Trade\PlaceOrder\PlaceOrder;
9
use Carpenstar\ByBitAPI\Spot\Trade\PlaceOrder\Request\PlaceOrderRequest;
10
use Carpenstar\ByBitAPI\Spot\Trade\PlaceOrder\Response\PlaceOrderResponse;
11
use PHPUnit\Framework\TestCase;
12
13
class PlaceOrderTest extends TestCase
14
{
15
    static private string $placeOrderResponse = '{"retCode":0,"retMsg":"OK","result":{"orderId":"1477137337600322304","orderLinkId":"64c7ef2bdf040","symbol":"BTCUSDT","createTime":"1690824492584","orderPrice":"1000","orderQty":"0.001","orderType":"LIMIT","side":"BUY","status":"NEW","timeInForce":"GTC","accountId":"1111837","execQty":"0","orderCategory":0,"smpType":"None"},"retExtInfo":{},"time":1690824492593}';
0 ignored issues
show
introduced by
The private property $placeOrderResponse is not used, and could be removed.
Loading history...
16
17
    /**
18
     * Тестирование размещения ордера по рынку на покупку
19
     * @return void
20
     * @throws SDKException
21
     */
22
    public function testPlaceBuyMarketOrderEndpoint()
23
    {
24
        $params = (new PlaceOrderRequest())
25
            ->setSide(EnumSide::BUY)
26
            ->setOrderType(EnumOrderType::MARKET)
27
            ->setSymbol("ETHUSDT")
28
            ->setOrderQty(3500); // Если покупка по рынку, то это свойство эквивалент USDT
29
30
31
        $bybit = (new BybitAPI())->setCredentials('https://api-testnet.bybit.com', 'fL02oi5qo8i2jDxlum', 'Ne1EE35XTprIWrId9vGEAc1ZYJTmodA4qFzZ')
32
            ->privateEndpoint(PlaceOrder::class, $params)
33
            ->execute();
34
35
        /** @var PlaceOrderResponse $orderInfo */
36
        $orderInfo = $bybit->getResult();
37
38
        $this->assertNotEmpty($orderInfo->getOrderId());
39
        $this->assertNotEmpty($orderInfo->getOrderLinkId());
40
        $this->assertEquals('ETHUSDT', $orderInfo->getSymbol());
41
        $this->assertInstanceOf(\DateTime::class, $orderInfo->getCreateTime());
42
        $this->assertTrue($orderInfo->getOrderPrice() == 0);
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing $orderInfo->getOrderPrice() of type double|null to 0; this is ambiguous as not only 0 == 0 is true, but null == 0 is true, too. Consider using a strict comparison ===.
Loading history...
43
        $this->assertTrue($orderInfo->getOrderQty() == 3500);
44
        $this->assertEquals(strtoupper(EnumOrderType::MARKET), $orderInfo->getOrderType());
45
        $this->assertEquals(strtoupper(EnumSide::BUY), $orderInfo->getSide());
46
        $this->assertEquals('NEW', $orderInfo->getStatus());
47
        $this->assertEquals('GTC', $orderInfo->getTimeInForce());
48
        $this->assertNotEmpty($orderInfo->getAccountId());
49
        $this->assertEmpty($orderInfo->getTriggerPrice());
50
   }
51
52
    /**
53
     * Тестирование размещения лимитного ордера на покупку
54
     * @return void
55
     * @throws SDKException
56
     */
57
    public function testPlaceBuyLimitOrderEndpoint()
58
    {
59
        $params = (new PlaceOrderRequest())
60
            ->setSide(EnumSide::BUY)
61
            ->setOrderType(EnumOrderType::LIMIT)
62
            ->setOrderPrice(3000)
63
            ->setSymbol("ETHUSDT")
64
            ->setOrderQty(1);
65
66
67
        $bybit = (new BybitAPI())->setCredentials('https://api-testnet.bybit.com', 'fL02oi5qo8i2jDxlum', 'Ne1EE35XTprIWrId9vGEAc1ZYJTmodA4qFzZ')
68
            ->privateEndpoint(PlaceOrder::class, $params)
69
            ->execute();
70
71
        /** @var PlaceOrderResponse $orderInfo */
72
        $orderInfo = $bybit->getResult();
73
74
        $this->assertNotEmpty($orderInfo->getOrderId());
75
        $this->assertNotEmpty($orderInfo->getOrderLinkId());
76
        $this->assertEquals('ETHUSDT', $orderInfo->getSymbol());
77
        $this->assertInstanceOf(\DateTime::class, $orderInfo->getCreateTime());
78
        $this->assertTrue($orderInfo->getOrderPrice() == 3000);
79
        $this->assertTrue($orderInfo->getOrderQty() == 1);
80
        $this->assertEquals(strtoupper(EnumOrderType::LIMIT), $orderInfo->getOrderType());
81
        $this->assertEquals(strtoupper(EnumSide::BUY), $orderInfo->getSide());
82
        $this->assertEquals('NEW', $orderInfo->getStatus());
83
        $this->assertEquals('GTC', $orderInfo->getTimeInForce());
84
        $this->assertNotEmpty($orderInfo->getAccountId());
85
        $this->assertEmpty($orderInfo->getTriggerPrice());
86
    }
87
88
    /**
89
     * Тестирование размещения рыночного ордера на покупку
90
     * @return void
91
     * @throws SDKException
92
     */
93
    public function testPlaceSellMarketOrderEndpoint()
94
    {
95
        $params = (new PlaceOrderRequest())
96
            ->setSide(EnumSide::SELL)
97
            ->setOrderType(EnumOrderType::MARKET)
98
            ->setSymbol("ETHUSDT")
99
            ->setOrderQty(1); // При продаже по рынку, это свойство отвечает за количество токенов
100
101
102
        $bybit = (new BybitAPI())->setCredentials('https://api-testnet.bybit.com', 'fL02oi5qo8i2jDxlum', 'Ne1EE35XTprIWrId9vGEAc1ZYJTmodA4qFzZ')
103
            ->privateEndpoint(PlaceOrder::class, $params)
104
            ->execute();
105
106
        /** @var PlaceOrderResponse $orderInfo */
107
        $orderInfo = $bybit->getResult();
108
109
        $this->assertNotEmpty($orderInfo->getOrderId());
110
        $this->assertNotEmpty($orderInfo->getOrderLinkId());
111
        $this->assertEquals('ETHUSDT', $orderInfo->getSymbol());
112
        $this->assertInstanceOf(\DateTime::class, $orderInfo->getCreateTime());
113
        $this->assertTrue($orderInfo->getOrderPrice() == 0);
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing $orderInfo->getOrderPrice() of type double|null to 0; this is ambiguous as not only 0 == 0 is true, but null == 0 is true, too. Consider using a strict comparison ===.
Loading history...
114
        $this->assertTrue($orderInfo->getOrderQty() == 1);
115
        $this->assertEquals(strtoupper(EnumOrderType::MARKET), $orderInfo->getOrderType());
116
        $this->assertEquals(strtoupper(EnumSide::SELL), $orderInfo->getSide());
117
        $this->assertEquals('NEW', $orderInfo->getStatus());
118
        $this->assertEquals('GTC', $orderInfo->getTimeInForce());
119
        $this->assertNotEmpty($orderInfo->getAccountId());
120
        $this->assertEmpty($orderInfo->getTriggerPrice());
121
    }
122
}