Passed
Push — master ( 7a134a...be08d2 )
by Vladislav
02:35 queued 13s
created

TickersResponse::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 13
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
namespace Carpenstar\ByBitAPI\Spot\MarketData\Tickers\Response;
3
4
use Carpenstar\ByBitAPI\Core\Helpers\DateTimeHelper;
5
use Carpenstar\ByBitAPI\Core\Objects\ResponseEntity;
6
use Carpenstar\ByBitAPI\Spot\MarketData\Tickers\Interfaces\ITickersResponse;
7
8
class TickersResponse extends ResponseEntity implements ITickersResponse
9
{
10
    /**
11
     * Current timestamp
12
     * @var \DateTime $t
13
     */
14
    private \DateTime $t;
15
16
    /**
17
     * Name of the trading pair
18
     * @var string $s
19
     */
20
    private string $s;
21
22
    /**
23
     * Last traded price
24
     * @var float $lp
25
     */
26
    private float $lp;
27
28
    /**
29
     * High price
30
     * @var float $h
31
     */
32
    private float $h;
33
34
    /**
35
     * Low price
36
     * @var float $l
37
     */
38
    private float $l;
39
40
    /**
41
     * Open price
42
     * @var float $o
43
     */
44
    private float $o;
45
46
    /**
47
     * Best bid price
48
     * @var float $bp
49
     */
50
    private float $bp;
51
52
    /**
53
     * Best ask price
54
     * @var float $ap
55
     */
56
    private float $ap;
57
58
    /**
59
     * Trading volume
60
     * @var float $v
61
     */
62
    private float $v;
63
64
    /**
65
     * Trading quote volume
66
     * @var float $qv
67
     */
68
    private float $qv;
69
70
    /**
71
     * @param array $data
72
     */
73
    public function __construct(array $data)
74
    {
75
        $this
76
            ->setT($data['t'])
77
            ->setS($data['s'])
78
            ->setLp($data['lp'])
79
            ->setH($data['h'])
80
            ->setL($data['l'])
81
            ->setO($data['o'])
82
            ->setBp($data['bp'])
83
            ->setAp($data['ap'])
84
            ->setV($data['v'])
85
            ->setQv($data['qv']);
86
    }
87
88
    /**
89
     * @param int $timestamp
90
     * @return TickersResponse
91
     */
92
    private function setT(int $timestamp): self
93
    {
94
        $this->t = DateTimeHelper::makeFromTimestamp($timestamp);
95
        return $this;
96
    }
97
98
    /**
99
     * @return \DateTime
100
     */
101
    public function getTime(): \DateTime
102
    {
103
        return $this->t;
104
    }
105
106
    /**
107
     * @param string $s
108
     * @return TickersResponse
109
     */
110
    private function setS(string $s): self
111
    {
112
        $this->s = $s;
113
        return $this;
114
    }
115
116
    /**
117
     * @return string
118
     */
119
    public function getSymbol(): string
120
    {
121
        return $this->s;
122
    }
123
124
    /**
125
     * @param float $ap
126
     */
127
    private function setAp(float $ap): self
128
    {
129
        $this->ap = $ap;
130
        return $this;
131
    }
132
133
    /**
134
     * Best ask price
135
     * @return float
136
     */
137
    public function getBestAskPrice(): float
138
    {
139
        return $this->ap;
140
    }
141
142
    /**
143
     * @param float $lp
144
     * @return TickersResponse
145
     */
146
    private function setLp(float $lp): self
147
    {
148
        $this->lp = $lp;
149
        return $this;
150
    }
151
152
    /**
153
     * Last traded price
154
     * @return float
155
     */
156
    public function getLastTradedPrice(): float
157
    {
158
        return $this->lp;
159
    }
160
161
    /**
162
     * @param float $h
163
     * @return TickersResponse
164
     */
165
    private function setH(float $h): self
166
    {
167
        $this->h = $h;
168
        return $this;
169
    }
170
171
    /**
172
     * High price
173
     * @return int
174
     */
175
    public function getHighPrice(): float
176
    {
177
        return $this->h;
178
    }
179
180
    /**
181
     * @param float $l
182
     * @return TickersResponse
183
     */
184
    private function setL(float $l): self
185
    {
186
        $this->l = $l;
187
        return $this;
188
    }
189
190
    /**
191
     * Low price
192
     * @return float
193
     */
194
    public function getLowPrice(): float
195
    {
196
        return $this->l;
197
    }
198
199
    /**
200
     * @param float $o
201
     * @return TickersResponse
202
     */
203
    private function setO(float $o): self
204
    {
205
        $this->o = $o;
206
        return $this;
207
    }
208
209
    /**
210
     * Open price
211
     * @return float
212
     */
213
    public function getOpenPrice(): float
214
    {
215
        return $this->o;
216
    }
217
218
    /**
219
     * @param float $bp
220
     * @return TickersResponse
221
     */
222
    private function setBp(float $bp): self
223
    {
224
        $this->bp = $bp;
225
        return $this;
226
    }
227
228
    /**
229
     * Best bid price
230
     * @return float
231
     */
232
    public function getBestBidPrice(): float
233
    {
234
        return $this->bp;
235
    }
236
237
    /**
238
     * @param float $v
239
     * @return TickersResponse
240
     */
241
    private function setV(float $v): self
242
    {
243
        $this->v = $v;
244
        return $this;
245
    }
246
247
    /**
248
     * Trading volume
249
     * @return float
250
     */
251
    public function getTradingVolume(): float
252
    {
253
        return $this->v;
254
    }
255
256
    /**
257
     * @param float $qv
258
     * @return TickersResponse
259
     */
260
    private function setQv(float $qv): self
261
    {
262
        $this->qv = $qv;
263
        return $this;
264
    }
265
266
    /**
267
     * Trading quote volume
268
     * @return float
269
     */
270
    public function getTradingQuoteVolume(): float
271
    {
272
        return $this->qv;
273
    }
274
}