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