Test Failed
Push — master ( f1d563...1fab6c )
by Vladislav
10:20 queued 07:53
created

InstrumentInfoResponseItem::__construct()   A

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
namespace Carpenstar\ByBitAPI\Derivatives\MarketData\InstrumentInfo\Response;
3
4
use Carpenstar\ByBitAPI\Core\Builders\ResponseDtoBuilder;
5
use Carpenstar\ByBitAPI\Core\Helpers\DateTimeHelper;
6
use Carpenstar\ByBitAPI\Core\Objects\Collection\EntityCollection;
7
use Carpenstar\ByBitAPI\Core\Objects\AbstractResponse;
8
use Carpenstar\ByBitAPI\Derivatives\MarketData\InstrumentInfo\Interfaces\IInstrumentInfoResponseItemInterface;
9
use DateTime;
10
11
class InstrumentInfoResponseItem extends AbstractResponse implements IInstrumentInfoResponseItemInterface
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
     * The cursor used to pagination
87
     * @var string|null
88
     */
89
    private ?string $nextPageCursor;
90
91
    /**
92
     * @var EntityCollection
93
     */
94
    private EntityCollection $leverageFilter;
95
96
    /**
97
     * @var EntityCollection $pricefilter
98
     */
99
    private EntityCollection $priceFilter;
100
101
    /**
102
     * @var EntityCollection $lotSizeFilter
103
     */
104
    private EntityCollection $lotSizeFilter;
105
106
    public function __construct(array $data)
107
    {
108
        $leverageFilterCollection = new EntityCollection();
109
        $priceFilterCollection = new EntityCollection();
110
        $lotSizeFilterCollection = new EntityCollection();
111
112
        $this->settleCoin = $data['settleCoin'];
113
        $this->fundingInterval = (int)$data['fundingInterval'];
114
        $this->unifiedMarginTrade = (bool)$data['unifiedMarginTrade'];
115
        $this->priceScale = $data['priceScale'] ?? 0.0;
116
        $this->deliveryFeeRate = (float)$data['deliveryFeeRate'];
117
        $this->deliveryTime = DateTimeHelper::makeFromTimestamp($data['deliveryTime']);
118
        $this->launchTime = DateTimeHelper::makeFromTimestamp($data['launchTime']);
119
        $this->quoteCoin = $data['quoteCoin'];
120
        $this->baseCoin = $data['baseCoin'];
121
        $this->symbol = $data['symbol'];
122
        $this->contractType = $data['contractType'] ?? null;
123
        $this->status = $data['status'];
124
        $this->nextPageCursor = $data['nextPageCursor'] ?? null;
125
126
        if (!empty($data['priceFilter'])) {
127
            array_map(function ($priceFilter) use ($priceFilterCollection) {
128
                $priceFilterCollection->push(ResponseDtoBuilder::make(PriceFilterResponseItem::class, $priceFilter));
129
            }, [$data['priceFilter']]);
130
        }
131
132
        if (!empty($data['leverageFilter'])) {
133
            array_map(function ($leverageFilterItem) use ($leverageFilterCollection) {
134
                $leverageFilterCollection->push(ResponseDtoBuilder::make(LeverageFilterResponseItem::class, $leverageFilterItem));
135
            }, [$data['leverageFilter']]);
136
        }
137
138
        if (!empty($data['lotSizeFilter'])) {
139
            array_map(function ($lotSizeFilterItem) use ($lotSizeFilterCollection) {
140
                $lotSizeFilterCollection->push(ResponseDtoBuilder::make(LotSizeFilterResponseItem::class, $lotSizeFilterItem));
141
            }, [$data['lotSizeFilter']]);
142
        }
143
144
        $this
145
            ->setLeverageFilter($leverageFilterCollection)
146
            ->setPriceFilter($priceFilterCollection)
147
            ->setLotSizeFilter($lotSizeFilterCollection);
148
    }
149
150
    /**
151
     * @return EntityCollection
152
     */
153
    public function getLotSizeFilter(): EntityCollection
154
    {
155
        return $this->lotSizeFilter;
156
    }
157
158
    /**
159
     * @param EntityCollection $lotSizeFilter
160
     * @return self
161
     */
162
    private function setLotSizeFilter(EntityCollection $lotSizeFilter): self
163
    {
164
        $this->lotSizeFilter = $lotSizeFilter;
165
        return $this;
166
    }
167
168
    /**
169
     * @return EntityCollection
170
     */
171
    public function getPriceFilter(): EntityCollection
172
    {
173
        return $this->priceFilter;
174
    }
175
176
    /**
177
     * @param EntityCollection $priceFilter
178
     * @return self
179
     */
180
    private function setPriceFilter(EntityCollection $priceFilter): self
181
    {
182
        $this->priceFilter = $priceFilter;
183
        return $this;
184
    }
185
186
    /**
187
     * @param EntityCollection $leverageFilter
188
     * @return self
189
     */
190
    private function setLeverageFilter(EntityCollection $leverageFilter): self
191
    {
192
        $this->leverageFilter = $leverageFilter;
193
        return $this;
194
    }
195
196
    /**
197
     * @return EntityCollection
198
     */
199
    public function getLeverageFilter(): EntityCollection
200
    {
201
        return $this->leverageFilter;
202
    }
203
204
    /**
205
     * @return string|null
206
     */
207
    public function getSettleCoin(): ?string
208
    {
209
        return $this->settleCoin;
210
    }
211
212
    /**
213
     * @return int
214
     */
215
    public function getFundingInterval(): int
216
    {
217
        return $this->fundingInterval;
218
    }
219
220
    /**
221
     * @return bool
222
     */
223
    public function getUnifiedMarginTrade(): bool
224
    {
225
        return $this->unifiedMarginTrade;
226
    }
227
228
    /**
229
     * @return float
230
     */
231
    public function getPriceScale(): float
232
    {
233
        return $this->priceScale;
234
    }
235
236
    /**
237
     * @return float
238
     */
239
    public function getDeliveryFeeRate(): float
240
    {
241
        return $this->deliveryFeeRate;
242
    }
243
244
    /**
245
     * @return DateTime|null
246
     */
247
    public function getDeliveryTime(): ?DateTime
248
    {
249
        return $this->deliveryTime;
250
    }
251
252
    /**
253
     * @return \DateTime|null
254
     */
255
    public function getLaunchTime(): ?\DateTime
256
    {
257
        return $this->launchTime;
258
    }
259
260
    /**
261
     * @return string|null
262
     */
263
    public function getQuoteCoin(): ?string
264
    {
265
        return $this->quoteCoin;
266
    }
267
268
    /**
269
     * @return string|null
270
     */
271
    public function getBaseCoin(): ?string
272
    {
273
        return $this->baseCoin;
274
    }
275
276
    /**
277
     * @return string|null
278
     */
279
    public function getSymbol(): ?string
280
    {
281
        return $this->symbol;
282
    }
283
284
    /**
285
     * @return string|null
286
     */
287
    public function getContractType(): ?string
288
    {
289
        return $this->contractType;
290
    }
291
292
    /**
293
     * @return string|null
294
     */
295
    public function getStatus(): ?string
296
    {
297
        return $this->status;
298
    }
299
300
    /**
301
     * @return string|null
302
     */
303
    public function getNextPageCursor(): ?string
304
    {
305
        return $this->nextPageCursor;
306
    }
307
}