1
|
|
|
<?php |
2
|
|
|
namespace Carpenstar\ByBitAPI\WebSockets\Channels\Spot\PublicChannels\Tickers\Entities; |
3
|
|
|
|
4
|
|
|
use Carpenstar\ByBitAPI\Core\Builders\ResponseBuilder; |
5
|
|
|
use Carpenstar\ByBitAPI\Core\Helpers\DateTimeHelper; |
6
|
|
|
use Carpenstar\ByBitAPI\Core\Interfaces\ICollectionInterface; |
7
|
|
|
use Carpenstar\ByBitAPI\Core\Objects\Collection\EntityCollection; |
8
|
|
|
use Carpenstar\ByBitAPI\Core\Objects\AbstractResponse; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* https://bybit-exchange.github.io/docs/derivatives/ws-public/ticker |
12
|
|
|
* Get latest information of the symbol |
13
|
|
|
* Future has snapshot and delta types. If a key does not exist in the field, it means the value is not changed. |
14
|
|
|
* Option has snapshot data only. |
15
|
|
|
* |
16
|
|
|
* Topic: tickers.{symbol} |
17
|
|
|
* |
18
|
|
|
* Push frequency: 100ms |
19
|
|
|
*/ |
20
|
|
|
class TickersAbstract extends AbstractResponse |
21
|
|
|
{ |
22
|
|
|
private ?string $topic; |
23
|
|
|
|
24
|
|
|
private ?string $type; |
25
|
|
|
|
26
|
|
|
private \DateTime $timestamp; |
27
|
|
|
|
28
|
|
|
private ?ICollectionInterface $data; |
29
|
|
|
|
30
|
|
|
public function __construct(array $data) |
31
|
|
|
{ |
32
|
|
|
$this->data = new EntityCollection(); |
33
|
|
|
$this |
34
|
|
|
->setTopic($data['topic']) |
35
|
|
|
->setType($data['type']) |
36
|
|
|
->setData($data['data']) |
37
|
|
|
->setTimestamp($data['ts']); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param string|null $topic |
42
|
|
|
* @return self |
43
|
|
|
*/ |
44
|
|
|
private function setTopic(?string $topic): self |
45
|
|
|
{ |
46
|
|
|
$this->topic = $topic; |
47
|
|
|
return $this; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @return string |
52
|
|
|
*/ |
53
|
|
|
public function getTopic(): ?string |
54
|
|
|
{ |
55
|
|
|
return $this->topic; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param string|null $type |
60
|
|
|
* @return self |
61
|
|
|
*/ |
62
|
|
|
private function setType(?string $type): self |
63
|
|
|
{ |
64
|
|
|
$this->type = $type; |
65
|
|
|
return $this; |
66
|
|
|
} |
67
|
|
|
/** |
68
|
|
|
* @return string |
69
|
|
|
*/ |
70
|
|
|
public function getType(): ?string |
71
|
|
|
{ |
72
|
|
|
return $this->type; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @param string $timestamp |
77
|
|
|
* @return self |
78
|
|
|
*/ |
79
|
|
|
private function setTimestamp(string $timestamp): self |
80
|
|
|
{ |
81
|
|
|
$this->timestamp = DateTimeHelper::makeFromTimestamp($timestamp); |
|
|
|
|
82
|
|
|
return $this; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @return \DateTime |
87
|
|
|
*/ |
88
|
|
|
public function getTimestamp(): \DateTime |
89
|
|
|
{ |
90
|
|
|
return $this->timestamp; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
private function setData(array $data): self |
94
|
|
|
{ |
95
|
|
|
if (!empty($data)) { |
96
|
|
|
$this->data->push(ResponseBuilder::make(TickersItemAbstract::class, $data)); |
|
|
|
|
97
|
|
|
} |
98
|
|
|
return $this; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function getData(): ICollectionInterface |
102
|
|
|
{ |
103
|
|
|
return $this->data; |
|
|
|
|
104
|
|
|
} |
105
|
|
|
} |