1
|
|
|
<?php |
2
|
|
|
namespace Carpenstar\ByBitAPI\Derivatives\MarketData\InstrumentInfo\Response; |
3
|
|
|
|
4
|
|
|
use Carpenstar\ByBitAPI\Core\Builders\ResponseBuilder; |
5
|
|
|
use Carpenstar\ByBitAPI\Core\Helpers\DateTimeHelper; |
6
|
|
|
use Carpenstar\ByBitAPI\Core\Objects\Collection\EntityCollection; |
7
|
|
|
use Carpenstar\ByBitAPI\Core\Objects\ResponseEntity; |
8
|
|
|
use Carpenstar\ByBitAPI\Derivatives\MarketData\InstrumentInfo\Interfaces\IInstrumentInfoResponse; |
9
|
|
|
use DateTime; |
10
|
|
|
|
11
|
|
|
class InstrumentInfoResponse extends ResponseEntity implements IInstrumentInfoResponse |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* Derivatives products category. Keeps empty string `""` when `category` is not passed |
15
|
|
|
* @var string|null |
16
|
|
|
*/ |
17
|
|
|
private ?string $symbol; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Contract type. `LinearPerpetual`, `InversePerpetual`, `InverseFutures` |
21
|
|
|
* @var null|string $contractType |
22
|
|
|
*/ |
23
|
|
|
private ?string $contractType; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Symbol status |
27
|
|
|
* @var null|string $status |
28
|
|
|
*/ |
29
|
|
|
private ?string $status; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Base coin. e.g BTCUSDT, BTC is base coin |
33
|
|
|
* @var string|null $baseCoin |
34
|
|
|
*/ |
35
|
|
|
private ?string $baseCoin; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Quote coin. e.g BTCPERP, USDC is quote coin |
39
|
|
|
* @var string|null |
40
|
|
|
*/ |
41
|
|
|
private ?string $quoteCoin; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* The launch timestamp (ms) |
45
|
|
|
* @var \DateTime|null |
46
|
|
|
*/ |
47
|
|
|
private \DateTime $launchTime; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* The delivery timestamp (ms). "0" for perpetual |
51
|
|
|
* @var null|DateTime $deliveryTime |
52
|
|
|
*/ |
53
|
|
|
private ?\DateTime $deliveryTime; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* The delivery fee rate |
57
|
|
|
* @var float |
58
|
|
|
*/ |
59
|
|
|
private float $deliveryFeeRate; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Price scale |
63
|
|
|
* @var float |
64
|
|
|
*/ |
65
|
|
|
private float $priceScale; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Support unified margin trade or not |
69
|
|
|
* @var bool |
70
|
|
|
*/ |
71
|
|
|
private bool $unifiedMarginTrade; |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Funding interval (minute) |
75
|
|
|
* @var int |
76
|
|
|
*/ |
77
|
|
|
private int $fundingInterval; |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Settle coin. e.g BTCUSD, BTC is settle coin |
81
|
|
|
* @var string|null |
82
|
|
|
*/ |
83
|
|
|
private ?string $settleCoin; |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @var EntityCollection |
87
|
|
|
*/ |
88
|
|
|
private EntityCollection $leverageFilter; |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @var EntityCollection $pricefilter |
92
|
|
|
*/ |
93
|
|
|
private EntityCollection $priceFilter; |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @var EntityCollection $lotSizeFilter |
97
|
|
|
*/ |
98
|
|
|
private EntityCollection $lotSizeFilter; |
99
|
|
|
|
100
|
|
|
public function __construct(array $data) |
101
|
|
|
{ |
102
|
|
|
$leverageFilterCollection = new EntityCollection(); |
103
|
|
|
$priceFilterCollection = new EntityCollection(); |
104
|
|
|
$lotSizeFilterCollection = new EntityCollection(); |
105
|
|
|
|
106
|
|
|
if (!empty($data['priceFilter'])) { |
107
|
|
|
array_map(function ($priceFilter) use ($priceFilterCollection) { |
108
|
|
|
$priceFilterCollection->push(ResponseBuilder::make(PriceFilterItemResponse::class, $priceFilter)); |
109
|
|
|
}, [$data['priceFilter']]); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
if (!empty($data['leverageFilter'])) { |
113
|
|
|
array_map(function ($leverageFilterItem) use ($leverageFilterCollection) { |
114
|
|
|
$leverageFilterCollection->push(ResponseBuilder::make(LeverageFilterItemResponse::class, $leverageFilterItem)); |
115
|
|
|
}, [$data['leverageFilter']]); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
if (!empty($data['lotSizeFilter'])) { |
119
|
|
|
array_map(function ($lotSizeFilterItem) use ($lotSizeFilterCollection) { |
120
|
|
|
$lotSizeFilterCollection->push(ResponseBuilder::make(LotSizeFilterItemResponse::class, $lotSizeFilterItem)); |
121
|
|
|
}, [$data['lotSizeFilter']]); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
$this |
125
|
|
|
->setSymbol($data['symbol']) |
126
|
|
|
->setContractType($data['contractType'] ?? null) |
127
|
|
|
->setStatus($data['status']) |
128
|
|
|
->setBaseCoin($data['baseCoin']) |
129
|
|
|
->setQuoteCoin($data['quoteCoin']) |
130
|
|
|
->setLaunchTime($data['launchTime']) |
131
|
|
|
->setDeliveryTime($data['deliveryTime']) |
132
|
|
|
->setDeliveryFeeRate((float)$data['deliveryFeeRate']) |
133
|
|
|
->setPriceScale($data['priceScale'] ?? 0.0) |
134
|
|
|
->setUnifiedMarginTrade((bool)$data['unifiedMarginTrade']) |
135
|
|
|
->setFundingInterval((int)$data['fundingInterval']) |
136
|
|
|
->setSettleCoin($data['settleCoin']) |
137
|
|
|
->setLeverageFilter($leverageFilterCollection) |
138
|
|
|
->setPriceFilter($priceFilterCollection) |
139
|
|
|
->setLotSizeFilter($lotSizeFilterCollection); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @return EntityCollection |
144
|
|
|
*/ |
145
|
|
|
public function getLotSizeFilter(): EntityCollection |
146
|
|
|
{ |
147
|
|
|
return $this->lotSizeFilter; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @param EntityCollection $lotSizeFilter |
152
|
|
|
* @return InstrumentInfoResponse |
153
|
|
|
*/ |
154
|
|
|
private function setLotSizeFilter(EntityCollection $lotSizeFilter): self |
155
|
|
|
{ |
156
|
|
|
$this->lotSizeFilter = $lotSizeFilter; |
157
|
|
|
return $this; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @return EntityCollection |
162
|
|
|
*/ |
163
|
|
|
public function getPriceFilter(): EntityCollection |
164
|
|
|
{ |
165
|
|
|
return $this->priceFilter; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* @param EntityCollection $priceFilter |
170
|
|
|
* @return InstrumentInfoResponse |
171
|
|
|
*/ |
172
|
|
|
private function setPriceFilter(EntityCollection $priceFilter): self |
173
|
|
|
{ |
174
|
|
|
$this->priceFilter = $priceFilter; |
175
|
|
|
return $this; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* @param EntityCollection $leverageFilter |
180
|
|
|
* @return InstrumentInfoResponse |
181
|
|
|
*/ |
182
|
|
|
private function setLeverageFilter(EntityCollection $leverageFilter): self |
183
|
|
|
{ |
184
|
|
|
$this->leverageFilter = $leverageFilter; |
185
|
|
|
return $this; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* @return EntityCollection |
190
|
|
|
*/ |
191
|
|
|
public function getLeverageFilter(): EntityCollection |
192
|
|
|
{ |
193
|
|
|
return $this->leverageFilter; |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
/** |
197
|
|
|
* @param string|null $settleCoin |
198
|
|
|
* @return InstrumentInfoResponse |
199
|
|
|
*/ |
200
|
|
|
private function setSettleCoin(?string $settleCoin): self |
201
|
|
|
{ |
202
|
|
|
$this->settleCoin = $settleCoin; |
203
|
|
|
return $this; |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* @return string|null |
208
|
|
|
*/ |
209
|
|
|
public function getSettleCoin(): ?string |
210
|
|
|
{ |
211
|
|
|
return $this->settleCoin; |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* @param int $fundingInterval |
216
|
|
|
* @return InstrumentInfoResponse |
217
|
|
|
*/ |
218
|
|
|
private function setFundingInterval(int $fundingInterval): self |
219
|
|
|
{ |
220
|
|
|
$this->fundingInterval = $fundingInterval; |
221
|
|
|
return $this; |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
/** |
225
|
|
|
* @return int |
226
|
|
|
*/ |
227
|
|
|
public function getFundingInterval(): int |
228
|
|
|
{ |
229
|
|
|
return $this->fundingInterval; |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
/** |
233
|
|
|
* @return bool |
234
|
|
|
*/ |
235
|
|
|
public function getUnifiedMarginTrade(): bool |
236
|
|
|
{ |
237
|
|
|
return $this->unifiedMarginTrade; |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* @param bool $unifiedMarginTrade |
242
|
|
|
* @return InstrumentInfoResponse |
243
|
|
|
*/ |
244
|
|
|
private function setUnifiedMarginTrade(?bool $unifiedMarginTrade): self |
245
|
|
|
{ |
246
|
|
|
$this->unifiedMarginTrade = $unifiedMarginTrade; |
247
|
|
|
return $this; |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* @return float |
252
|
|
|
*/ |
253
|
|
|
public function getPriceScale(): float |
254
|
|
|
{ |
255
|
|
|
return $this->priceScale; |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
/** |
259
|
|
|
* @param float $priceScale |
260
|
|
|
* @return InstrumentInfoResponse |
261
|
|
|
*/ |
262
|
|
|
private function setPriceScale(?float $priceScale): self |
263
|
|
|
{ |
264
|
|
|
$this->priceScale = $priceScale; |
265
|
|
|
return $this; |
266
|
|
|
} |
267
|
|
|
|
268
|
|
|
/** |
269
|
|
|
* @return float |
270
|
|
|
*/ |
271
|
|
|
public function getDeliveryFeeRate(): float |
272
|
|
|
{ |
273
|
|
|
return $this->deliveryFeeRate; |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
/** |
277
|
|
|
* @param float $deliveryFeeRate |
278
|
|
|
* @return InstrumentInfoResponse |
279
|
|
|
*/ |
280
|
|
|
private function setDeliveryFeeRate(float $deliveryFeeRate): self |
281
|
|
|
{ |
282
|
|
|
$this->deliveryFeeRate = $deliveryFeeRate; |
283
|
|
|
return $this; |
284
|
|
|
} |
285
|
|
|
|
286
|
|
|
/** |
287
|
|
|
* The delivery timestamp (ms). "0" for perpetual |
288
|
|
|
* @param int $deliveryTime |
289
|
|
|
* @return InstrumentInfoResponse |
290
|
|
|
*/ |
291
|
|
|
private function setDeliveryTime(int $deliveryTime): self |
292
|
|
|
{ |
293
|
|
|
$this->deliveryTime = null; |
294
|
|
|
if ($deliveryTime > 0) { |
295
|
|
|
$this->deliveryTime = DateTimeHelper::makeFromTimestamp($deliveryTime); |
296
|
|
|
} |
297
|
|
|
return $this; |
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
/** |
301
|
|
|
* @return DateTime|null |
302
|
|
|
*/ |
303
|
|
|
public function getDeliveryTime(): ?DateTime |
304
|
|
|
{ |
305
|
|
|
return $this->deliveryTime; |
306
|
|
|
} |
307
|
|
|
|
308
|
|
|
/** |
309
|
|
|
* @param int $launchTime |
310
|
|
|
* @return InstrumentInfoResponse |
311
|
|
|
*/ |
312
|
|
|
private function setLaunchTime(int $launchTime): self |
313
|
|
|
{ |
314
|
|
|
$this->launchTime = DateTimeHelper::makeFromTimestamp($launchTime); |
315
|
|
|
return $this; |
316
|
|
|
} |
317
|
|
|
|
318
|
|
|
/** |
319
|
|
|
* @return \DateTime|null |
320
|
|
|
*/ |
321
|
|
|
public function getLaunchTime(): ?\DateTime |
322
|
|
|
{ |
323
|
|
|
return $this->launchTime; |
324
|
|
|
} |
325
|
|
|
|
326
|
|
|
/** |
327
|
|
|
* @return string|null |
328
|
|
|
*/ |
329
|
|
|
public function getQuoteCoin(): ?string |
330
|
|
|
{ |
331
|
|
|
return $this->quoteCoin; |
332
|
|
|
} |
333
|
|
|
|
334
|
|
|
/** |
335
|
|
|
* @param string|null $quoteCoin |
336
|
|
|
* @return InstrumentInfoResponse |
337
|
|
|
*/ |
338
|
|
|
private function setQuoteCoin(?string $quoteCoin): self |
339
|
|
|
{ |
340
|
|
|
$this->quoteCoin = $quoteCoin; |
341
|
|
|
return $this; |
342
|
|
|
} |
343
|
|
|
|
344
|
|
|
/** |
345
|
|
|
* @return string|null |
346
|
|
|
*/ |
347
|
|
|
public function getBaseCoin(): ?string |
348
|
|
|
{ |
349
|
|
|
return $this->baseCoin; |
350
|
|
|
} |
351
|
|
|
|
352
|
|
|
/** |
353
|
|
|
* @param string|null $baseCoin |
354
|
|
|
* @return InstrumentInfoResponse |
355
|
|
|
*/ |
356
|
|
|
private function setBaseCoin(?string $baseCoin): self |
357
|
|
|
{ |
358
|
|
|
$this->baseCoin = $baseCoin; |
359
|
|
|
return $this; |
360
|
|
|
} |
361
|
|
|
|
362
|
|
|
/** |
363
|
|
|
* @param string|null $symbol |
364
|
|
|
* @return InstrumentInfoResponse |
365
|
|
|
*/ |
366
|
|
|
private function setSymbol(?string $symbol): self |
367
|
|
|
{ |
368
|
|
|
$this->symbol = $symbol; |
369
|
|
|
return $this; |
370
|
|
|
} |
371
|
|
|
|
372
|
|
|
/** |
373
|
|
|
* @return string|null |
374
|
|
|
*/ |
375
|
|
|
public function getSymbol(): ?string |
376
|
|
|
{ |
377
|
|
|
return $this->symbol; |
378
|
|
|
} |
379
|
|
|
|
380
|
|
|
/** |
381
|
|
|
* Contract type. `LinearPerpetual`, `InversePerpetual`, `InverseFutures` |
382
|
|
|
* @param string|null $contractType |
383
|
|
|
* @return InstrumentInfoResponse |
384
|
|
|
*/ |
385
|
|
|
private function setContractType(?string $contractType): self |
386
|
|
|
{ |
387
|
|
|
$this->contractType = $contractType; |
388
|
|
|
return $this; |
389
|
|
|
} |
390
|
|
|
|
391
|
|
|
/** |
392
|
|
|
* @return string|null |
393
|
|
|
*/ |
394
|
|
|
public function getContractType(): ?string |
395
|
|
|
{ |
396
|
|
|
return $this->contractType; |
397
|
|
|
} |
398
|
|
|
|
399
|
|
|
/** |
400
|
|
|
* @param string|null $status |
401
|
|
|
* @return InstrumentInfoResponse |
402
|
|
|
*/ |
403
|
|
|
private function setStatus(?string $status): self |
404
|
|
|
{ |
405
|
|
|
$this->status = $status; |
406
|
|
|
return $this; |
407
|
|
|
} |
408
|
|
|
|
409
|
|
|
/** |
410
|
|
|
* @return string|null |
411
|
|
|
*/ |
412
|
|
|
public function getStatus(): ?string |
413
|
|
|
{ |
414
|
|
|
return $this->status; |
415
|
|
|
} |
416
|
|
|
} |