|
1
|
|
|
<?php |
|
2
|
|
|
namespace Carpenstar\ByBitAPI\Spot\Trade\OrderHistory\Tests; |
|
3
|
|
|
|
|
4
|
|
|
|
|
5
|
|
|
use Carpenstar\ByBitAPI\BybitAPI; |
|
6
|
|
|
use Carpenstar\ByBitAPI\Core\Exceptions\SDKException; |
|
7
|
|
|
use Carpenstar\ByBitAPI\Core\Response\CurlResponseHandler; |
|
8
|
|
|
use Carpenstar\ByBitAPI\Spot\Trade\OrderHistory\OrderHistory; |
|
9
|
|
|
use Carpenstar\ByBitAPI\Spot\Trade\OrderHistory\Request\OrderHistoryRequest; |
|
10
|
|
|
use Carpenstar\ByBitAPI\Spot\Trade\OrderHistory\Response\OrderHistoryResponse; |
|
11
|
|
|
use Carpenstar\ByBitAPI\Spot\Trade\OrderHistory\Response\OrderHistoryResponseItem; |
|
12
|
|
|
use PHPUnit\Framework\TestCase; |
|
13
|
|
|
|
|
14
|
|
|
class OrderHistoryTest extends TestCase |
|
15
|
|
|
{ |
|
16
|
|
|
static private string $orderHistoryResponse = '{"retCode":0,"retMsg":"OK","result":{"list":[{"accountId":"533287","symbol":"BTCUSDT","orderLinkId":"spotx003","orderId":"1210856408331857664","orderPrice":"23800","orderQty":"0.02","execQty":"0","cummulativeQuoteQty":"0","avgPrice":"0","status":"REJECTED","timeInForce":"GTC","orderType":"LIMIT_MAKER","side":"BUY","stopPrice":"0.0","icebergQty":"0.0","createTime":1659081332185,"updateTime":1659081332225,"isWorking":"1","blockTradeId":"","cancelType":"UNKNOWN","smpGroup":0,"smpOrderId":"","smpType":"None"}]},"retExtInfo":{},"time":1659082630638}'; |
|
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Тестирование заполнения структуры ответа |
|
20
|
|
|
* @return void |
|
21
|
|
|
*/ |
|
22
|
|
|
public function testBuildResponseData() |
|
23
|
|
|
{ |
|
24
|
|
|
$json = '{"retCode":0,"retMsg":"OK","result":{"list":[{"accountId":"533287","symbol":"BTCUSDT","orderLinkId":"spotx004","orderId":"1210858291884732160","orderPrice":"23500","orderQty":"0.02","execQty":"0","cummulativeQuoteQty":"0","avgPrice":"0","status":"NEW","timeInForce":"GTC","orderType":"LIMIT_MAKER","side":"SELL","stopPrice":"0.0","icebergQty":"0.0","createTime":1659081556722,"updateTime":1659081556740,"isWorking":"1","blockTradeId":"","cancelType":"UNKNOWN","smpGroup":0,"smpOrderId":"","smpType":"None"}]},"retExtInfo": {},"time": 1659081570356}'; |
|
25
|
|
|
$data = (new CurlResponseHandler())->build(json_decode($json, true), OrderHistoryResponse::class); |
|
26
|
|
|
|
|
27
|
|
|
$this->assertEquals(0, $data->getReturnCode()); |
|
28
|
|
|
$this->assertEquals('OK', $data->getReturnMessage()); |
|
29
|
|
|
$this->assertInstanceOf(OrderHistoryResponse::class, $data->getResult()); |
|
30
|
|
|
|
|
31
|
|
|
$orderInfo = $data->getResult(); |
|
32
|
|
|
foreach ($orderInfo->getOrderHistory() as $order) { |
|
|
|
|
|
|
33
|
|
|
$this->assertIsInt($order->getAccountId()); |
|
34
|
|
|
$this->assertIsString($order->getSymbol()); |
|
35
|
|
|
$this->assertIsString($order->getOrderLinkId()); |
|
36
|
|
|
$this->assertIsInt($order->getOrderId()); |
|
37
|
|
|
$this->assertIsFloat($order->getOrderPrice()); |
|
38
|
|
|
$this->assertIsFloat($order->getOrderQty()); |
|
39
|
|
|
$this->assertIsFloat($order->getExecQty()); |
|
40
|
|
|
$this->assertIsFloat($order->getCummulativeQuoteQty()); |
|
41
|
|
|
$this->assertIsFloat($order->getAvgPrice()); |
|
42
|
|
|
$this->assertIsString($order->getStatus()); |
|
43
|
|
|
$this->assertIsString($order->getTimeInForce()); |
|
44
|
|
|
$this->assertIsString($order->getOrderType()); |
|
45
|
|
|
$this->assertIsString($order->getSide()); |
|
46
|
|
|
$this->assertIsFloat($order->getStopPrice()); |
|
47
|
|
|
$this->assertInstanceOf(\DateTime::class, $order->getCreateTime()); |
|
48
|
|
|
$this->assertInstanceOf(\DateTime::class, $order->getUpdateTime()); |
|
49
|
|
|
$this->assertIsInt($order->getIsWorking()); |
|
50
|
|
|
$this->assertIsInt($order->getOrderCategory()); |
|
51
|
|
|
if (!is_null($order->getTriggerPrice())) { |
|
52
|
|
|
$this->assertIsFloat($order->getTriggerPrice()); |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Тестирование эндпоинта на корректное исполнение |
|
59
|
|
|
* @return void |
|
60
|
|
|
* @throws SDKException |
|
61
|
|
|
*/ |
|
62
|
|
|
public function testOrderHistoryEndpoint() |
|
63
|
|
|
{ |
|
64
|
|
|
$bybit = (new BybitAPI())->setCredentials('https://api-testnet.bybit.com', 'fL02oi5qo8i2jDxlum', 'Ne1EE35XTprIWrId9vGEAc1ZYJTmodA4qFzZ'); |
|
65
|
|
|
|
|
66
|
|
|
$orderHistoryResponse = $bybit->privateEndpoint(OrderHistory::class, (new OrderHistoryRequest())->setSymbol('ETHUSDT'))->execute(); |
|
67
|
|
|
|
|
68
|
|
|
$this->assertEquals(0, $orderHistoryResponse->getReturnCode()); |
|
69
|
|
|
$this->assertEquals('OK', $orderHistoryResponse->getReturnMessage()); |
|
70
|
|
|
$this->assertInstanceOf(OrderHistoryResponse::class, $orderHistoryResponse->getResult()); |
|
71
|
|
|
|
|
72
|
|
|
$orderInfoList = $orderHistoryResponse->getResult()->getOrderHistory(); |
|
73
|
|
|
|
|
74
|
|
|
foreach ($orderInfoList as $order) { |
|
75
|
|
|
$this->assertIsInt($order->getAccountId()); |
|
76
|
|
|
$this->assertIsString($order->getSymbol()); |
|
77
|
|
|
$this->assertIsString($order->getOrderLinkId()); |
|
78
|
|
|
$this->assertIsInt($order->getOrderId()); |
|
79
|
|
|
$this->assertIsFloat($order->getOrderPrice()); |
|
80
|
|
|
$this->assertIsFloat($order->getOrderQty()); |
|
81
|
|
|
$this->assertIsFloat($order->getExecQty()); |
|
82
|
|
|
$this->assertIsFloat($order->getCummulativeQuoteQty()); |
|
83
|
|
|
$this->assertIsFloat($order->getAvgPrice()); |
|
84
|
|
|
$this->assertIsString($order->getStatus()); |
|
85
|
|
|
$this->assertIsString($order->getTimeInForce()); |
|
86
|
|
|
$this->assertIsString($order->getOrderType()); |
|
87
|
|
|
$this->assertIsString($order->getSide()); |
|
88
|
|
|
$this->assertIsFloat($order->getStopPrice()); |
|
89
|
|
|
$this->assertInstanceOf(\DateTime::class, $order->getCreateTime()); |
|
90
|
|
|
$this->assertInstanceOf(\DateTime::class, $order->getUpdateTime()); |
|
91
|
|
|
$this->assertIsInt($order->getIsWorking()); |
|
92
|
|
|
$this->assertIsInt($order->getOrderCategory()); |
|
93
|
|
|
if (!is_null($order->getTriggerPrice())) { |
|
94
|
|
|
$this->assertIsFloat($order->getTriggerPrice()); |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
} |