Completed
Push — master ( 5bd029...50052c )
by Fabian
01:43
created

TickerResponse   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 155
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 155
ccs 0
cts 67
cp 0
rs 10
c 0
b 0
f 0
wmc 13

11 Methods

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