|
1
|
|
|
<?php |
|
2
|
|
|
namespace Carpenstar\ByBitAPI\WebSockets\Channels\Spot\PublicChannels\Tickers\Entities; |
|
3
|
|
|
|
|
4
|
|
|
use Carpenstar\ByBitAPI\Core\Helpers\DateTimeHelper; |
|
5
|
|
|
use Carpenstar\ByBitAPI\Core\Objects\AbstractResponse; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* https://bybit-exchange.github.io/docs/derivatives/ws-public/ticker |
|
9
|
|
|
*/ |
|
10
|
|
|
class TickersItemAbstract extends AbstractResponse |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* Trading pair |
|
14
|
|
|
* @var string $symbol |
|
15
|
|
|
*/ |
|
16
|
|
|
private string $symbol; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Timestamp (trading time in the match box) |
|
20
|
|
|
* @var null|\DateTime $timestamp |
|
21
|
|
|
*/ |
|
22
|
|
|
private ?\DateTime $timestamp; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Open price |
|
26
|
|
|
* @var float $openPrice |
|
27
|
|
|
*/ |
|
28
|
|
|
private float $openPrice; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* High price |
|
32
|
|
|
* @var float $highPrice |
|
33
|
|
|
*/ |
|
34
|
|
|
private float $highPrice; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Low price |
|
38
|
|
|
* @var float $lowPrice |
|
39
|
|
|
*/ |
|
40
|
|
|
private float $lowPrice; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Close price |
|
44
|
|
|
* @var float $closePrice |
|
45
|
|
|
*/ |
|
46
|
|
|
private float $closePrice; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Trading volume |
|
50
|
|
|
* @var float $tradingVolume |
|
51
|
|
|
*/ |
|
52
|
|
|
private float $tradingVolume; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Trading quote volume |
|
56
|
|
|
* @var float $tradinguoteVolume |
|
57
|
|
|
*/ |
|
58
|
|
|
private float $tradinqQuoteVolume; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Change |
|
62
|
|
|
* @var float $change |
|
63
|
|
|
*/ |
|
64
|
|
|
private float $change; |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* USD index price. It can be empty |
|
68
|
|
|
* @var null|string $usdIndexPrice |
|
69
|
|
|
*/ |
|
70
|
|
|
private ?string $usdIndexPrice; |
|
71
|
|
|
|
|
72
|
|
|
public function __construct(array $data) |
|
73
|
|
|
{ |
|
74
|
|
|
$this |
|
75
|
|
|
->setSymbol($data['s'] ?? null) |
|
76
|
|
|
->setTimestamp($data['t'] ?? null) |
|
77
|
|
|
->setOpenPrice($data['o'] ?? null) |
|
78
|
|
|
->setHighPrice($data['h'] ?? null) |
|
79
|
|
|
->setLowPrice($data['l'] ?? null) |
|
80
|
|
|
->setClosePrice($data['c'] ?? null) |
|
81
|
|
|
->setTradingVolume($data['v'] ?? null) |
|
82
|
|
|
->setTradingQuoteVolume($data['qv'] ?? null) |
|
83
|
|
|
->setChange($data['m'] ?? null) |
|
84
|
|
|
->setUsdIndexPrice($data['xp'] ?? null); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @param string|null $symbol |
|
89
|
|
|
* @return self |
|
90
|
|
|
*/ |
|
91
|
|
|
private function setSymbol(?string $symbol): self |
|
92
|
|
|
{ |
|
93
|
|
|
$this->symbol = $symbol; |
|
94
|
|
|
return $this; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @return string|null |
|
99
|
|
|
*/ |
|
100
|
|
|
public function getSymbol(): ?string |
|
101
|
|
|
{ |
|
102
|
|
|
return $this->symbol; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* @param float|null $openPrice |
|
107
|
|
|
* @return self |
|
108
|
|
|
*/ |
|
109
|
|
|
private function setOpenPrice(?float $openPrice): self |
|
110
|
|
|
{ |
|
111
|
|
|
$this->openPrice = $openPrice; |
|
112
|
|
|
return $this; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* @return string|null |
|
117
|
|
|
*/ |
|
118
|
|
|
public function getOpenPrice(): ?float |
|
119
|
|
|
{ |
|
120
|
|
|
return $this->openPrice; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* @param float|null $highPrice |
|
125
|
|
|
* @return self |
|
126
|
|
|
*/ |
|
127
|
|
|
private function setHighPrice(?float $highPrice): self |
|
128
|
|
|
{ |
|
129
|
|
|
$this->highPrice = $highPrice; |
|
130
|
|
|
return $this; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* @return float|null |
|
135
|
|
|
*/ |
|
136
|
|
|
public function getHighPrice(): ?float |
|
137
|
|
|
{ |
|
138
|
|
|
return $this->highPrice; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* @param float|null $lowPrice |
|
143
|
|
|
* @return self |
|
144
|
|
|
*/ |
|
145
|
|
|
private function setLowPrice(?float $lowPrice): self |
|
146
|
|
|
{ |
|
147
|
|
|
$this->lowPrice = $lowPrice; |
|
148
|
|
|
return $this; |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
/** |
|
152
|
|
|
* @return float|null |
|
153
|
|
|
*/ |
|
154
|
|
|
public function getLowPrice(): ?float |
|
155
|
|
|
{ |
|
156
|
|
|
return $this->lowPrice; |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
/** |
|
160
|
|
|
* @param float|null $closePrice |
|
161
|
|
|
* @return self |
|
162
|
|
|
*/ |
|
163
|
|
|
private function setClosePrice(?float $closePrice): self |
|
164
|
|
|
{ |
|
165
|
|
|
$this->closePrice = $closePrice; |
|
166
|
|
|
return $this; |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
/** |
|
170
|
|
|
* @return float|null |
|
171
|
|
|
*/ |
|
172
|
|
|
public function getClosePrice(): ?float |
|
173
|
|
|
{ |
|
174
|
|
|
return $this->closePrice; |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
/** |
|
178
|
|
|
* @param float|null $tradingVolume |
|
179
|
|
|
* @return self |
|
180
|
|
|
*/ |
|
181
|
|
|
private function setTradingVolume(?float $tradingVolume): self |
|
182
|
|
|
{ |
|
183
|
|
|
$this->tradingVolume = $tradingVolume; |
|
184
|
|
|
return $this; |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
/** |
|
188
|
|
|
* @return float|null |
|
189
|
|
|
*/ |
|
190
|
|
|
public function getTradingVolume(): ?float |
|
191
|
|
|
{ |
|
192
|
|
|
return $this->tradingVolume; |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
/** |
|
196
|
|
|
* @param float|null $tradingQuoteVolume |
|
197
|
|
|
* @return self |
|
198
|
|
|
*/ |
|
199
|
|
|
private function setTradingQuoteVolume(?float $tradingQuoteVolume): self |
|
200
|
|
|
{ |
|
201
|
|
|
$this->tradinqQuoteVolume = $tradingQuoteVolume; |
|
202
|
|
|
return $this; |
|
203
|
|
|
} |
|
204
|
|
|
|
|
205
|
|
|
/** |
|
206
|
|
|
* @return float|null |
|
207
|
|
|
*/ |
|
208
|
|
|
public function getTradingQuoteVolume(): ?float |
|
209
|
|
|
{ |
|
210
|
|
|
return $this->tradinqQuoteVolume; |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
|
|
/** |
|
214
|
|
|
* @param float|null $change |
|
215
|
|
|
* @return self |
|
216
|
|
|
*/ |
|
217
|
|
|
private function setChange(?float $change): self |
|
218
|
|
|
{ |
|
219
|
|
|
$this->change = $change; |
|
220
|
|
|
return $this; |
|
221
|
|
|
} |
|
222
|
|
|
|
|
223
|
|
|
/** |
|
224
|
|
|
* @return float|null |
|
225
|
|
|
*/ |
|
226
|
|
|
public function getChange(): ?float |
|
227
|
|
|
{ |
|
228
|
|
|
return $this->change; |
|
229
|
|
|
} |
|
230
|
|
|
|
|
231
|
|
|
/** |
|
232
|
|
|
* @param string|null $usdIndexPrice |
|
233
|
|
|
* @return self |
|
234
|
|
|
*/ |
|
235
|
|
|
private function setUsdIndexPrice(?string $usdIndexPrice): self |
|
236
|
|
|
{ |
|
237
|
|
|
$this->usdIndexPrice = $usdIndexPrice; |
|
238
|
|
|
return $this; |
|
239
|
|
|
} |
|
240
|
|
|
|
|
241
|
|
|
/** |
|
242
|
|
|
* @return float|null |
|
243
|
|
|
*/ |
|
244
|
|
|
public function getUsdIndexPrice(): ?string |
|
245
|
|
|
{ |
|
246
|
|
|
return $this->usdIndexPrice; |
|
|
|
|
|
|
247
|
|
|
} |
|
248
|
|
|
|
|
249
|
|
|
/** |
|
250
|
|
|
* @param string|null $nextFundingTime |
|
251
|
|
|
* @return self |
|
252
|
|
|
*/ |
|
253
|
|
|
private function setTimestamp(?string $timestamp): self |
|
254
|
|
|
{ |
|
255
|
|
|
if (!empty($timestamp)) { |
|
256
|
|
|
$this->timestamp = DateTimeHelper::makeFromTimestamp($timestamp); |
|
|
|
|
|
|
257
|
|
|
} |
|
258
|
|
|
return $this; |
|
259
|
|
|
} |
|
260
|
|
|
|
|
261
|
|
|
/** |
|
262
|
|
|
* @return \DateTime|null |
|
263
|
|
|
*/ |
|
264
|
|
|
public function getTimestamp(): ?\DateTime |
|
265
|
|
|
{ |
|
266
|
|
|
return $this->timestamp; |
|
267
|
|
|
} |
|
268
|
|
|
} |