1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Carpenstar\ByBitAPI\Spot\MarketData\Kline\Response; |
4
|
|
|
|
5
|
|
|
use Carpenstar\ByBitAPI\Core\Helpers\DateTimeHelper; |
6
|
|
|
use Carpenstar\ByBitAPI\Core\Objects\AbstractResponse; |
7
|
|
|
use Carpenstar\ByBitAPI\Spot\MarketData\Kline\Interfaces\IKlineResponseItemInterface; |
8
|
|
|
|
9
|
|
|
class KlineResponseItem extends AbstractResponse implements IKlineResponseItemInterface |
10
|
|
|
{ |
11
|
|
|
private \DateTime $time; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Name of the trading pair |
15
|
|
|
* @var string $symbol |
16
|
|
|
*/ |
17
|
|
|
private string $symbol; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Alias |
21
|
|
|
* @var string $alias |
22
|
|
|
*/ |
23
|
|
|
private string $alias; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Close price |
27
|
|
|
* @var float $closePrice |
28
|
|
|
*/ |
29
|
|
|
private float $closePrice; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* High price |
33
|
|
|
* @var float $highPrice |
34
|
|
|
*/ |
35
|
|
|
private float $highPrice; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Low price |
39
|
|
|
* @var float $lowPrice |
40
|
|
|
*/ |
41
|
|
|
private float $lowPrice; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Open price |
45
|
|
|
* @var float $openPrice |
46
|
|
|
*/ |
47
|
|
|
private float $openPrice; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Trading volume |
51
|
|
|
* @var float $tradingVolume |
52
|
|
|
*/ |
53
|
|
|
private float $tradingVolume; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param array $data |
57
|
|
|
*/ |
58
|
|
|
public function __construct(array $data) |
59
|
|
|
{ |
60
|
|
|
$this |
61
|
|
|
->setTime($data['t']) |
62
|
|
|
->setSymbol($data['s']) |
63
|
|
|
->setAlias($data['sn']) |
64
|
|
|
->setClosePrice($data['c']) |
65
|
|
|
->setHighPrice($data['h']) |
66
|
|
|
->setLowPrice($data['l']) |
67
|
|
|
->setOpenPrice($data['o']) |
68
|
|
|
->setTradingVolume($data['v']); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @param int $timestamp |
73
|
|
|
* @return KlineResponseItem |
74
|
|
|
*/ |
75
|
|
|
private function setTime(int $timestamp): self |
76
|
|
|
{ |
77
|
|
|
$this->time = DateTimeHelper::makeFromTimestamp($timestamp); |
78
|
|
|
return $this; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @return \DateTime |
83
|
|
|
*/ |
84
|
|
|
public function getTime(): \DateTime |
85
|
|
|
{ |
86
|
|
|
return $this->time; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @param string $symbol |
91
|
|
|
* @return KlineResponseItem |
92
|
|
|
*/ |
93
|
|
|
private function setSymbol(string $symbol): self |
94
|
|
|
{ |
95
|
|
|
$this->symbol = $symbol; |
96
|
|
|
return $this; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @return string |
101
|
|
|
*/ |
102
|
|
|
public function getSymbol(): string |
103
|
|
|
{ |
104
|
|
|
return $this->symbol; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @param string $alias |
109
|
|
|
* @return KlineResponseItem |
110
|
|
|
*/ |
111
|
|
|
private function setAlias(string $alias): self |
112
|
|
|
{ |
113
|
|
|
$this->alias = $alias; |
114
|
|
|
return $this; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @return string |
119
|
|
|
*/ |
120
|
|
|
public function getAlias(): string |
121
|
|
|
{ |
122
|
|
|
return $this->alias; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @param float $closePrice |
127
|
|
|
* @return KlineResponseItem |
128
|
|
|
*/ |
129
|
|
|
private function setClosePrice(float $closePrice): self |
130
|
|
|
{ |
131
|
|
|
$this->closePrice = $closePrice; |
132
|
|
|
return $this; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @return float |
137
|
|
|
*/ |
138
|
|
|
public function getClosePrice(): float |
139
|
|
|
{ |
140
|
|
|
return $this->closePrice; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @param float $highPrice |
145
|
|
|
* @return KlineResponseItem |
146
|
|
|
*/ |
147
|
|
|
private function setHighPrice(float $highPrice): self |
148
|
|
|
{ |
149
|
|
|
$this->highPrice = $highPrice; |
150
|
|
|
return $this; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @return float |
155
|
|
|
*/ |
156
|
|
|
public function getHighPrice(): float |
157
|
|
|
{ |
158
|
|
|
return $this->highPrice; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* @param float $lowPrice |
163
|
|
|
* @return KlineResponseItem |
164
|
|
|
*/ |
165
|
|
|
private function setLowPrice(float $lowPrice): self |
166
|
|
|
{ |
167
|
|
|
$this->lowPrice = $lowPrice; |
168
|
|
|
return $this; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* @return float |
173
|
|
|
*/ |
174
|
|
|
public function getLowPrice(): float |
175
|
|
|
{ |
176
|
|
|
return $this->lowPrice; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* @param float $openPrice |
181
|
|
|
* @return KlineResponseItem |
182
|
|
|
*/ |
183
|
|
|
private function setOpenPrice(float $openPrice): self |
184
|
|
|
{ |
185
|
|
|
$this->openPrice = $openPrice; |
186
|
|
|
return $this; |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* @return float |
191
|
|
|
*/ |
192
|
|
|
public function getOpenPrice(): float |
193
|
|
|
{ |
194
|
|
|
return $this->openPrice; |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* @param float $tradingVolume |
199
|
|
|
* @return KlineResponseItem |
200
|
|
|
*/ |
201
|
|
|
private function setTradingVolume(float $tradingVolume): self |
202
|
|
|
{ |
203
|
|
|
$this->tradingVolume = $tradingVolume; |
204
|
|
|
return $this; |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* @return float |
209
|
|
|
*/ |
210
|
|
|
public function getTradingVolume(): float |
211
|
|
|
{ |
212
|
|
|
return $this->tradingVolume; |
213
|
|
|
} |
214
|
|
|
} |
215
|
|
|
|