|
1
|
|
|
<?php |
|
2
|
|
|
namespace Carpenstar\ByBitAPI\Spot\MarketData\InstrumentInfo\Tests; |
|
3
|
|
|
|
|
4
|
|
|
use Carpenstar\ByBitAPI\Core\Builders\ResponseDtoBuilder; |
|
5
|
|
|
use Carpenstar\ByBitAPI\Core\Builders\ResponseHandlerBuilder; |
|
6
|
|
|
use Carpenstar\ByBitAPI\Core\Builders\RestBuilder; |
|
7
|
|
|
use Carpenstar\ByBitAPI\Core\Enums\EnumOutputMode; |
|
8
|
|
|
use Carpenstar\ByBitAPI\Core\Objects\Collection\EntityCollection; |
|
9
|
|
|
use Carpenstar\ByBitAPI\Core\Response\CurlResponseDto; |
|
10
|
|
|
use Carpenstar\ByBitAPI\Core\Response\CurlResponseHandler; |
|
11
|
|
|
use Carpenstar\ByBitAPI\Spot\MarketData\InstrumentInfo\Overrides\TestInstrumentInfo; |
|
12
|
|
|
use Carpenstar\ByBitAPI\Spot\MarketData\InstrumentInfo\Response\InstrumentInfoResponse; |
|
13
|
|
|
use PHPUnit\Framework\TestCase; |
|
14
|
|
|
|
|
15
|
|
|
class InstrumentInfoTest extends TestCase |
|
16
|
|
|
{ |
|
17
|
|
|
private static string $instrumentInfoApiResponse = '{"retCode":0,"retMsg":"OK","result":{"list":[{"name":"BTCUSDT","alias":"BTCUSDT","baseCoin":"BTC","quoteCoin":"USDT","basePrecision":"0.000001","quotePrecision":"0.00000001","minTradeQty":"0.00004","minTradeAmt":"1","maxTradeQty":"500","maxTradeAmt":"1200000","minPricePrecision":"0.01","category":"1","showStatus":"1","innovation":"0"},{"name":"ETHUSDT","alias":"ETHUSDT","baseCoin":"ETH","quoteCoin":"USDT","basePrecision":"0.00001","quotePrecision":"0.0000001","minTradeQty":"0.0005","minTradeAmt":"1","maxTradeQty":"100000000","maxTradeAmt":"1200000","minPricePrecision":"0.01","category":"1","showStatus":"1","innovation":"0"},{"name":"EOSUSDT","alias":"EOSUSDT","baseCoin":"EOS","quoteCoin":"USDT","basePrecision":"0.01","quotePrecision":"0.000001","minTradeQty":"0.01","minTradeAmt":"0.01","maxTradeQty":"90909.090909","maxTradeAmt":"10000","minPricePrecision":"0.0001","category":"1","showStatus":"1","innovation":"0"}]},"retExtInfo":{},"time":1683980087416}'; |
|
18
|
|
|
|
|
19
|
|
|
public function testInstrumentInfoDTOBuilder() |
|
20
|
|
|
{ |
|
21
|
|
|
foreach (json_decode(self::$instrumentInfoApiResponse, true)['result']['list'] as $dataItem) { |
|
22
|
|
|
$dto = ResponseDtoBuilder::make(InstrumentInfoResponse::class, $dataItem); |
|
23
|
|
|
$this->assertInstanceOf(InstrumentInfoResponse::class, $dto); |
|
24
|
|
|
$this->assertIsString($dto->getName()); |
|
25
|
|
|
$this->assertIsString($dto->getAlias()); |
|
26
|
|
|
$this->assertIsString($dto->getQuoteCoin()); |
|
27
|
|
|
$this->assertIsString($dto->getBaseCoin()); |
|
28
|
|
|
$this->assertIsFloat($dto->getBasePrecision()); |
|
29
|
|
|
$this->assertIsFloat($dto->getQuotePrecision()); |
|
30
|
|
|
$this->assertIsInt($dto->getInnovation()); |
|
31
|
|
|
$this->assertIsInt($dto->getMaxTradeAmt()); |
|
32
|
|
|
$this->assertIsFloat($dto->getMaxTradeQty()); |
|
33
|
|
|
$this->assertIsFloat($dto->getMinTradeAmt()); |
|
34
|
|
|
$this->assertIsFloat($dto->getMinTradeQty()); |
|
35
|
|
|
$this->assertIsFloat($dto->getMinPricePrecision()); |
|
36
|
|
|
$this->assertIsInt($dto->getCategory()); |
|
37
|
|
|
$this->assertIsInt($dto->getShowStatus()); |
|
38
|
|
|
$this->assertIsInt($dto->getInnovation()); |
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function testInstrumentInfoResponseHandlerBuilder() |
|
43
|
|
|
{ |
|
44
|
|
|
$handler = ResponseHandlerBuilder::make(self::$instrumentInfoApiResponse, CurlResponseHandler::class, InstrumentInfoResponse::class); |
|
45
|
|
|
$this->assertInstanceOf(EntityCollection::class, $handler->getBody()); |
|
46
|
|
|
$this->assertGreaterThan(0, $handler->getBody()->count()); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function testInstrumentInfoEndpoint() |
|
50
|
|
|
{ |
|
51
|
|
|
$endpoint = RestBuilder::make(TestInstrumentInfo::class); |
|
52
|
|
|
|
|
53
|
|
|
$entityResponse = $endpoint->execute(EnumOutputMode::MODE_ENTITY, self::$instrumentInfoApiResponse); |
|
54
|
|
|
$this->assertInstanceOf(CurlResponseDto::class, $entityResponse); |
|
55
|
|
|
$body = $entityResponse->getBody(); |
|
56
|
|
|
$this->assertInstanceOf(EntityCollection::class, $body); |
|
57
|
|
|
|
|
58
|
|
|
foreach ($body->fetch() as $dataItem) { |
|
59
|
|
|
$dto = ResponseDtoBuilder::make(InstrumentInfoResponse::class, $dataItem); |
|
60
|
|
|
$this->assertInstanceOf(InstrumentInfoResponse::class, $dto); |
|
61
|
|
|
$this->assertIsString($dto->getName()); |
|
62
|
|
|
$this->assertIsString($dto->getAlias()); |
|
63
|
|
|
$this->assertIsString($dto->getQuoteCoin()); |
|
64
|
|
|
$this->assertIsString($dto->getBaseCoin()); |
|
65
|
|
|
$this->assertIsFloat($dto->getBasePrecision()); |
|
66
|
|
|
$this->assertIsFloat($dto->getQuotePrecision()); |
|
67
|
|
|
$this->assertIsInt($dto->getInnovation()); |
|
68
|
|
|
$this->assertIsInt($dto->getMaxTradeAmt()); |
|
69
|
|
|
$this->assertIsFloat($dto->getMaxTradeQty()); |
|
70
|
|
|
$this->assertIsFloat($dto->getMinTradeAmt()); |
|
71
|
|
|
$this->assertIsFloat($dto->getMinTradeQty()); |
|
72
|
|
|
$this->assertIsFloat($dto->getMinPricePrecision()); |
|
73
|
|
|
$this->assertIsInt($dto->getCategory()); |
|
74
|
|
|
$this->assertIsInt($dto->getShowStatus()); |
|
75
|
|
|
$this->assertIsInt($dto->getInnovation()); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
} |