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