InstrumentInfoResponseItem::__construct()   A
last analyzed

Complexity

Conditions 4
Paths 8

Size

Total Lines 42
Code Lines 32

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 32
c 1
b 0
f 0
nc 8
nop 1
dl 0
loc 42
rs 9.408
1
<?php
2
3
namespace Carpenstar\ByBitAPI\Derivatives\MarketData\InstrumentInfo\Response;
4
5
use Carpenstar\ByBitAPI\Core\Builders\ResponseDtoBuilder;
6
use Carpenstar\ByBitAPI\Core\Helpers\DateTimeHelper;
7
use Carpenstar\ByBitAPI\Core\Objects\Collection\EntityCollection;
8
use Carpenstar\ByBitAPI\Core\Objects\AbstractResponse;
9
use Carpenstar\ByBitAPI\Derivatives\MarketData\InstrumentInfo\Interfaces\IInstrumentInfoResponseItemInterface;
10
use DateTime;
11
12
class InstrumentInfoResponseItem extends AbstractResponse implements IInstrumentInfoResponseItemInterface
13
{
14
    /**
15
     * Derivatives products category. Keeps empty string `""` when `category` is not passed
16
     * @var string|null
17
     */
18
    private ?string $symbol;
19
20
    /**
21
     * Contract type. `LinearPerpetual`, `InversePerpetual`, `InverseFutures`
22
     * @var null|string $contractType
23
     */
24
    private ?string $contractType;
25
26
    /**
27
     * Symbol status
28
     * @var null|string $status
29
     */
30
    private ?string $status;
31
32
    /**
33
     * Base coin. e.g BTCUSDT, BTC is base coin
34
     * @var string|null $baseCoin
35
     */
36
    private ?string $baseCoin;
37
38
    /**
39
     * Quote coin. e.g BTCPERP, USDC is quote coin
40
     * @var string|null
41
     */
42
    private ?string $quoteCoin;
43
44
    /**
45
     * The launch timestamp (ms)
46
     * @var \DateTime|null
47
     */
48
    private \DateTime $launchTime;
49
50
    /**
51
     * The delivery timestamp (ms). "0" for perpetual
52
     * @var null|DateTime $deliveryTime
53
     */
54
    private ?\DateTime $deliveryTime;
55
56
    /**
57
     * The delivery fee rate
58
     * @var float
59
     */
60
    private float $deliveryFeeRate;
61
62
    /**
63
     * Price scale
64
     * @var float
65
     */
66
    private float $priceScale;
67
68
    /**
69
     * Support unified margin trade or not
70
     * @var bool
71
     */
72
    private bool $unifiedMarginTrade;
73
74
    /**
75
     * Funding interval (minute)
76
     * @var int
77
     */
78
    private int $fundingInterval;
79
80
    /**
81
     * Settle coin. e.g BTCUSD, BTC is settle coin
82
     * @var string|null
83
     */
84
    private ?string $settleCoin;
85
86
    /**
87
     * The cursor used to pagination
88
     * @var string|null
89
     */
90
    private ?string $nextPageCursor;
91
92
    /**
93
     * @var EntityCollection
94
     */
95
    private EntityCollection $leverageFilter;
96
97
    /**
98
     * @var EntityCollection $pricefilter
99
     */
100
    private EntityCollection $priceFilter;
101
102
    /**
103
     * @var EntityCollection $lotSizeFilter
104
     */
105
    private EntityCollection $lotSizeFilter;
106
107
    public function __construct(array $data)
108
    {
109
        $leverageFilterCollection = new EntityCollection();
110
        $priceFilterCollection = new EntityCollection();
111
        $lotSizeFilterCollection = new EntityCollection();
112
113
        $this->settleCoin = $data['settleCoin'];
114
        $this->fundingInterval = (int)$data['fundingInterval'];
115
        $this->unifiedMarginTrade = (bool)$data['unifiedMarginTrade'];
116
        $this->priceScale = $data['priceScale'] ?? 0.0;
117
        $this->deliveryFeeRate = (float)$data['deliveryFeeRate'];
118
        $this->deliveryTime = DateTimeHelper::makeFromTimestamp($data['deliveryTime']);
119
        $this->launchTime = DateTimeHelper::makeFromTimestamp($data['launchTime']);
120
        $this->quoteCoin = $data['quoteCoin'];
121
        $this->baseCoin = $data['baseCoin'];
122
        $this->symbol = $data['symbol'];
123
        $this->contractType = $data['contractType'] ?? null;
124
        $this->status = $data['status'];
125
        $this->nextPageCursor = $data['nextPageCursor'] ?? null;
126
127
        if (!empty($data['priceFilter'])) {
128
            array_map(function ($priceFilter) use ($priceFilterCollection) {
129
                $priceFilterCollection->push(ResponseDtoBuilder::make(PriceFilterResponseItem::class, $priceFilter));
130
            }, [$data['priceFilter']]);
131
        }
132
133
        if (!empty($data['leverageFilter'])) {
134
            array_map(function ($leverageFilterItem) use ($leverageFilterCollection) {
135
                $leverageFilterCollection->push(ResponseDtoBuilder::make(LeverageFilterResponseItem::class, $leverageFilterItem));
136
            }, [$data['leverageFilter']]);
137
        }
138
139
        if (!empty($data['lotSizeFilter'])) {
140
            array_map(function ($lotSizeFilterItem) use ($lotSizeFilterCollection) {
141
                $lotSizeFilterCollection->push(ResponseDtoBuilder::make(LotSizeFilterResponseItem::class, $lotSizeFilterItem));
142
            }, [$data['lotSizeFilter']]);
143
        }
144
145
        $this
146
            ->setLeverageFilter($leverageFilterCollection)
147
            ->setPriceFilter($priceFilterCollection)
148
            ->setLotSizeFilter($lotSizeFilterCollection);
149
    }
150
151
    /**
152
     * @return EntityCollection
153
     */
154
    public function getLotSizeFilter(): EntityCollection
155
    {
156
        return $this->lotSizeFilter;
157
    }
158
159
    /**
160
     * @param EntityCollection $lotSizeFilter
161
     * @return self
162
     */
163
    private function setLotSizeFilter(EntityCollection $lotSizeFilter): self
164
    {
165
        $this->lotSizeFilter = $lotSizeFilter;
166
        return $this;
167
    }
168
169
    /**
170
     * @return EntityCollection
171
     */
172
    public function getPriceFilter(): EntityCollection
173
    {
174
        return $this->priceFilter;
175
    }
176
177
    /**
178
     * @param EntityCollection $priceFilter
179
     * @return self
180
     */
181
    private function setPriceFilter(EntityCollection $priceFilter): self
182
    {
183
        $this->priceFilter = $priceFilter;
184
        return $this;
185
    }
186
187
    /**
188
     * @param EntityCollection $leverageFilter
189
     * @return self
190
     */
191
    private function setLeverageFilter(EntityCollection $leverageFilter): self
192
    {
193
        $this->leverageFilter = $leverageFilter;
194
        return $this;
195
    }
196
197
    /**
198
     * @return EntityCollection
199
     */
200
    public function getLeverageFilter(): EntityCollection
201
    {
202
        return $this->leverageFilter;
203
    }
204
205
    /**
206
     * @return string|null
207
     */
208
    public function getSettleCoin(): ?string
209
    {
210
        return $this->settleCoin;
211
    }
212
213
    /**
214
     * @return int
215
     */
216
    public function getFundingInterval(): int
217
    {
218
        return $this->fundingInterval;
219
    }
220
221
    /**
222
     * @return bool
223
     */
224
    public function getUnifiedMarginTrade(): bool
225
    {
226
        return $this->unifiedMarginTrade;
227
    }
228
229
    /**
230
     * @return float
231
     */
232
    public function getPriceScale(): float
233
    {
234
        return $this->priceScale;
235
    }
236
237
    /**
238
     * @return float
239
     */
240
    public function getDeliveryFeeRate(): float
241
    {
242
        return $this->deliveryFeeRate;
243
    }
244
245
    /**
246
     * @return DateTime|null
247
     */
248
    public function getDeliveryTime(): ?DateTime
249
    {
250
        return $this->deliveryTime;
251
    }
252
253
    /**
254
     * @return \DateTime|null
255
     */
256
    public function getLaunchTime(): ?\DateTime
257
    {
258
        return $this->launchTime;
259
    }
260
261
    /**
262
     * @return string|null
263
     */
264
    public function getQuoteCoin(): ?string
265
    {
266
        return $this->quoteCoin;
267
    }
268
269
    /**
270
     * @return string|null
271
     */
272
    public function getBaseCoin(): ?string
273
    {
274
        return $this->baseCoin;
275
    }
276
277
    /**
278
     * @return string|null
279
     */
280
    public function getSymbol(): ?string
281
    {
282
        return $this->symbol;
283
    }
284
285
    /**
286
     * @return string|null
287
     */
288
    public function getContractType(): ?string
289
    {
290
        return $this->contractType;
291
    }
292
293
    /**
294
     * @return string|null
295
     */
296
    public function getStatus(): ?string
297
    {
298
        return $this->status;
299
    }
300
301
    /**
302
     * @return string|null
303
     */
304
    public function getNextPageCursor(): ?string
305
    {
306
        return $this->nextPageCursor;
307
    }
308
}
309