1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Carpenstar\ByBitAPI\WebSockets\Channels\Spot\PublicChannels\Kline\Entities; |
4
|
|
|
|
5
|
|
|
use Carpenstar\ByBitAPI\Core\Helpers\DateTimeHelper; |
6
|
|
|
use Carpenstar\ByBitAPI\Core\Objects\AbstractResponse; |
7
|
|
|
use Carpenstar\ByBitAPI\Core\Builders\ResponseDtoBuilder; |
8
|
|
|
use Carpenstar\ByBitAPI\Core\Objects\Collection\EntityCollection; |
9
|
|
|
use Carpenstar\ByBitAPI\WebSockets\Channels\Spot\PublicChannels\Bookticker\Entities\BoocktickerResponseItem; |
10
|
|
|
|
11
|
|
|
class KlineResponse extends AbstractResponse |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* Topic name |
15
|
|
|
* @var string $topic |
16
|
|
|
*/ |
17
|
|
|
private string $topic; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* The timestamp that message is sent out |
21
|
|
|
* @var \DateTime $requestTimestamp |
22
|
|
|
*/ |
23
|
|
|
private \DateTime $requestTimestamp; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Data type. snapshot |
27
|
|
|
* @var string $type |
28
|
|
|
*/ |
29
|
|
|
private string $type; |
30
|
|
|
private EntityCollection $data; |
31
|
|
|
|
32
|
|
|
|
33
|
|
|
public function __construct(array $data) |
34
|
|
|
{ |
35
|
|
|
$collection = new EntityCollection(); |
36
|
|
|
|
37
|
|
|
$this->requestTimestamp = DateTimeHelper::makeFromTimestamp($data['ts']); |
38
|
|
|
$this->topic = $data['topic']; |
39
|
|
|
$this->type = $data['type']; |
40
|
|
|
|
41
|
|
|
if (!empty($data['data'])) { |
42
|
|
|
|
43
|
|
|
$data['data'] = array_is_list($data['data']) ? $data['data'] : [$data['data']]; |
|
|
|
|
44
|
|
|
|
45
|
|
|
array_map(function ($item) use ($collection) { |
46
|
|
|
$collection->push(ResponseDtoBuilder::make(KlineResponseItem::class, $item)); |
47
|
|
|
}, $data['data']); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
$this->data = $collection; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function getTopic(): string |
54
|
|
|
{ |
55
|
|
|
return $this->topic; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function getRequestTimestamp(): \DateTime |
59
|
|
|
{ |
60
|
|
|
return $this->requestTimestamp; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function getType(): string |
64
|
|
|
{ |
65
|
|
|
return $this->type; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function getData(): array |
69
|
|
|
{ |
70
|
|
|
return $this->data->all(); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|