1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Carpenstar\ByBitAPI\Spot\MarketData\PublicTradingRecords\Response; |
4
|
|
|
|
5
|
|
|
use Carpenstar\ByBitAPI\Core\Helpers\DateTimeHelper; |
6
|
|
|
use Carpenstar\ByBitAPI\Core\Objects\AbstractResponse; |
7
|
|
|
use Carpenstar\ByBitAPI\Spot\MarketData\PublicTradingRecords\Interfaces\IPublicTradingRecordsResponseItemInterface; |
8
|
|
|
|
9
|
|
|
class PublicTradingRecordsResponseItem extends AbstractResponse implements IPublicTradingRecordsResponseItemInterface |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* Order price |
13
|
|
|
* @var null|float $price |
14
|
|
|
*/ |
15
|
|
|
private ?float $price; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Current timestamp |
19
|
|
|
* @var \DateTime $time |
20
|
|
|
*/ |
21
|
|
|
private \DateTime $time; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Order quantity |
25
|
|
|
* @var float $quantity |
26
|
|
|
*/ |
27
|
|
|
private float $qty; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* 0:Sell or taker order, 1:Buy maker order |
31
|
|
|
* @var bool $isBuyerMaker |
32
|
|
|
*/ |
33
|
|
|
private bool $isBuyerMaker; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* 0:normal trade, 1:Paradigm block trade |
37
|
|
|
* @var int $type |
38
|
|
|
*/ |
39
|
|
|
private int $type; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param array $data |
43
|
|
|
*/ |
44
|
|
|
public function __construct(array $data) |
45
|
|
|
{ |
46
|
|
|
$this |
47
|
|
|
->setPrice($data['price']) |
48
|
|
|
->setQty($data['qty']) |
49
|
|
|
->setTime($data['time']) |
50
|
|
|
->setIsBuyerMaker((bool)$data['isBuyerMaker']) |
51
|
|
|
->setType($data['type']); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param string $type |
56
|
|
|
* @return self |
57
|
|
|
*/ |
58
|
|
|
private function setType(string $type): self |
59
|
|
|
{ |
60
|
|
|
$this->type = $type; |
|
|
|
|
61
|
|
|
return $this; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @return int |
66
|
|
|
*/ |
67
|
|
|
public function getType(): int |
68
|
|
|
{ |
69
|
|
|
return $this->type; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @param float|null $price |
74
|
|
|
* @return PublicTradingRecordsResponseItem |
75
|
|
|
*/ |
76
|
|
|
private function setPrice(?float $price = null): self |
77
|
|
|
{ |
78
|
|
|
$this->price = $price; |
79
|
|
|
return $this; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @return float |
84
|
|
|
*/ |
85
|
|
|
public function getPrice(): float |
86
|
|
|
{ |
87
|
|
|
return $this->price; |
|
|
|
|
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @param float $quantity |
92
|
|
|
* @return PublicTradingRecordsResponseItem |
93
|
|
|
*/ |
94
|
|
|
private function setQty(?float $quantity = null): self |
95
|
|
|
{ |
96
|
|
|
$this->qty = $quantity; |
97
|
|
|
return $this; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @return float |
102
|
|
|
*/ |
103
|
|
|
public function getQuantity(): float |
104
|
|
|
{ |
105
|
|
|
return $this->qty; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @param int $time |
110
|
|
|
* @return PublicTradingRecordsResponseItem |
111
|
|
|
*/ |
112
|
|
|
private function setTime(int $time): self |
113
|
|
|
{ |
114
|
|
|
$this->time = DateTimeHelper::makeFromTimestamp($time); |
115
|
|
|
return $this; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @return \DateTime |
120
|
|
|
*/ |
121
|
|
|
public function getTime(): \DateTime |
122
|
|
|
{ |
123
|
|
|
return $this->time; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @param bool $isBuyerMaker |
128
|
|
|
* @return PublicTradingRecordsResponseItem |
129
|
|
|
*/ |
130
|
|
|
private function setIsBuyerMaker(bool $isBuyerMaker): self |
131
|
|
|
{ |
132
|
|
|
$this->isBuyerMaker = $isBuyerMaker; |
133
|
|
|
return $this; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @return bool |
138
|
|
|
*/ |
139
|
|
|
public function getIsBuyerMaker(): bool |
140
|
|
|
{ |
141
|
|
|
return $this->isBuyerMaker; |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
|
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.