1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Carpenstar\ByBitAPI\Spot\MarketData\BestBidAskPrice\Response; |
4
|
|
|
|
5
|
|
|
use Carpenstar\ByBitAPI\Core\Helpers\DateTimeHelper; |
6
|
|
|
use Carpenstar\ByBitAPI\Core\Objects\AbstractResponse; |
7
|
|
|
use Carpenstar\ByBitAPI\Spot\MarketData\BestBidAskPrice\Interfaces\IBestBidAskPriceResponseInterface; |
8
|
|
|
|
9
|
|
|
class BestBidAskPriceResponse extends AbstractResponse implements IBestBidAskPriceResponseInterface |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* Name of the trading pair |
13
|
|
|
* @var string $symbol |
14
|
|
|
*/ |
15
|
|
|
private string $symbol; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Best bid price |
19
|
|
|
* @var float $bidPrice |
20
|
|
|
*/ |
21
|
|
|
private float $bidPrice; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Bid quantity |
25
|
|
|
* @var float $bidQty |
26
|
|
|
*/ |
27
|
|
|
private float $bidQty; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Best ask price |
31
|
|
|
* @var float $askPrice |
32
|
|
|
*/ |
33
|
|
|
private float $askPrice; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Ask quantity |
37
|
|
|
* @var float $askQty |
38
|
|
|
*/ |
39
|
|
|
private float $askQty; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var \DateTime $time |
43
|
|
|
*/ |
44
|
|
|
private \DateTime $time; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param array $data |
48
|
|
|
*/ |
49
|
|
|
public function __construct(array $data) |
50
|
|
|
{ |
51
|
|
|
$this |
52
|
|
|
->setSymbol($data['symbol']) |
53
|
|
|
->setTime($data['time']) |
54
|
|
|
->setAskPrice($data['askPrice']) |
55
|
|
|
->setBidPrice($data['bidPrice']) |
56
|
|
|
->setBidQty($data['bidQty']) |
57
|
|
|
->setAskQty($data['askQty']); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @param string $symbol |
62
|
|
|
* @return $this |
63
|
|
|
*/ |
64
|
|
|
private function setSymbol(string $symbol): self |
65
|
|
|
{ |
66
|
|
|
$this->symbol = $symbol; |
67
|
|
|
return $this; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @return string |
72
|
|
|
*/ |
73
|
|
|
public function getSymbol(): string |
74
|
|
|
{ |
75
|
|
|
return $this->symbol; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param float $askPrice |
80
|
|
|
* @return BestBidAskPriceResponse |
81
|
|
|
*/ |
82
|
|
|
private function setAskPrice(float $askPrice): self |
83
|
|
|
{ |
84
|
|
|
$this->askPrice = $askPrice; |
85
|
|
|
return $this; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @return float |
90
|
|
|
*/ |
91
|
|
|
public function getAskPrice(): float |
92
|
|
|
{ |
93
|
|
|
return $this->askPrice; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @param float $askQty |
98
|
|
|
* @return BestBidAskPriceResponse |
99
|
|
|
*/ |
100
|
|
|
private function setAskQty(float $askQty): self |
101
|
|
|
{ |
102
|
|
|
$this->askQty = $askQty; |
103
|
|
|
return $this; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @return float |
108
|
|
|
*/ |
109
|
|
|
public function getAskQty(): float |
110
|
|
|
{ |
111
|
|
|
return $this->askQty; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @param float $bidPrice |
116
|
|
|
* @return BestBidAskPriceResponse |
117
|
|
|
*/ |
118
|
|
|
private function setBidPrice(float $bidPrice): self |
119
|
|
|
{ |
120
|
|
|
$this->bidPrice = $bidPrice; |
121
|
|
|
return $this; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @return float |
126
|
|
|
*/ |
127
|
|
|
public function getBidPrice(): float |
128
|
|
|
{ |
129
|
|
|
return $this->bidPrice; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @param float $bidQty |
134
|
|
|
* @return BestBidAskPriceResponse |
135
|
|
|
*/ |
136
|
|
|
private function setBidQty(string $bidQty): self |
137
|
|
|
{ |
138
|
|
|
$this->bidQty = $bidQty; |
|
|
|
|
139
|
|
|
return $this; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @return float |
144
|
|
|
*/ |
145
|
|
|
public function getBidQty(): float |
146
|
|
|
{ |
147
|
|
|
return $this->bidQty; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @param int $time |
152
|
|
|
* @return BestBidAskPriceResponse |
153
|
|
|
*/ |
154
|
|
|
private function setTime(int $time): self |
155
|
|
|
{ |
156
|
|
|
$this->time = DateTimeHelper::makeFromTimestamp($time); |
157
|
|
|
return $this; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @return \DateTime |
162
|
|
|
*/ |
163
|
|
|
public function getTime(): \DateTime |
164
|
|
|
{ |
165
|
|
|
return $this->time; |
166
|
|
|
} |
167
|
|
|
} |
168
|
|
|
|
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.