1
|
|
|
<?php |
2
|
|
|
namespace Carpenstar\ByBitAPI\WebSockets\Channels\Spot\PublicChannels\Bookticker\Entities; |
3
|
|
|
|
4
|
|
|
use Carpenstar\ByBitAPI\Core\Helpers\DateTimeHelper; |
5
|
|
|
use Carpenstar\ByBitAPI\Core\Objects\AbstractResponse; |
6
|
|
|
|
7
|
|
|
class BooktickerAbstract extends AbstractResponse |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* Topic name |
11
|
|
|
* @var string |
12
|
|
|
*/ |
13
|
|
|
private string $topic; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* The timestamp (ms) that message is sent out |
17
|
|
|
* @var \DateTime $requestTimestamp |
18
|
|
|
*/ |
19
|
|
|
private \DateTime $requestTimestamp; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Data type. snapshot |
23
|
|
|
* @var string $type |
24
|
|
|
*/ |
25
|
|
|
private string $type; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Trading pair |
29
|
|
|
* @var string |
30
|
|
|
*/ |
31
|
|
|
private string $symbol; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Best bid price |
35
|
|
|
* @var float $bestBidPrice |
36
|
|
|
*/ |
37
|
|
|
private float $bestBidPrice; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Bid quantity |
41
|
|
|
* @var float $bidQuantity |
42
|
|
|
*/ |
43
|
|
|
private float $bidQuantity; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Best ask price |
47
|
|
|
* @var float $bestAskPrice |
48
|
|
|
*/ |
49
|
|
|
private float $bestAskPrice; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Ask quantity |
53
|
|
|
* @var float $askQuantity |
54
|
|
|
*/ |
55
|
|
|
private float $askQuantity; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @var \DateTime $responseTimestamp |
59
|
|
|
*/ |
60
|
|
|
private \DateTime $responseTimestamp; |
61
|
|
|
|
62
|
|
|
public function __construct(array $data) |
63
|
|
|
{ |
64
|
|
|
$this |
65
|
|
|
->setTopic($data['topic']) |
66
|
|
|
->setRequestTimestamp($data['ts']) |
67
|
|
|
->setType($data['type']) |
68
|
|
|
->setSymbol($data['data']['s']) |
69
|
|
|
->setBestAskPrice($data['data']['bp']) |
70
|
|
|
->setAskQuantity($data['data']['aq']) |
71
|
|
|
->setBestBidPrice($data['data']['bq']) |
72
|
|
|
->setBidQuantity($data['data']['bq']) |
73
|
|
|
->setResponseTimestamp($data['data']['t']); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @param string $responseTimestamp |
78
|
|
|
* @return BooktickerAbstract |
79
|
|
|
*/ |
80
|
|
|
public function setResponseTimestamp(string $responseTimestamp): self |
81
|
|
|
{ |
82
|
|
|
$this->responseTimestamp = DateTimeHelper::makeFromTimestamp($responseTimestamp); |
|
|
|
|
83
|
|
|
return $this; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @return \DateTime |
88
|
|
|
*/ |
89
|
|
|
public function getResponseTimestamp(): \DateTime |
90
|
|
|
{ |
91
|
|
|
return $this->responseTimestamp; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @param float $bestBidPrice |
96
|
|
|
* @return BooktickerAbstract |
97
|
|
|
*/ |
98
|
|
|
private function setBestBidPrice(float $bestBidPrice): self |
99
|
|
|
{ |
100
|
|
|
$this->bestBidPrice = $bestBidPrice; |
101
|
|
|
return $this; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @return float |
106
|
|
|
*/ |
107
|
|
|
public function getBestBidPrice(): float |
108
|
|
|
{ |
109
|
|
|
return $this->bestBidPrice; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @param float $bidQuantity |
114
|
|
|
* @return BooktickerAbstract |
115
|
|
|
*/ |
116
|
|
|
private function setBidQuantity(float $bidQuantity): self |
117
|
|
|
{ |
118
|
|
|
$this->bidQuantity = $bidQuantity; |
119
|
|
|
return $this; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @return float |
124
|
|
|
*/ |
125
|
|
|
public function getBidQuantity(): float |
126
|
|
|
{ |
127
|
|
|
return $this->bidQuantity; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @param float $bestAskPrice |
132
|
|
|
* @return BooktickerAbstract |
133
|
|
|
*/ |
134
|
|
|
private function setBestAskPrice(float $bestAskPrice): self |
135
|
|
|
{ |
136
|
|
|
$this->bestAskPrice = $bestAskPrice; |
137
|
|
|
return $this; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @return float |
142
|
|
|
*/ |
143
|
|
|
public function getBestAskPrice(): float |
144
|
|
|
{ |
145
|
|
|
return $this->bestAskPrice; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @param float $askQuantity |
150
|
|
|
* @return BooktickerAbstract |
151
|
|
|
*/ |
152
|
|
|
public function setAskQuantity(float $askQuantity): self |
153
|
|
|
{ |
154
|
|
|
$this->askQuantity = $askQuantity; |
155
|
|
|
return $this; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @return float |
160
|
|
|
*/ |
161
|
|
|
public function getAskQuantity(): float |
162
|
|
|
{ |
163
|
|
|
return $this->askQuantity; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* @param string $symbol |
168
|
|
|
* @return BooktickerAbstract |
169
|
|
|
*/ |
170
|
|
|
public function setSymbol(string $symbol): self |
171
|
|
|
{ |
172
|
|
|
$this->symbol = $symbol; |
173
|
|
|
return $this; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* @return string |
178
|
|
|
*/ |
179
|
|
|
public function getSymbol(): string |
180
|
|
|
{ |
181
|
|
|
return $this->symbol; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* @param string $topic |
186
|
|
|
* @return BooktickerAbstract |
187
|
|
|
*/ |
188
|
|
|
private function setTopic(string $topic): self |
189
|
|
|
{ |
190
|
|
|
$this->topic = $topic; |
191
|
|
|
return $this; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* @return string |
196
|
|
|
*/ |
197
|
|
|
public function getTopic(): string |
198
|
|
|
{ |
199
|
|
|
return $this->topic; |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* @param string $requestTimestamp |
204
|
|
|
* @return BooktickerAbstract |
205
|
|
|
*/ |
206
|
|
|
private function setRequestTimestamp(string $requestTimestamp): self |
207
|
|
|
{ |
208
|
|
|
$this->requestTimestamp = DateTimeHelper::makeFromTimestamp($requestTimestamp); |
|
|
|
|
209
|
|
|
return $this; |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
/** |
213
|
|
|
* @return \DateTime |
214
|
|
|
*/ |
215
|
|
|
public function getRequestTimestamp(): \DateTime |
216
|
|
|
{ |
217
|
|
|
return $this->requestTimestamp; |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
/** |
221
|
|
|
* @param string $type |
222
|
|
|
* @return BooktickerAbstract |
223
|
|
|
*/ |
224
|
|
|
private function setType(string $type): self |
225
|
|
|
{ |
226
|
|
|
$this->type = $type; |
227
|
|
|
return $this; |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* @return string |
232
|
|
|
*/ |
233
|
|
|
public function getType(): string |
234
|
|
|
{ |
235
|
|
|
return $this->type; |
236
|
|
|
} |
237
|
|
|
} |