Passed
Pull Request — master (#8)
by Vladislav
10:51
created

KlineAbstract::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 11
nc 1
nop 1
dl 0
loc 13
rs 9.9
c 0
b 0
f 0
1
<?php
2
namespace Carpenstar\ByBitAPI\WebSockets\Channels\Spot\PublicChannels\Kline\Entities;
3
4
use Carpenstar\ByBitAPI\Core\Helpers\DateTimeHelper;
5
use Carpenstar\ByBitAPI\Core\Objects\AbstractResponse;
6
7
class KlineAbstract extends AbstractResponse
8
{
9
    /**
10
     * Topic name
11
     * @var string $topic
12
     */
13
    private string $topic;
14
15
    /**
16
     * The timestamp that message is sent out
17
     * @var \DateTime $requestTimestamp
18
     */
19
    private \DateTime $requestTimestamp;
20
21
    /**
22
     * Data type. snapshot
23
     * @var string $type
24
     */
25
    private string $type;
26
27
    /**
28
     * The start timestamp of the bar
29
     * @var \DateTime $barTimestamp
30
     */
31
    private \DateTime $barTimestamp;
32
33
    /**
34
     * Trading pair
35
     * @var string $symbol
36
     */
37
    private string $symbol;
38
39
    /**
40
     * Close price
41
     * @var float $closePrice
42
     */
43
    private float $closePrice;
44
45
    /**
46
     * High price
47
     * @var float $highPrice
48
     */
49
    private float $highPrice;
50
51
    /**
52
     * Low price
53
     * @var float $lowPrice
54
     */
55
    private float $lowPrice;
56
57
    /**
58
     * Open price
59
     * @var float $openPrice
60
     */
61
    private float $openPrice;
62
63
    /**
64
     * Trading volume
65
     * @var float $tradingVolume
66
     */
67
    private float $tradingVolume;
68
69
    public function __construct(array $data)
70
    {
71
        $this
72
            ->setTopic($data['topic'])
73
            ->setRequestTimestamp($data['ts'])
74
            ->setType($data['type'])
75
            ->setBarTimestamp($data['data']['t'])
76
            ->setSymbol($data['data']['s'])
77
            ->setClosePrice($data['data']['c'])
78
            ->setHighPrice($data['data']['h'])
79
            ->setLowPrice($data['data']['l'])
80
            ->setOpenPrice($data['data']['o'])
81
            ->setTradingVolume($data['data']['v']);
82
    }
83
84
    /**
85
     * @param string $topic
86
     * @return KlineAbstract
87
     */
88
    private function setTopic(string $topic): self
89
    {
90
        $this->topic = $topic;
91
        return $this;
92
    }
93
94
    /**
95
     * @param string $requestTimestamp
96
     * @return KlineAbstract
97
     */
98
    private function setRequestTimestamp(string $requestTimestamp): self
99
    {
100
        $this->requestTimestamp = DateTimeHelper::makeFromTimestamp($requestTimestamp);
0 ignored issues
show
Bug introduced by
$requestTimestamp of type string is incompatible with the type integer expected by parameter $timestamp of Carpenstar\ByBitAPI\Core...er::makeFromTimestamp(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

100
        $this->requestTimestamp = DateTimeHelper::makeFromTimestamp(/** @scrutinizer ignore-type */ $requestTimestamp);
Loading history...
101
        return $this;
102
    }
103
104
    /**
105
     * @param string $type
106
     * @return KlineAbstract
107
     */
108
    private function setType(string $type): self
109
    {
110
        $this->type = $type;
111
        return $this;
112
    }
113
114
    /**
115
     * @param string $barTimestamp
116
     * @return KlineAbstract
117
     */
118
    private function setBarTimestamp(string $barTimestamp): self
119
    {
120
        $this->barTimestamp = DateTimeHelper::makeFromTimestamp($barTimestamp);
0 ignored issues
show
Bug introduced by
$barTimestamp of type string is incompatible with the type integer expected by parameter $timestamp of Carpenstar\ByBitAPI\Core...er::makeFromTimestamp(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

120
        $this->barTimestamp = DateTimeHelper::makeFromTimestamp(/** @scrutinizer ignore-type */ $barTimestamp);
Loading history...
121
        return $this;
122
    }
123
124
    /**
125
     * @param string $symbol
126
     * @return KlineAbstract
127
     */
128
    private function setSymbol(string $symbol): self
129
    {
130
        $this->symbol = $symbol;
131
        return $this;
132
    }
133
134
    /**
135
     * @param float $closePrice
136
     * @return KlineAbstract
137
     */
138
    private function setClosePrice(float $closePrice): self
139
    {
140
        $this->closePrice = $closePrice;
141
        return $this;
142
    }
143
144
    /**
145
     * @param float $highPrice
146
     * @return KlineAbstract
147
     */
148
    private function setHighPrice(float $highPrice): self
149
    {
150
        $this->highPrice = $highPrice;
151
        return $this;
152
    }
153
154
    /**
155
     * @param float $lowPrice
156
     * @return KlineAbstract
157
     */
158
    private function setLowPrice(float $lowPrice): self
159
    {
160
        $this->lowPrice = $lowPrice;
161
        return $this;
162
    }
163
164
    /**
165
     * @param float $openPrice
166
     * @return KlineAbstract
167
     */
168
    private function setOpenPrice(float $openPrice): self
169
    {
170
        $this->openPrice = $openPrice;
171
        return $this;
172
    }
173
174
    /**
175
     * @param float $tradingVolume
176
     * @return KlineAbstract
177
     */
178
    private function setTradingVolume(float $tradingVolume): self
179
    {
180
        $this->tradingVolume = $tradingVolume;
181
        return $this;
182
    }
183
184
    /**
185
     * @return string
186
     */
187
    public function getTopic(): string
188
    {
189
        return $this->topic;
190
    }
191
192
    /**
193
     * @return \DateTime
194
     */
195
    public function getRequestTimestamp(): \DateTime
196
    {
197
        return $this->requestTimestamp;
198
    }
199
200
    /**
201
     * @return string
202
     */
203
    public function getType(): string
204
    {
205
        return $this->type;
206
    }
207
208
    /**
209
     * @return \DateTime
210
     */
211
    public function getBarTimestamp(): \DateTime
212
    {
213
        return $this->barTimestamp;
214
    }
215
216
    /**
217
     * @return string
218
     */
219
    public function getSymbol(): string
220
    {
221
        return $this->symbol;
222
    }
223
224
    /**
225
     * @return float
226
     */
227
    public function getClosePrice(): float
228
    {
229
        return $this->closePrice;
230
    }
231
232
    /**
233
     * @return float
234
     */
235
    public function getHighPrice(): float
236
    {
237
        return $this->highPrice;
238
    }
239
240
    /**
241
     * @return float
242
     */
243
    public function getLowPrice(): float
244
    {
245
        return $this->lowPrice;
246
    }
247
248
    /**
249
     * @return float
250
     */
251
    public function getOpenPrice(): float
252
    {
253
        return $this->openPrice;
254
    }
255
256
    /**
257
     * @return float
258
     */
259
    public function getTradingVolume(): float
260
    {
261
        return $this->tradingVolume;
262
    }
263
}