Passed
Push — master ( f32712...07732c )
by Vladislav
04:33 queued 01:39
created

MyPositionResponse   F

Complexity

Total Complexity 61

Size/Duplication

Total Lines 755
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 152
c 1
b 0
f 0
dl 0
loc 755
rs 3.52
wmc 61

61 Methods

Rating   Name   Duplication   Size   Complexity  
A getSessionAvgPrice() 0 3 1
A __construct() 0 33 1
A setRiskLimitValue() 0 4 1
A setSessionAvgPrice() 0 4 1
A setEntryPrice() 0 4 1
A getPositionIdx() 0 3 1
A setAutoAddMargin() 0 4 1
A getTradeMode() 0 3 1
A getBustPrice() 0 3 1
A setSide() 0 4 1
A getLeverage() 0 3 1
A getSymbol() 0 3 1
A setSize() 0 4 1
A setStopLoss() 0 4 1
A setLiqPrice() 0 4 1
A getPositionMM() 0 3 1
A setTpSlMode() 0 4 1
A getActivePrice() 0 3 1
A getStopLoss() 0 3 1
A getPositionValue() 0 3 1
A getTakeProfit() 0 3 1
A setTrailingStop() 0 4 1
A getMarkPrice() 0 3 1
A getCumRealisedPnl() 0 3 1
A setUnrealisedPnl() 0 4 1
A getRiskLimitValue() 0 3 1
A getAutoAddMargin() 0 3 1
A setCreatedTime() 0 4 1
A setOccClosingFee() 0 4 1
A getAdlRankIndicator() 0 3 1
A getPositionIM() 0 3 1
A setAdlRankIndicator() 0 4 1
A getPositionStatus() 0 3 1
A getLiqPrice() 0 3 1
A getRiskId() 0 3 1
A setSymbol() 0 4 1
A getUpdatedTime() 0 3 1
A getPositionBalance() 0 3 1
A setPositionMM() 0 4 1
A setActivePrice() 0 4 1
A getSize() 0 3 1
A setUpdatedTime() 0 4 1
A setCumRealisedPnl() 0 4 1
A getEntryPrice() 0 3 1
A setPositionIM() 0 4 1
A setTakeProfit() 0 4 1
A getTrailingStop() 0 3 1
A getTpSlMode() 0 3 1
A setPositionIdx() 0 4 1
A setBustPrice() 0 4 1
A setTradeMode() 0 4 1
A setRiskId() 0 4 1
A setPositionBalance() 0 4 1
A getCreatedTime() 0 3 1
A setMarkPrice() 0 4 1
A setPositionStatus() 0 4 1
A setLeverage() 0 4 1
A getOccClosingFee() 0 3 1
A getSide() 0 3 1
A getUnrealisedPnl() 0 3 1
A setPositionValue() 0 4 1

How to fix   Complexity   

Complex Class

Complex classes like MyPositionResponse often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use MyPositionResponse, and based on these observations, apply Extract Interface, too.

1
<?php
2
namespace Carpenstar\ByBitAPI\Derivatives\Contract\Position\MyPosition\Response;
3
4
use Carpenstar\ByBitAPI\Core\Helpers\DateTimeHelper;
5
use Carpenstar\ByBitAPI\Core\Objects\AbstractResponse;
6
use Carpenstar\ByBitAPI\Derivatives\Contract\Position\MyPosition\Interfaces\IMyPositionResponseInterface;
7
8
class MyPositionResponse extends AbstractResponse implements IMyPositionResponseInterface
9
{
10
    /**
11
     * Symbol name
12
     * @var string $symbol
13
     */
14
    private string $symbol;
15
16
    /**
17
     * Side. Buy, Sell. Return None when zero position of one-way mode
18
     * @var string $side
19
     */
20
    private string $side;
21
22
    /**
23
     * Position size
24
     * @var float $size
25
     */
26
    private float $size;
27
28
    /**
29
     * Entry price
30
     * @var float $entryPrice
31
     */
32
    private float $entryPrice;
33
34
    /**
35
     * leverage
36
     * @var float $leverage
37
     */
38
    private float $leverage;
39
40
    /**
41
     * Position value
42
     * @var float $positionValue
43
     */
44
    private float $positionValue;
45
46
    /**
47
     * Position index
48
     * @var int $positionIdx
49
     */
50
    private int $positionIdx;
51
52
    /**
53
     * Risk limit id
54
     * @var int $riskId
55
     */
56
    private int $riskId;
57
58
    /**
59
     * Position limit value corresponding to the risk id
60
     * @var string $riskLimitValue
61
     */
62
    private string $riskLimitValue;
63
64
    /**
65
     * 0: cross margin mode. 1: isolated margin mode
66
     * @var int $tradeMode
67
     */
68
    private int $tradeMode;
69
70
    /**
71
     * 0: false. 1: true
72
     * @var int $autoAddMargin
73
     */
74
    private int $autoAddMargin;
75
76
    /**
77
     * Position margin
78
     * @var float $positionBalance
79
     */
80
    private float $positionBalance;
81
82
    /**
83
     * Estimated liquidation price. It returns value only when minPrice < liqPrice < maxPrice
84
     * @var float $liqPrice
85
     */
86
    private float $liqPrice;
87
88
    /**
89
     * Estimated bankruptcy price
90
     * @var float $bustPrice
91
     */
92
    private float $bustPrice;
93
94
    /**
95
     * Depreciated, meaningless here, always "Full"
96
     * @var string $tpSlMode
97
     */
98
    private string $tpSlMode;
99
100
    /**
101
     * Take profit price
102
     * @var float $takeProfit
103
     */
104
    private float $takeProfit;
105
106
    /**
107
     * Stop loss price
108
     * @var float $stopLoss
109
     */
110
    private float $stopLoss;
111
112
    /**
113
     * Position created timestamp (ms)
114
     * @var \DateTime $createdTime
115
     */
116
    private \DateTime $createdTime;
117
118
    /**
119
     * Position data updated timestamp (ms)
120
     * @var \DateTime $updatedTime
121
     */
122
    private \DateTime $updatedTime;
123
124
    /**
125
     * Trailing stop
126
     * @var string $trailingStop
127
     */
128
    private string $trailingStop;
129
130
    /**
131
     * Activate price of trailing stop
132
     * @var float $activePrice
133
     */
134
    private float $activePrice;
135
136
    /**
137
     * Real-time mark price
138
     * @var float $markPrice
139
     */
140
    private float $markPrice;
141
142
    /**
143
     * unrealised PNL
144
     * @var float $unrealisedPnl
145
     */
146
    private float $unrealisedPnl;
147
148
    /**
149
     * cumulative realised PNL
150
     * @var float $cumRealisedPnl
151
     */
152
    private float $cumRealisedPnl;
153
154
    /**
155
     * Position maintenance margin
156
     * @var float $positionMM
157
     */
158
    private float $positionMM;
159
160
    /**
161
     * Position initial margin
162
     * @var float $positionIM
163
     */
164
    private float $positionIM;
165
166
    /**
167
     * Position status
168
     * @var string $positionStatus
169
     */
170
    private string $positionStatus;
171
172
    /**
173
     * Settlement price
174
     * @var float $sessionAvgPrice
175
     */
176
    private float $sessionAvgPrice;
177
178
    /**
179
     * Pre-occupancy closing fee
180
     * @var float $occClosingFee
181
     */
182
    private float $occClosingFee;
183
184
    /**
185
     * Auto-deleverage rank indicator. What is Auto-Deleveraging?
186
     * @var int $adlRankIndicator
187
     */
188
    private int $adlRankIndicator;
189
190
    public function __construct(array $data)
191
    {
192
        $this
193
            ->setSymbol($data['symbol'])
194
            ->setSide($data['side'])
195
            ->setSize($data['size'])
196
            ->setEntryPrice($data['entryPrice'])
197
            ->setLeverage($data['leverage'])
198
            ->setPositionValue($data['positionValue'])
199
            ->setPositionIdx((float) $data['positionIdx'])
0 ignored issues
show
Bug introduced by
(double)$data['positionIdx'] of type double is incompatible with the type integer expected by parameter $positionIdx of Carpenstar\ByBitAPI\Deri...ponse::setPositionIdx(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

199
            ->setPositionIdx(/** @scrutinizer ignore-type */ (float) $data['positionIdx'])
Loading history...
200
            ->setRiskId($data['riskId'])
201
            ->setRiskLimitValue((float) $data['riskLimitValue'])
202
            ->setTradeMode($data['tradeMode'])
203
            ->setAutoAddMargin($data['autoAddMargin'])
204
            ->setPositionBalance($data['positionBalance'])
205
            ->setLiqPrice((float) $data['liqPrice'])
206
            ->setBustPrice((float) $data['bustPrice'])
207
            ->setTpSlMode($data['tpSlMode'])
208
            ->setTakeProfit((float) $data['takeProfit'])
209
            ->setStopLoss((float) $data['stopLoss'])
210
            ->setCreatedTime($data['createdTime'])
211
            ->setUpdatedTime($data['updatedTime'])
212
            ->setTrailingStop($data['trailingStop'])
213
            ->setActivePrice((float) $data['activePrice'])
214
            ->setMarkPrice((float) $data['markPrice'])
215
            ->setUnrealisedPnl($data['unrealisedPnl'])
216
            ->setCumRealisedPnl($data['cumRealisedPnl'])
217
            ->setPositionMM((float) $data['positionMM'])
218
            ->setPositionIM((float) $data['positionIM'])
219
            ->setPositionStatus($data['positionStatus'])
220
            ->setSessionAvgPrice((float) $data['sessionAvgPrice'])
221
            ->setOccClosingFee((float) $data['occClosingFee'])
222
            ->setAdlRankIndicator($data['adlRankIndicator']);
223
    }
224
225
    /**
226
     * @return string
227
     */
228
    public function getSymbol(): string
229
    {
230
        return $this->symbol;
231
    }
232
233
    /**
234
     * @param string $symbol
235
     * @return MyPositionResponse
236
     */
237
    private function setSymbol(string $symbol): self
238
    {
239
        $this->symbol = $symbol;
240
        return $this;
241
    }
242
243
    /**
244
     * @return string
245
     */
246
    public function getSide(): string
247
    {
248
        return $this->side;
249
    }
250
251
    /**
252
     * @param string $side
253
     * @return MyPositionResponse
254
     */
255
    private function setSide(string $side): self
256
    {
257
        $this->side = $side;
258
        return $this;
259
    }
260
261
    /**
262
     * @return float
263
     */
264
    public function getSize(): float
265
    {
266
        return $this->size;
267
    }
268
269
    /**
270
     * @param float $size
271
     * @return MyPositionResponse
272
     */
273
    private function setSize(float $size): self
274
    {
275
        $this->size = $size;
276
        return $this;
277
    }
278
279
    /**
280
     * @return float
281
     */
282
    public function getEntryPrice(): float
283
    {
284
        return $this->entryPrice;
285
    }
286
287
    /**
288
     * @param float $entryPrice
289
     * @return MyPositionResponse
290
     */
291
    private function setEntryPrice(float $entryPrice): self
292
    {
293
        $this->entryPrice = $entryPrice;
294
        return $this;
295
    }
296
297
    /**
298
     * @return float
299
     */
300
    public function getLeverage(): float
301
    {
302
        return $this->leverage;
303
    }
304
305
    /**
306
     * @param float $leverage
307
     * @return MyPositionResponse
308
     */
309
    private function setLeverage(float $leverage): self
310
    {
311
        $this->leverage = $leverage;
312
        return $this;
313
    }
314
315
    /**
316
     * @return float
317
     */
318
    public function getPositionValue(): float
319
    {
320
        return $this->positionValue;
321
    }
322
323
    /**
324
     * @param float $positionValue
325
     * @return MyPositionResponse
326
     */
327
    private function setPositionValue(float $positionValue): self
328
    {
329
        $this->positionValue = $positionValue;
330
        return $this;
331
    }
332
333
    /**
334
     * @return int
335
     */
336
    public function getPositionIdx(): int
337
    {
338
        return $this->positionIdx;
339
    }
340
341
    /**
342
     * @param int $positionIdx
343
     * @return MyPositionResponse
344
     */
345
    private function setPositionIdx(int $positionIdx): self
346
    {
347
        $this->positionIdx = $positionIdx;
348
        return $this;
349
    }
350
351
    /**
352
     * @return int
353
     */
354
    public function getRiskId(): int
355
    {
356
        return $this->riskId;
357
    }
358
359
    /**
360
     * @param int $riskId
361
     * @return MyPositionResponse
362
     */
363
    private function setRiskId(int $riskId): self
364
    {
365
        $this->riskId = $riskId;
366
        return $this;
367
    }
368
369
    /**
370
     * @return string
371
     */
372
    public function getRiskLimitValue(): string
373
    {
374
        return $this->riskLimitValue;
375
    }
376
377
    /**
378
     * @param string $riskLimitValue
379
     * @return MyPositionResponse
380
     */
381
    private function setRiskLimitValue(string $riskLimitValue): self
382
    {
383
        $this->riskLimitValue = $riskLimitValue;
384
        return $this;
385
    }
386
387
    /**
388
     * @return int
389
     */
390
    public function getTradeMode(): int
391
    {
392
        return $this->tradeMode;
393
    }
394
395
    /**
396
     * @param int $tradeMode
397
     * @return MyPositionResponse
398
     */
399
    private function setTradeMode(int $tradeMode): self
400
    {
401
        $this->tradeMode = $tradeMode;
402
        return $this;
403
    }
404
405
    /**
406
     * @return int
407
     */
408
    public function getAutoAddMargin(): int
409
    {
410
        return $this->autoAddMargin;
411
    }
412
413
    /**
414
     * @param int $autoAddMargin
415
     * @return MyPositionResponse
416
     */
417
    private function setAutoAddMargin(int $autoAddMargin): self
418
    {
419
        $this->autoAddMargin = $autoAddMargin;
420
        return $this;
421
    }
422
423
    /**
424
     * @return float
425
     */
426
    public function getPositionBalance(): float
427
    {
428
        return $this->positionBalance;
429
    }
430
431
    /**
432
     * @param float $positionBalance
433
     * @return MyPositionResponse
434
     */
435
    private function setPositionBalance(float $positionBalance): self
436
    {
437
        $this->positionBalance = $positionBalance;
438
        return $this;
439
    }
440
441
    /**
442
     * @return float
443
     */
444
    public function getLiqPrice(): float
445
    {
446
        return $this->liqPrice;
447
    }
448
449
    /**
450
     * @param float $liqPrice
451
     * @return MyPositionResponse
452
     */
453
    private function setLiqPrice(float $liqPrice): self
454
    {
455
        $this->liqPrice = $liqPrice;
456
        return $this;
457
    }
458
459
    /**
460
     * @return float
461
     */
462
    public function getBustPrice(): float
463
    {
464
        return $this->bustPrice;
465
    }
466
467
    /**
468
     * @param float $bustPrice
469
     * @return MyPositionResponse
470
     */
471
    private function setBustPrice(float $bustPrice): self
472
    {
473
        $this->bustPrice = $bustPrice;
474
        return $this;
475
    }
476
477
    /**
478
     * @return string
479
     */
480
    public function getTpSlMode(): string
481
    {
482
        return $this->tpSlMode;
483
    }
484
485
    /**
486
     * @param string $tpSlMode
487
     * @return MyPositionResponse
488
     */
489
    private function setTpSlMode(string $tpSlMode): self
490
    {
491
        $this->tpSlMode = $tpSlMode;
492
        return $this;
493
    }
494
495
    /**
496
     * @return float
497
     */
498
    public function getTakeProfit(): float
499
    {
500
        return $this->takeProfit;
501
    }
502
503
    /**
504
     * @param float $takeProfit
505
     * @return MyPositionResponse
506
     */
507
    private function setTakeProfit(float $takeProfit): self
508
    {
509
        $this->takeProfit = $takeProfit;
510
        return $this;
511
    }
512
513
    /**
514
     * @return float
515
     */
516
    public function getStopLoss(): float
517
    {
518
        return $this->stopLoss;
519
    }
520
521
    /**
522
     * @param float $stopLoss
523
     * @return MyPositionResponse
524
     */
525
    private function setStopLoss(float $stopLoss): self
526
    {
527
        $this->stopLoss = $stopLoss;
528
        return $this;
529
    }
530
531
    /**
532
     * @return \DateTime
533
     */
534
    public function getCreatedTime(): \DateTime
535
    {
536
        return $this->createdTime;
537
    }
538
539
    /**
540
     * @param string $createdTime
541
     * @return MyPositionResponse
542
     */
543
    private function setCreatedTime(string $createdTime): self
544
    {
545
        $this->createdTime = DateTimeHelper::makeFromTimestamp($createdTime);
0 ignored issues
show
Bug introduced by
$createdTime of type string is incompatible with the type integer expected by parameter $timestamp of Carpenstar\ByBitAPI\Core...er::makeFromTimestamp(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

545
        $this->createdTime = DateTimeHelper::makeFromTimestamp(/** @scrutinizer ignore-type */ $createdTime);
Loading history...
546
        return $this;
547
    }
548
549
    /**
550
     * @return \DateTime
551
     */
552
    public function getUpdatedTime(): \DateTime
553
    {
554
        return $this->updatedTime;
555
    }
556
557
    /**
558
     * @param string $updatedTime
559
     * @return MyPositionResponse
560
     */
561
    private function setUpdatedTime(string $updatedTime): self
562
    {
563
        $this->updatedTime = DateTimeHelper::makeFromTimestamp($updatedTime);
0 ignored issues
show
Bug introduced by
$updatedTime of type string is incompatible with the type integer expected by parameter $timestamp of Carpenstar\ByBitAPI\Core...er::makeFromTimestamp(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

563
        $this->updatedTime = DateTimeHelper::makeFromTimestamp(/** @scrutinizer ignore-type */ $updatedTime);
Loading history...
564
        return $this;
565
    }
566
567
    /**
568
     * @return string
569
     */
570
    public function getTrailingStop(): string
571
    {
572
        return $this->trailingStop;
573
    }
574
575
    /**
576
     * @param string $trailingStop
577
     * @return MyPositionResponse
578
     */
579
    private function setTrailingStop(string $trailingStop): self
580
    {
581
        $this->trailingStop = $trailingStop;
582
        return $this;
583
    }
584
585
    /**
586
     * @return float
587
     */
588
    public function getActivePrice(): float
589
    {
590
        return $this->activePrice;
591
    }
592
593
    /**
594
     * @param float $activePrice
595
     * @return MyPositionResponse
596
     */
597
    private function setActivePrice(float $activePrice): self
598
    {
599
        $this->activePrice = $activePrice;
600
        return $this;
601
    }
602
603
    /**
604
     * @return float
605
     */
606
    public function getMarkPrice(): float
607
    {
608
        return $this->markPrice;
609
    }
610
611
    /**
612
     * @param float $markPrice
613
     * @return MyPositionResponse
614
     */
615
    private function setMarkPrice(float $markPrice): self
616
    {
617
        $this->markPrice = $markPrice;
618
        return $this;
619
    }
620
621
    /**
622
     * @return float
623
     */
624
    public function getUnrealisedPnl(): float
625
    {
626
        return $this->unrealisedPnl;
627
    }
628
629
    /**
630
     * @param float $unrealisedPnl
631
     * @return MyPositionResponse
632
     */
633
    private function setUnrealisedPnl(float $unrealisedPnl): self
634
    {
635
        $this->unrealisedPnl = $unrealisedPnl;
636
        return $this;
637
    }
638
639
    /**
640
     * @return float
641
     */
642
    public function getCumRealisedPnl(): float
643
    {
644
        return $this->cumRealisedPnl;
645
    }
646
647
    /**
648
     * @param float $cumRealisedPnl
649
     * @return MyPositionResponse
650
     */
651
    private function setCumRealisedPnl(float $cumRealisedPnl): self
652
    {
653
        $this->cumRealisedPnl = $cumRealisedPnl;
654
        return $this;
655
    }
656
657
    /**
658
     * @return float
659
     */
660
    public function getPositionMM(): float
661
    {
662
        return $this->positionMM;
663
    }
664
665
    /**
666
     * @param float $positionMM
667
     * @return MyPositionResponse
668
     */
669
    private function setPositionMM(float $positionMM): self
670
    {
671
        $this->positionMM = $positionMM;
672
        return $this;
673
    }
674
675
    /**
676
     * @return float
677
     */
678
    public function getPositionIM(): float
679
    {
680
        return $this->positionIM;
681
    }
682
683
    /**
684
     * @param float $positionIM
685
     * @return MyPositionResponse
686
     */
687
    private function setPositionIM(float $positionIM): self
688
    {
689
        $this->positionIM = $positionIM;
690
        return $this;
691
    }
692
693
    /**
694
     * @return string
695
     */
696
    public function getPositionStatus(): string
697
    {
698
        return $this->positionStatus;
699
    }
700
701
    /**
702
     * @param string $positionStatus
703
     * @return MyPositionResponse
704
     */
705
    private function setPositionStatus(string $positionStatus): self
706
    {
707
        $this->positionStatus = $positionStatus;
708
        return $this;
709
    }
710
711
    /**
712
     * @return float
713
     */
714
    public function getSessionAvgPrice(): float
715
    {
716
        return $this->sessionAvgPrice;
717
    }
718
719
    /**
720
     * @param float $sessionAvgPrice
721
     * @return MyPositionResponse
722
     */
723
    private function setSessionAvgPrice(float $sessionAvgPrice): self
724
    {
725
        $this->sessionAvgPrice = $sessionAvgPrice;
726
        return $this;
727
    }
728
729
    /**
730
     * @return float
731
     */
732
    public function getOccClosingFee(): float
733
    {
734
        return $this->occClosingFee;
735
    }
736
737
    /**
738
     * @param float $occClosingFee
739
     * @return MyPositionResponse
740
     */
741
    private function setOccClosingFee(float $occClosingFee): self
742
    {
743
        $this->occClosingFee = $occClosingFee;
744
        return $this;
745
    }
746
747
    /**
748
     * @return int
749
     */
750
    public function getAdlRankIndicator(): int
751
    {
752
        return $this->adlRankIndicator;
753
    }
754
755
    /**
756
     * @param int $adlRankIndicator
757
     * @return MyPositionResponse
758
     */
759
    private function setAdlRankIndicator(int $adlRankIndicator): self
760
    {
761
        $this->adlRankIndicator = $adlRankIndicator;
762
        return $this;
763
    }
764
765
766
}
767