1
|
|
|
<?php |
2
|
|
|
namespace Carpenstar\ByBitAPI\Spot\Trade\GetOrder\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\Core\Response\CurlResponseHandler; |
9
|
|
|
use Carpenstar\ByBitAPI\Spot\Trade\GetOrder\GetOrder; |
10
|
|
|
use Carpenstar\ByBitAPI\Spot\Trade\GetOrder\Request\GetOrderRequest; |
11
|
|
|
use Carpenstar\ByBitAPI\Spot\Trade\GetOrder\Response\GetOrderResponse; |
12
|
|
|
use Carpenstar\ByBitAPI\Spot\Trade\PlaceOrder\PlaceOrder; |
13
|
|
|
use Carpenstar\ByBitAPI\Spot\Trade\PlaceOrder\Request\PlaceOrderRequest; |
14
|
|
|
use Carpenstar\ByBitAPI\Spot\Trade\PlaceOrder\Response\PlaceOrderResponse; |
15
|
|
|
use PHPUnit\Framework\TestCase; |
16
|
|
|
|
17
|
|
|
class GetOrderTest extends TestCase |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* Тестирование заполнения структуры ответа |
21
|
|
|
* @return void |
22
|
|
|
*/ |
23
|
|
|
public function testBuildResponseData() |
24
|
|
|
{ |
25
|
|
|
$json = '{"retCode":0,"retMsg":"OK","result":{"accountId":"1111837","symbol":"BTCUSDT","orderLinkId":"64c7ef2bdf040","orderId":"1477137337600322304","orderPrice":"1000","orderQty":"0.001","execQty":"0","cummulativeQuoteQty":"0","avgPrice":"0","status":"NEW","timeInForce":"GTC","orderType":"LIMIT","side":"BUY","stopPrice":"0.0","icebergQty":"0.0","createTime":"1690824492584","updateTime":"1690824492595","isWorking":"1","locked":"1","orderCategory":0,"blockTradeId":"","smpType":"None","cancelType":"UNKNOWN","smpGroup":0,"smpOrderId":""},"retExtInfo":{},"time":1690834565801}'; |
26
|
|
|
$data = (new CurlResponseHandler())->build(json_decode($json, true), GetOrderResponse::class); |
27
|
|
|
|
28
|
|
|
$this->assertEquals(0, $data->getReturnCode()); |
29
|
|
|
$this->assertEquals('OK', $data->getReturnMessage()); |
30
|
|
|
$this->assertInstanceOf(GetOrderResponse::class, $data->getResult()); |
31
|
|
|
|
32
|
|
|
/** @var GetOrderResponse $orderInfo */ |
33
|
|
|
$orderInfo = $data->getResult(); |
34
|
|
|
|
35
|
|
|
$this->assertIsInt($orderInfo->getOrderId()); |
36
|
|
|
$this->assertIsString($orderInfo->getOrderLinkId()); |
37
|
|
|
$this->assertIsString($orderInfo->getSymbol()); |
38
|
|
|
$this->assertIsString($orderInfo->getStatus()); |
39
|
|
|
$this->assertIsInt($orderInfo->getAccountId()); |
40
|
|
|
$this->assertIsFloat($orderInfo->getOrderPrice()); |
41
|
|
|
$this->assertInstanceOf(\DateTime::class, $orderInfo->getCreateTime()); |
42
|
|
|
$this->assertIsFloat($orderInfo->getOrderQty()); |
43
|
|
|
$this->assertIsFloat($orderInfo->getExecQty()); |
44
|
|
|
$this->assertIsString($orderInfo->getTimeInForce()); |
45
|
|
|
$this->assertIsString($orderInfo->getOrderType()); |
46
|
|
|
$this->assertIsString($orderInfo->getSide()); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Тестирование эндпоинта на корректное исполнение |
51
|
|
|
* @return void |
52
|
|
|
* @throws SDKException |
53
|
|
|
*/ |
54
|
|
|
public function testGetOrderEndpoint() |
55
|
|
|
{ |
56
|
|
|
$bybit = (new BybitAPI())->setCredentials('https://api-testnet.bybit.com', 'fL02oi5qo8i2jDxlum', 'Ne1EE35XTprIWrId9vGEAc1ZYJTmodA4qFzZ'); |
57
|
|
|
|
58
|
|
|
$params = (new PlaceOrderRequest()) |
59
|
|
|
->setSide(EnumSide::BUY) |
60
|
|
|
->setOrderType(EnumOrderType::LIMIT) |
61
|
|
|
->setOrderPrice(3000) |
62
|
|
|
->setSymbol("ETHUSDT") |
63
|
|
|
->setOrderQty(1); |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
$placeOrderEndpoint = $bybit->privateEndpoint(PlaceOrder::class, $params)->execute(); |
67
|
|
|
|
68
|
|
|
/** @var PlaceOrderResponse $orderInfo */ |
69
|
|
|
$orderInfo = $placeOrderEndpoint->getResult(); |
70
|
|
|
|
71
|
|
|
$this->assertNotEmpty($orderInfo->getOrderId()); |
72
|
|
|
$this->assertNotEmpty($orderInfo->getOrderLinkId()); |
73
|
|
|
$this->assertEquals('ETHUSDT', $orderInfo->getSymbol()); |
74
|
|
|
$this->assertInstanceOf(\DateTime::class, $orderInfo->getCreateTime()); |
75
|
|
|
$this->assertTrue($orderInfo->getOrderPrice() == 3000); |
76
|
|
|
$this->assertTrue($orderInfo->getOrderQty() == 1); |
77
|
|
|
$this->assertEquals(strtoupper(EnumOrderType::LIMIT), $orderInfo->getOrderType()); |
78
|
|
|
$this->assertEquals(strtoupper(EnumSide::BUY), $orderInfo->getSide()); |
79
|
|
|
$this->assertEquals('NEW', $orderInfo->getStatus()); |
80
|
|
|
$this->assertEquals('GTC', $orderInfo->getTimeInForce()); |
81
|
|
|
$this->assertNotEmpty($orderInfo->getAccountId()); |
82
|
|
|
$this->assertEmpty($orderInfo->getTriggerPrice()); |
83
|
|
|
|
84
|
|
|
$getOrderResponse = $bybit->privateEndpoint(GetOrder::class, (new GetOrderRequest())->setOrderId($orderInfo->getOrderId()))->execute(); |
85
|
|
|
|
86
|
|
|
$this->assertEquals(0, $getOrderResponse->getReturnCode()); |
87
|
|
|
$this->assertEquals('OK', $getOrderResponse->getReturnMessage()); |
88
|
|
|
$this->assertInstanceOf(GetOrderResponse::class, $getOrderResponse->getResult()); |
89
|
|
|
|
90
|
|
|
/** @var GetOrderResponse $getOrderInfo */ |
91
|
|
|
$getOrderInfo = $getOrderResponse->getResult(); |
92
|
|
|
|
93
|
|
|
$this->assertIsInt($getOrderInfo->getOrderId()); |
94
|
|
|
$this->assertIsString($getOrderInfo->getOrderLinkId()); |
95
|
|
|
$this->assertIsString($getOrderInfo->getSymbol()); |
96
|
|
|
$this->assertIsString($getOrderInfo->getStatus()); |
97
|
|
|
$this->assertIsInt($getOrderInfo->getAccountId()); |
98
|
|
|
$this->assertIsFloat($getOrderInfo->getOrderPrice()); |
99
|
|
|
$this->assertInstanceOf(\DateTime::class, $getOrderInfo->getCreateTime()); |
100
|
|
|
$this->assertIsFloat($getOrderInfo->getOrderQty()); |
101
|
|
|
$this->assertIsFloat($getOrderInfo->getExecQty()); |
102
|
|
|
$this->assertIsString($getOrderInfo->getTimeInForce()); |
103
|
|
|
$this->assertIsString($getOrderInfo->getOrderType()); |
104
|
|
|
$this->assertIsString($getOrderInfo->getSide()); |
105
|
|
|
} |
106
|
|
|
} |