|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Carpenstar\ByBitAPI\WebSockets\Spot\PublicChannels\Tickers\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\Spot\PublicChannels\Tickers\Entities\TickersResponseItem; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* https://bybit-exchange.github.io/docs/derivatives/ws-public/ticker |
|
14
|
|
|
* Get latest information of the symbol |
|
15
|
|
|
* Future has snapshot and delta types. If a key does not exist in the field, it means the value is not changed. |
|
16
|
|
|
* Option has snapshot data only. |
|
17
|
|
|
* |
|
18
|
|
|
* Topic: tickers.{symbol} |
|
19
|
|
|
* |
|
20
|
|
|
* Push frequency: 100ms |
|
21
|
|
|
*/ |
|
22
|
|
|
class TickersResponse extends AbstractResponse |
|
23
|
|
|
{ |
|
24
|
|
|
private string $topic; |
|
25
|
|
|
|
|
26
|
|
|
private string $type; |
|
27
|
|
|
|
|
28
|
|
|
private \DateTime $timestamp; |
|
29
|
|
|
|
|
30
|
|
|
private EntityCollection $data; |
|
31
|
|
|
|
|
32
|
|
|
public function __construct(array $data) |
|
33
|
|
|
{ |
|
34
|
|
|
$collection = new EntityCollection(); |
|
35
|
|
|
|
|
36
|
|
|
$this->topic = $data['topic']; |
|
37
|
|
|
$this->type = $data['type']; |
|
38
|
|
|
$this->timestamp = DateTimeHelper::makeFromTimestamp($data['ts']); |
|
39
|
|
|
|
|
40
|
|
|
if (!empty($data['data'])) { |
|
41
|
|
|
$data['data'] = isset($data['data'][0]) ? $data['data'] : [$data['data']]; |
|
42
|
|
|
array_map(function ($item) use ($collection) { |
|
43
|
|
|
$collection->push(ResponseDtoBuilder::make(TickersResponseItem::class, $item)); |
|
44
|
|
|
}, $data['data']); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
$this->data = $collection; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @return string |
|
52
|
|
|
*/ |
|
53
|
|
|
public function getTopic(): string |
|
54
|
|
|
{ |
|
55
|
|
|
return $this->topic; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @return string |
|
60
|
|
|
*/ |
|
61
|
|
|
public function getType(): string |
|
62
|
|
|
{ |
|
63
|
|
|
return $this->type; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @return \DateTime |
|
68
|
|
|
*/ |
|
69
|
|
|
public function getTimestamp(): \DateTime |
|
70
|
|
|
{ |
|
71
|
|
|
return $this->timestamp; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function getData(): array |
|
75
|
|
|
{ |
|
76
|
|
|
return $this->data->all(); |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|