1
|
|
|
<?php |
2
|
|
|
namespace Carpenstar\ByBitAPI\WebSockets\Channels\Derivatives\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 int $crossSequence; |
29
|
|
|
|
30
|
|
|
private ?ICollectionInterface $data; |
31
|
|
|
|
32
|
|
|
public function __construct(array $data) |
33
|
|
|
{ |
34
|
|
|
$this->data = new EntityCollection(); |
35
|
|
|
$this |
36
|
|
|
->setTopic($data['topic']) |
37
|
|
|
->setType($data['type']) |
38
|
|
|
->setData($data['data']) |
39
|
|
|
->setTimestamp($data['ts']) |
40
|
|
|
->setCrossSequence($data['cs']); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param string|null $topic |
45
|
|
|
* @return self |
46
|
|
|
*/ |
47
|
|
|
private function setTopic(?string $topic): self |
48
|
|
|
{ |
49
|
|
|
$this->topic = $topic; |
50
|
|
|
return $this; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @return string |
55
|
|
|
*/ |
56
|
|
|
public function getTopic(): ?string |
57
|
|
|
{ |
58
|
|
|
return $this->topic; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param string|null $type |
63
|
|
|
* @return self |
64
|
|
|
*/ |
65
|
|
|
private function setType(?string $type): self |
66
|
|
|
{ |
67
|
|
|
$this->type = $type; |
68
|
|
|
return $this; |
69
|
|
|
} |
70
|
|
|
/** |
71
|
|
|
* @return string |
72
|
|
|
*/ |
73
|
|
|
public function getType(): ?string |
74
|
|
|
{ |
75
|
|
|
return $this->type; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param string $timestamp |
80
|
|
|
* @return self |
81
|
|
|
*/ |
82
|
|
|
private function setTimestamp(string $timestamp): self |
83
|
|
|
{ |
84
|
|
|
$this->timestamp = DateTimeHelper::makeFromTimestamp($timestamp); |
|
|
|
|
85
|
|
|
return $this; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @return \DateTime |
90
|
|
|
*/ |
91
|
|
|
public function getTimestamp(): \DateTime |
92
|
|
|
{ |
93
|
|
|
return $this->timestamp; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @param int $crossSequence |
98
|
|
|
* @return self |
99
|
|
|
*/ |
100
|
|
|
private function setCrossSequence(int $crossSequence): self |
101
|
|
|
{ |
102
|
|
|
$this->crossSequence = $crossSequence; |
103
|
|
|
return $this; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @return int |
108
|
|
|
*/ |
109
|
|
|
public function getCrossSequence(): int |
110
|
|
|
{ |
111
|
|
|
return $this->crossSequence; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
private function setData(array $data): self |
115
|
|
|
{ |
116
|
|
|
if (!empty($data)) { |
117
|
|
|
$this->data->push(ResponseBuilder::make(TickersDataItemAbstract::class, $data)); |
|
|
|
|
118
|
|
|
} |
119
|
|
|
return $this; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
public function getData(): ICollectionInterface |
123
|
|
|
{ |
124
|
|
|
return $this->data; |
|
|
|
|
125
|
|
|
} |
126
|
|
|
} |