Total Complexity | 61 |
Total Lines | 755 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Complex classes like MyPositionResponseItem 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 MyPositionResponseItem, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
9 | class MyPositionResponseItem extends AbstractResponse implements IMyPositionResponseItemInterface |
||
10 | { |
||
11 | /** |
||
12 | * Symbol name |
||
13 | * @var string $symbol |
||
14 | */ |
||
15 | private string $symbol; |
||
16 | |||
17 | /** |
||
18 | * Side. Buy, Sell. Return None when zero position of one-way mode |
||
19 | * @var string $side |
||
20 | */ |
||
21 | private string $side; |
||
22 | |||
23 | /** |
||
24 | * Position size |
||
25 | * @var float $size |
||
26 | */ |
||
27 | private float $size; |
||
28 | |||
29 | /** |
||
30 | * Entry price |
||
31 | * @var float $entryPrice |
||
32 | */ |
||
33 | private float $entryPrice; |
||
34 | |||
35 | /** |
||
36 | * leverage |
||
37 | * @var float $leverage |
||
38 | */ |
||
39 | private float $leverage; |
||
40 | |||
41 | /** |
||
42 | * Position value |
||
43 | * @var float $positionValue |
||
44 | */ |
||
45 | private float $positionValue; |
||
46 | |||
47 | /** |
||
48 | * Position index |
||
49 | * @var int $positionIdx |
||
50 | */ |
||
51 | private int $positionIdx; |
||
52 | |||
53 | /** |
||
54 | * Risk limit id |
||
55 | * @var int $riskId |
||
56 | */ |
||
57 | private int $riskId; |
||
58 | |||
59 | /** |
||
60 | * Position limit value corresponding to the risk id |
||
61 | * @var string $riskLimitValue |
||
62 | */ |
||
63 | private string $riskLimitValue; |
||
64 | |||
65 | /** |
||
66 | * 0: cross margin mode. 1: isolated margin mode |
||
67 | * @var int $tradeMode |
||
68 | */ |
||
69 | private int $tradeMode; |
||
70 | |||
71 | /** |
||
72 | * 0: false. 1: true |
||
73 | * @var int $autoAddMargin |
||
74 | */ |
||
75 | private int $autoAddMargin; |
||
76 | |||
77 | /** |
||
78 | * Position margin |
||
79 | * @var float $positionBalance |
||
80 | */ |
||
81 | private float $positionBalance; |
||
82 | |||
83 | /** |
||
84 | * Estimated liquidation price. It returns value only when minPrice < liqPrice < maxPrice |
||
85 | * @var float $liqPrice |
||
86 | */ |
||
87 | private float $liqPrice; |
||
88 | |||
89 | /** |
||
90 | * Estimated bankruptcy price |
||
91 | * @var float $bustPrice |
||
92 | */ |
||
93 | private float $bustPrice; |
||
94 | |||
95 | /** |
||
96 | * Depreciated, meaningless here, always "Full" |
||
97 | * @var string $tpSlMode |
||
98 | */ |
||
99 | private string $tpSlMode; |
||
100 | |||
101 | /** |
||
102 | * Take profit price |
||
103 | * @var float $takeProfit |
||
104 | */ |
||
105 | private float $takeProfit; |
||
106 | |||
107 | /** |
||
108 | * Stop loss price |
||
109 | * @var float $stopLoss |
||
110 | */ |
||
111 | private float $stopLoss; |
||
112 | |||
113 | /** |
||
114 | * Position created timestamp (ms) |
||
115 | * @var \DateTime $createdTime |
||
116 | */ |
||
117 | private \DateTime $createdTime; |
||
118 | |||
119 | /** |
||
120 | * Position data updated timestamp (ms) |
||
121 | * @var \DateTime $updatedTime |
||
122 | */ |
||
123 | private \DateTime $updatedTime; |
||
124 | |||
125 | /** |
||
126 | * Trailing stop |
||
127 | * @var string $trailingStop |
||
128 | */ |
||
129 | private string $trailingStop; |
||
130 | |||
131 | /** |
||
132 | * Activate price of trailing stop |
||
133 | * @var float $activePrice |
||
134 | */ |
||
135 | private float $activePrice; |
||
136 | |||
137 | /** |
||
138 | * Real-time mark price |
||
139 | * @var float $markPrice |
||
140 | */ |
||
141 | private float $markPrice; |
||
142 | |||
143 | /** |
||
144 | * unrealised PNL |
||
145 | * @var float $unrealisedPnl |
||
146 | */ |
||
147 | private float $unrealisedPnl; |
||
148 | |||
149 | /** |
||
150 | * cumulative realised PNL |
||
151 | * @var float $cumRealisedPnl |
||
152 | */ |
||
153 | private float $cumRealisedPnl; |
||
154 | |||
155 | /** |
||
156 | * Position maintenance margin |
||
157 | * @var float $positionMM |
||
158 | */ |
||
159 | private float $positionMM; |
||
160 | |||
161 | /** |
||
162 | * Position initial margin |
||
163 | * @var float $positionIM |
||
164 | */ |
||
165 | private float $positionIM; |
||
166 | |||
167 | /** |
||
168 | * Position status |
||
169 | * @var string $positionStatus |
||
170 | */ |
||
171 | private string $positionStatus; |
||
172 | |||
173 | /** |
||
174 | * Settlement price |
||
175 | * @var float $sessionAvgPrice |
||
176 | */ |
||
177 | private float $sessionAvgPrice; |
||
178 | |||
179 | /** |
||
180 | * Pre-occupancy closing fee |
||
181 | * @var float $occClosingFee |
||
182 | */ |
||
183 | private float $occClosingFee; |
||
184 | |||
185 | /** |
||
186 | * Auto-deleverage rank indicator. What is Auto-Deleveraging? |
||
187 | * @var int $adlRankIndicator |
||
188 | */ |
||
189 | private int $adlRankIndicator; |
||
190 | |||
191 | public function __construct(array $data) |
||
192 | { |
||
193 | $this |
||
194 | ->setSymbol($data['symbol']) |
||
195 | ->setSide($data['side']) |
||
196 | ->setSize($data['size']) |
||
197 | ->setEntryPrice($data['entryPrice']) |
||
198 | ->setLeverage($data['leverage']) |
||
199 | ->setPositionValue($data['positionValue']) |
||
200 | ->setPositionIdx((float) $data['positionIdx']) |
||
|
|||
201 | ->setRiskId($data['riskId']) |
||
202 | ->setRiskLimitValue((float) $data['riskLimitValue']) |
||
203 | ->setTradeMode($data['tradeMode']) |
||
204 | ->setAutoAddMargin($data['autoAddMargin']) |
||
205 | ->setPositionBalance($data['positionBalance']) |
||
206 | ->setLiqPrice((float) $data['liqPrice']) |
||
207 | ->setBustPrice((float) $data['bustPrice']) |
||
208 | ->setTpSlMode($data['tpSlMode']) |
||
209 | ->setTakeProfit((float) $data['takeProfit']) |
||
210 | ->setStopLoss((float) $data['stopLoss']) |
||
211 | ->setCreatedTime($data['createdTime']) |
||
212 | ->setUpdatedTime($data['updatedTime']) |
||
213 | ->setTrailingStop($data['trailingStop']) |
||
214 | ->setActivePrice((float) $data['activePrice']) |
||
215 | ->setMarkPrice((float) $data['markPrice']) |
||
216 | ->setUnrealisedPnl($data['unrealisedPnl']) |
||
217 | ->setCumRealisedPnl($data['cumRealisedPnl']) |
||
218 | ->setPositionMM((float) $data['positionMM']) |
||
219 | ->setPositionIM((float) $data['positionIM']) |
||
220 | ->setPositionStatus($data['positionStatus']) |
||
221 | ->setSessionAvgPrice((float) $data['sessionAvgPrice']) |
||
222 | ->setOccClosingFee((float) $data['occClosingFee']) |
||
223 | ->setAdlRankIndicator($data['adlRankIndicator']); |
||
224 | } |
||
225 | |||
226 | /** |
||
227 | * @return string |
||
228 | */ |
||
229 | public function getSymbol(): string |
||
230 | { |
||
231 | return $this->symbol; |
||
232 | } |
||
233 | |||
234 | /** |
||
235 | * @param string $symbol |
||
236 | * @return MyPositionResponse |
||
237 | */ |
||
238 | private function setSymbol(string $symbol): self |
||
239 | { |
||
240 | $this->symbol = $symbol; |
||
241 | return $this; |
||
242 | } |
||
243 | |||
244 | /** |
||
245 | * @return string |
||
246 | */ |
||
247 | public function getSide(): string |
||
248 | { |
||
249 | return $this->side; |
||
250 | } |
||
251 | |||
252 | /** |
||
253 | * @param string $side |
||
254 | * @return MyPositionResponse |
||
255 | */ |
||
256 | private function setSide(string $side): self |
||
257 | { |
||
258 | $this->side = $side; |
||
259 | return $this; |
||
260 | } |
||
261 | |||
262 | /** |
||
263 | * @return float |
||
264 | */ |
||
265 | public function getSize(): float |
||
268 | } |
||
269 | |||
270 | /** |
||
271 | * @param float $size |
||
272 | * @return MyPositionResponse |
||
273 | */ |
||
274 | private function setSize(float $size): self |
||
275 | { |
||
276 | $this->size = $size; |
||
277 | return $this; |
||
278 | } |
||
279 | |||
280 | /** |
||
281 | * @return float |
||
282 | */ |
||
283 | public function getEntryPrice(): float |
||
284 | { |
||
285 | return $this->entryPrice; |
||
286 | } |
||
287 | |||
288 | /** |
||
289 | * @param float $entryPrice |
||
290 | * @return MyPositionResponse |
||
291 | */ |
||
292 | private function setEntryPrice(float $entryPrice): self |
||
293 | { |
||
294 | $this->entryPrice = $entryPrice; |
||
295 | return $this; |
||
296 | } |
||
297 | |||
298 | /** |
||
299 | * @return float |
||
300 | */ |
||
301 | public function getLeverage(): float |
||
302 | { |
||
303 | return $this->leverage; |
||
304 | } |
||
305 | |||
306 | /** |
||
307 | * @param float $leverage |
||
308 | * @return MyPositionResponse |
||
309 | */ |
||
310 | private function setLeverage(float $leverage): self |
||
311 | { |
||
312 | $this->leverage = $leverage; |
||
313 | return $this; |
||
314 | } |
||
315 | |||
316 | /** |
||
317 | * @return float |
||
318 | */ |
||
319 | public function getPositionValue(): float |
||
320 | { |
||
321 | return $this->positionValue; |
||
322 | } |
||
323 | |||
324 | /** |
||
325 | * @param float $positionValue |
||
326 | * @return MyPositionResponse |
||
327 | */ |
||
328 | private function setPositionValue(float $positionValue): self |
||
329 | { |
||
330 | $this->positionValue = $positionValue; |
||
331 | return $this; |
||
332 | } |
||
333 | |||
334 | /** |
||
335 | * @return int |
||
336 | */ |
||
337 | public function getPositionIdx(): int |
||
338 | { |
||
339 | return $this->positionIdx; |
||
340 | } |
||
341 | |||
342 | /** |
||
343 | * @param int $positionIdx |
||
344 | * @return MyPositionResponse |
||
345 | */ |
||
346 | private function setPositionIdx(int $positionIdx): self |
||
347 | { |
||
348 | $this->positionIdx = $positionIdx; |
||
349 | return $this; |
||
350 | } |
||
351 | |||
352 | /** |
||
353 | * @return int |
||
354 | */ |
||
355 | public function getRiskId(): int |
||
356 | { |
||
357 | return $this->riskId; |
||
358 | } |
||
359 | |||
360 | /** |
||
361 | * @param int $riskId |
||
362 | * @return MyPositionResponse |
||
363 | */ |
||
364 | private function setRiskId(int $riskId): self |
||
365 | { |
||
366 | $this->riskId = $riskId; |
||
367 | return $this; |
||
368 | } |
||
369 | |||
370 | /** |
||
371 | * @return string |
||
372 | */ |
||
373 | public function getRiskLimitValue(): string |
||
374 | { |
||
375 | return $this->riskLimitValue; |
||
376 | } |
||
377 | |||
378 | /** |
||
379 | * @param string $riskLimitValue |
||
380 | * @return MyPositionResponse |
||
381 | */ |
||
382 | private function setRiskLimitValue(string $riskLimitValue): self |
||
383 | { |
||
384 | $this->riskLimitValue = $riskLimitValue; |
||
385 | return $this; |
||
386 | } |
||
387 | |||
388 | /** |
||
389 | * @return int |
||
390 | */ |
||
391 | public function getTradeMode(): int |
||
392 | { |
||
393 | return $this->tradeMode; |
||
394 | } |
||
395 | |||
396 | /** |
||
397 | * @param int $tradeMode |
||
398 | * @return MyPositionResponse |
||
399 | */ |
||
400 | private function setTradeMode(int $tradeMode): self |
||
401 | { |
||
402 | $this->tradeMode = $tradeMode; |
||
403 | return $this; |
||
404 | } |
||
405 | |||
406 | /** |
||
407 | * @return int |
||
408 | */ |
||
409 | public function getAutoAddMargin(): int |
||
410 | { |
||
411 | return $this->autoAddMargin; |
||
412 | } |
||
413 | |||
414 | /** |
||
415 | * @param int $autoAddMargin |
||
416 | * @return MyPositionResponse |
||
417 | */ |
||
418 | private function setAutoAddMargin(int $autoAddMargin): self |
||
419 | { |
||
420 | $this->autoAddMargin = $autoAddMargin; |
||
421 | return $this; |
||
422 | } |
||
423 | |||
424 | /** |
||
425 | * @return float |
||
426 | */ |
||
427 | public function getPositionBalance(): float |
||
428 | { |
||
429 | return $this->positionBalance; |
||
430 | } |
||
431 | |||
432 | /** |
||
433 | * @param float $positionBalance |
||
434 | * @return MyPositionResponse |
||
435 | */ |
||
436 | private function setPositionBalance(float $positionBalance): self |
||
437 | { |
||
438 | $this->positionBalance = $positionBalance; |
||
439 | return $this; |
||
440 | } |
||
441 | |||
442 | /** |
||
443 | * @return float |
||
444 | */ |
||
445 | public function getLiqPrice(): float |
||
446 | { |
||
447 | return $this->liqPrice; |
||
448 | } |
||
449 | |||
450 | /** |
||
451 | * @param float $liqPrice |
||
452 | * @return MyPositionResponse |
||
453 | */ |
||
454 | private function setLiqPrice(float $liqPrice): self |
||
455 | { |
||
456 | $this->liqPrice = $liqPrice; |
||
457 | return $this; |
||
458 | } |
||
459 | |||
460 | /** |
||
461 | * @return float |
||
462 | */ |
||
463 | public function getBustPrice(): float |
||
464 | { |
||
465 | return $this->bustPrice; |
||
466 | } |
||
467 | |||
468 | /** |
||
469 | * @param float $bustPrice |
||
470 | * @return MyPositionResponse |
||
471 | */ |
||
472 | private function setBustPrice(float $bustPrice): self |
||
473 | { |
||
474 | $this->bustPrice = $bustPrice; |
||
475 | return $this; |
||
476 | } |
||
477 | |||
478 | /** |
||
479 | * @return string |
||
480 | */ |
||
481 | public function getTpSlMode(): string |
||
482 | { |
||
483 | return $this->tpSlMode; |
||
484 | } |
||
485 | |||
486 | /** |
||
487 | * @param string $tpSlMode |
||
488 | * @return MyPositionResponse |
||
489 | */ |
||
490 | private function setTpSlMode(string $tpSlMode): self |
||
491 | { |
||
492 | $this->tpSlMode = $tpSlMode; |
||
493 | return $this; |
||
494 | } |
||
495 | |||
496 | /** |
||
497 | * @return float |
||
498 | */ |
||
499 | public function getTakeProfit(): float |
||
500 | { |
||
501 | return $this->takeProfit; |
||
502 | } |
||
503 | |||
504 | /** |
||
505 | * @param float $takeProfit |
||
506 | * @return MyPositionResponse |
||
507 | */ |
||
508 | private function setTakeProfit(float $takeProfit): self |
||
509 | { |
||
510 | $this->takeProfit = $takeProfit; |
||
511 | return $this; |
||
512 | } |
||
513 | |||
514 | /** |
||
515 | * @return float |
||
516 | */ |
||
517 | public function getStopLoss(): float |
||
518 | { |
||
519 | return $this->stopLoss; |
||
520 | } |
||
521 | |||
522 | /** |
||
523 | * @param float $stopLoss |
||
524 | * @return MyPositionResponse |
||
525 | */ |
||
526 | private function setStopLoss(float $stopLoss): self |
||
527 | { |
||
528 | $this->stopLoss = $stopLoss; |
||
529 | return $this; |
||
530 | } |
||
531 | |||
532 | /** |
||
533 | * @return \DateTime |
||
534 | */ |
||
535 | public function getCreatedTime(): \DateTime |
||
536 | { |
||
537 | return $this->createdTime; |
||
538 | } |
||
539 | |||
540 | /** |
||
541 | * @param string $createdTime |
||
542 | * @return MyPositionResponse |
||
543 | */ |
||
544 | private function setCreatedTime(string $createdTime): self |
||
545 | { |
||
546 | $this->createdTime = DateTimeHelper::makeFromTimestamp($createdTime); |
||
547 | return $this; |
||
548 | } |
||
549 | |||
550 | /** |
||
551 | * @return \DateTime |
||
552 | */ |
||
553 | public function getUpdatedTime(): \DateTime |
||
554 | { |
||
555 | return $this->updatedTime; |
||
556 | } |
||
557 | |||
558 | /** |
||
559 | * @param string $updatedTime |
||
560 | * @return MyPositionResponse |
||
561 | */ |
||
562 | private function setUpdatedTime(string $updatedTime): self |
||
563 | { |
||
564 | $this->updatedTime = DateTimeHelper::makeFromTimestamp($updatedTime); |
||
565 | return $this; |
||
566 | } |
||
567 | |||
568 | /** |
||
569 | * @return string |
||
570 | */ |
||
571 | public function getTrailingStop(): string |
||
574 | } |
||
575 | |||
576 | /** |
||
577 | * @param string $trailingStop |
||
578 | * @return MyPositionResponse |
||
579 | */ |
||
580 | private function setTrailingStop(string $trailingStop): self |
||
581 | { |
||
582 | $this->trailingStop = $trailingStop; |
||
583 | return $this; |
||
584 | } |
||
585 | |||
586 | /** |
||
587 | * @return float |
||
588 | */ |
||
589 | public function getActivePrice(): float |
||
590 | { |
||
591 | return $this->activePrice; |
||
592 | } |
||
593 | |||
594 | /** |
||
595 | * @param float $activePrice |
||
596 | * @return MyPositionResponse |
||
597 | */ |
||
598 | private function setActivePrice(float $activePrice): self |
||
599 | { |
||
600 | $this->activePrice = $activePrice; |
||
601 | return $this; |
||
602 | } |
||
603 | |||
604 | /** |
||
605 | * @return float |
||
606 | */ |
||
607 | public function getMarkPrice(): float |
||
608 | { |
||
609 | return $this->markPrice; |
||
610 | } |
||
611 | |||
612 | /** |
||
613 | * @param float $markPrice |
||
614 | * @return MyPositionResponse |
||
615 | */ |
||
616 | private function setMarkPrice(float $markPrice): self |
||
617 | { |
||
618 | $this->markPrice = $markPrice; |
||
619 | return $this; |
||
620 | } |
||
621 | |||
622 | /** |
||
623 | * @return float |
||
624 | */ |
||
625 | public function getUnrealisedPnl(): float |
||
626 | { |
||
627 | return $this->unrealisedPnl; |
||
628 | } |
||
629 | |||
630 | /** |
||
631 | * @param float $unrealisedPnl |
||
632 | * @return MyPositionResponse |
||
633 | */ |
||
634 | private function setUnrealisedPnl(float $unrealisedPnl): self |
||
635 | { |
||
636 | $this->unrealisedPnl = $unrealisedPnl; |
||
637 | return $this; |
||
638 | } |
||
639 | |||
640 | /** |
||
641 | * @return float |
||
642 | */ |
||
643 | public function getCumRealisedPnl(): float |
||
644 | { |
||
645 | return $this->cumRealisedPnl; |
||
646 | } |
||
647 | |||
648 | /** |
||
649 | * @param float $cumRealisedPnl |
||
650 | * @return MyPositionResponse |
||
651 | */ |
||
652 | private function setCumRealisedPnl(float $cumRealisedPnl): self |
||
653 | { |
||
654 | $this->cumRealisedPnl = $cumRealisedPnl; |
||
655 | return $this; |
||
656 | } |
||
657 | |||
658 | /** |
||
659 | * @return float |
||
660 | */ |
||
661 | public function getPositionMM(): float |
||
662 | { |
||
663 | return $this->positionMM; |
||
664 | } |
||
665 | |||
666 | /** |
||
667 | * @param float $positionMM |
||
668 | * @return MyPositionResponse |
||
669 | */ |
||
670 | private function setPositionMM(float $positionMM): self |
||
671 | { |
||
672 | $this->positionMM = $positionMM; |
||
673 | return $this; |
||
674 | } |
||
675 | |||
676 | /** |
||
677 | * @return float |
||
678 | */ |
||
679 | public function getPositionIM(): float |
||
680 | { |
||
681 | return $this->positionIM; |
||
682 | } |
||
683 | |||
684 | /** |
||
685 | * @param float $positionIM |
||
686 | * @return MyPositionResponse |
||
687 | */ |
||
688 | private function setPositionIM(float $positionIM): self |
||
689 | { |
||
690 | $this->positionIM = $positionIM; |
||
691 | return $this; |
||
692 | } |
||
693 | |||
694 | /** |
||
695 | * @return string |
||
696 | */ |
||
697 | public function getPositionStatus(): string |
||
698 | { |
||
699 | return $this->positionStatus; |
||
700 | } |
||
701 | |||
702 | /** |
||
703 | * @param string $positionStatus |
||
704 | * @return MyPositionResponse |
||
705 | */ |
||
706 | private function setPositionStatus(string $positionStatus): self |
||
707 | { |
||
708 | $this->positionStatus = $positionStatus; |
||
709 | return $this; |
||
710 | } |
||
711 | |||
712 | /** |
||
713 | * @return float |
||
714 | */ |
||
715 | public function getSessionAvgPrice(): float |
||
716 | { |
||
717 | return $this->sessionAvgPrice; |
||
718 | } |
||
719 | |||
720 | /** |
||
721 | * @param float $sessionAvgPrice |
||
722 | * @return MyPositionResponse |
||
723 | */ |
||
724 | private function setSessionAvgPrice(float $sessionAvgPrice): self |
||
725 | { |
||
726 | $this->sessionAvgPrice = $sessionAvgPrice; |
||
727 | return $this; |
||
728 | } |
||
729 | |||
730 | /** |
||
731 | * @return float |
||
732 | */ |
||
733 | public function getOccClosingFee(): float |
||
734 | { |
||
735 | return $this->occClosingFee; |
||
736 | } |
||
737 | |||
738 | /** |
||
739 | * @param float $occClosingFee |
||
740 | * @return MyPositionResponse |
||
741 | */ |
||
742 | private function setOccClosingFee(float $occClosingFee): self |
||
746 | } |
||
747 | |||
748 | /** |
||
749 | * @return int |
||
750 | */ |
||
751 | public function getAdlRankIndicator(): int |
||
752 | { |
||
753 | return $this->adlRankIndicator; |
||
754 | } |
||
755 | |||
756 | /** |
||
757 | * @param int $adlRankIndicator |
||
758 | * @return MyPositionResponse |
||
759 | */ |
||
760 | private function setAdlRankIndicator(int $adlRankIndicator): self |
||
761 | { |
||
762 | $this->adlRankIndicator = $adlRankIndicator; |
||
763 | return $this; |
||
764 | } |
||
765 | } |