|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace HanischIt\KrakenApi\Call\GetTicker; |
|
4
|
|
|
|
|
5
|
|
|
use HanischIt\KrakenApi\Call\GetTicker\Model\AskBidModel; |
|
6
|
|
|
use HanischIt\KrakenApi\Call\GetTicker\Model\DayPriceModel; |
|
7
|
|
|
use HanischIt\KrakenApi\Call\GetTicker\Model\PriceVolumeModel; |
|
8
|
|
|
use HanischIt\KrakenApi\Call\GetTicker\Model\TickerModel; |
|
9
|
|
|
use HanischIt\KrakenApi\Model\ResponseInterface; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Class TickerResponse |
|
13
|
|
|
* @package HanischIt\KrakenApi\Call\GetTicker |
|
14
|
|
|
*/ |
|
15
|
|
|
class TickerResponse implements ResponseInterface |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @var TickerModel[] |
|
19
|
|
|
*/ |
|
20
|
|
|
private $models; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @param array $result |
|
24
|
|
|
*/ |
|
25
|
2 |
|
public function manualMapping($result) |
|
26
|
|
|
{ |
|
27
|
2 |
|
foreach ($result as $assetPair => $tickerValues) { |
|
28
|
2 |
|
$this->models[$assetPair] = new TickerModel( |
|
29
|
2 |
|
$assetPair, |
|
30
|
2 |
|
new AskBidModel($tickerValues["a"][0], $tickerValues["a"][1], $tickerValues["a"][2]), |
|
31
|
2 |
|
new AskBidModel($tickerValues["b"][0], $tickerValues["b"][1], $tickerValues["b"][2]), |
|
32
|
2 |
|
new PriceVolumeModel($tickerValues["c"][0], $tickerValues["c"][1]), |
|
33
|
2 |
|
new DayPriceModel($tickerValues["v"][0], $tickerValues["v"][1]), |
|
34
|
2 |
|
new DayPriceModel($tickerValues["p"][0], $tickerValues["p"][1]), |
|
35
|
2 |
|
new DayPriceModel($tickerValues["t"][0], $tickerValues["t"][1]), |
|
36
|
2 |
|
new DayPriceModel($tickerValues["l"][0], $tickerValues["l"][1]), |
|
37
|
2 |
|
new DayPriceModel($tickerValues["h"][0], $tickerValues["h"][1]), |
|
38
|
2 |
|
$tickerValues["o"] |
|
39
|
2 |
|
); |
|
40
|
2 |
|
} |
|
41
|
2 |
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @param string $assetPair |
|
45
|
|
|
* |
|
46
|
|
|
* @return AskBidModel |
|
47
|
|
|
* @throws \Exception |
|
48
|
|
|
*/ |
|
49
|
1 |
|
public function getAsk($assetPair) |
|
50
|
|
|
{ |
|
51
|
1 |
|
$this->checkIfAssetPairExist($assetPair); |
|
52
|
|
|
|
|
53
|
1 |
|
return $this->models[$assetPair]->getAsk(); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @param string $assetPair |
|
58
|
|
|
* |
|
59
|
|
|
* @throws \Exception |
|
60
|
|
|
*/ |
|
61
|
2 |
|
private function checkIfAssetPairExist($assetPair) |
|
62
|
|
|
{ |
|
63
|
2 |
|
if (!isset($this->models[$assetPair])) { |
|
64
|
1 |
|
throw new \Exception($assetPair . " is not included in response"); |
|
65
|
|
|
} |
|
66
|
1 |
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @param string $assetPair |
|
70
|
|
|
* |
|
71
|
|
|
* @return AskBidModel |
|
72
|
|
|
* @throws \Exception |
|
73
|
|
|
*/ |
|
74
|
1 |
|
public function getBid($assetPair) |
|
75
|
|
|
{ |
|
76
|
1 |
|
$this->checkIfAssetPairExist($assetPair); |
|
77
|
|
|
|
|
78
|
1 |
|
return $this->models[$assetPair]->getBid(); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @param string $assetPair |
|
83
|
|
|
* |
|
84
|
|
|
* @return PriceVolumeModel |
|
85
|
|
|
* @throws \Exception |
|
86
|
|
|
*/ |
|
87
|
1 |
|
public function getLastTradeClosed($assetPair) |
|
88
|
|
|
{ |
|
89
|
1 |
|
$this->checkIfAssetPairExist($assetPair); |
|
90
|
|
|
|
|
91
|
1 |
|
return $this->models[$assetPair]->getLastTradeClosed(); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @param string $assetPair |
|
96
|
|
|
* |
|
97
|
|
|
* @return DayPriceModel |
|
98
|
|
|
* @throws \Exception |
|
99
|
|
|
*/ |
|
100
|
1 |
|
public function getVolume($assetPair) |
|
101
|
|
|
{ |
|
102
|
1 |
|
$this->checkIfAssetPairExist($assetPair); |
|
103
|
|
|
|
|
104
|
1 |
|
return $this->models[$assetPair]->getVolume(); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* @param string $assetPair |
|
109
|
|
|
* |
|
110
|
|
|
* @return DayPriceModel |
|
111
|
|
|
* @throws \Exception |
|
112
|
|
|
*/ |
|
113
|
1 |
|
public function getVolumeWeightedAverage($assetPair) |
|
114
|
|
|
{ |
|
115
|
1 |
|
$this->checkIfAssetPairExist($assetPair); |
|
116
|
|
|
|
|
117
|
1 |
|
return $this->models[$assetPair]->getVolumeWeightedAverage(); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* @param string $assetPair |
|
122
|
|
|
* |
|
123
|
|
|
* @return DayPriceModel |
|
124
|
|
|
* @throws \Exception |
|
125
|
|
|
*/ |
|
126
|
1 |
|
public function getNumberOfTrades($assetPair) |
|
127
|
|
|
{ |
|
128
|
1 |
|
$this->checkIfAssetPairExist($assetPair); |
|
129
|
|
|
|
|
130
|
1 |
|
return $this->models[$assetPair]->getNumberOfTrades(); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* @param string $assetPair |
|
135
|
|
|
* |
|
136
|
|
|
* @return DayPriceModel |
|
137
|
|
|
* @throws \Exception |
|
138
|
|
|
*/ |
|
139
|
1 |
|
public function getLow($assetPair) |
|
140
|
|
|
{ |
|
141
|
1 |
|
$this->checkIfAssetPairExist($assetPair); |
|
142
|
|
|
|
|
143
|
1 |
|
return $this->models[$assetPair]->getLow(); |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* @param string $assetPair |
|
148
|
|
|
* |
|
149
|
|
|
* @return DayPriceModel |
|
150
|
|
|
* @throws \Exception |
|
151
|
|
|
*/ |
|
152
|
2 |
|
public function getHigh($assetPair) |
|
153
|
|
|
{ |
|
154
|
2 |
|
$this->checkIfAssetPairExist($assetPair); |
|
155
|
|
|
|
|
156
|
1 |
|
return $this->models[$assetPair]->getHigh(); |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
/** |
|
160
|
|
|
* @param string $assetPair |
|
161
|
|
|
* |
|
162
|
|
|
* @return float |
|
163
|
|
|
* @throws \Exception |
|
164
|
|
|
*/ |
|
165
|
1 |
|
public function getTodaysOpeningPrice($assetPair) |
|
166
|
|
|
{ |
|
167
|
1 |
|
$this->checkIfAssetPairExist($assetPair); |
|
168
|
|
|
|
|
169
|
1 |
|
return $this->models[$assetPair]->getTodaysOpeningPrice(); |
|
170
|
|
|
} |
|
171
|
|
|
} |
|
172
|
|
|
|