1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Codenixsv\CoinGeckoApi\Api; |
6
|
|
|
|
7
|
|
|
use Exception; |
8
|
|
|
|
9
|
|
|
class Coins extends Api |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @return array |
13
|
|
|
* @throws Exception |
14
|
|
|
*/ |
15
|
1 |
|
public function getList(): array |
16
|
|
|
{ |
17
|
1 |
|
return $this->get('/coins/list'); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @param string $vsCurrency |
22
|
|
|
* @param array $params |
23
|
|
|
* @return array |
24
|
|
|
* @throws Exception |
25
|
|
|
*/ |
26
|
1 |
|
public function getMarkets(string $vsCurrency, array $params = []): array |
27
|
|
|
{ |
28
|
1 |
|
$params['vs_currency'] = $vsCurrency; |
29
|
|
|
|
30
|
1 |
|
return $this->get('/coins/markets', $params); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param string $id |
35
|
|
|
* @param array $params |
36
|
|
|
* @return array |
37
|
|
|
* @throws Exception |
38
|
|
|
*/ |
39
|
1 |
|
public function getCoin(string $id, array $params = []): array |
40
|
|
|
{ |
41
|
1 |
|
return $this->get('/coins/' . $id, $params); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param string $id |
46
|
|
|
* @param array $params |
47
|
|
|
* @return array |
48
|
|
|
* @throws Exception |
49
|
|
|
*/ |
50
|
1 |
|
public function getTickers(string $id, array $params = []): array |
51
|
|
|
{ |
52
|
1 |
|
return $this->get('/coins/' . $id . '/tickers', $params); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param string $id |
57
|
|
|
* @param string $date |
58
|
|
|
* @param array $params |
59
|
|
|
* @return array |
60
|
|
|
* @throws Exception |
61
|
|
|
*/ |
62
|
1 |
|
public function getHistory(string $id, string $date, array $params = []): array |
63
|
|
|
{ |
64
|
1 |
|
$params['date'] = $date; |
65
|
1 |
|
return $this->get('/coins/' . $id . '/history', $params); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param string $id |
70
|
|
|
* @param string $vsCurrency |
71
|
|
|
* @param string $days |
72
|
|
|
* @return array |
73
|
|
|
* @throws Exception |
74
|
|
|
*/ |
75
|
1 |
|
public function getMarketChart(string $id, string $vsCurrency, string $days): array |
76
|
|
|
{ |
77
|
1 |
|
$params['vs_currency'] = $vsCurrency; |
|
|
|
|
78
|
1 |
|
$params['days'] = $days; |
79
|
1 |
|
return $this->get('/coins/' . $id . '/market_chart', $params); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @param string $id |
84
|
|
|
* @param string $vsCurrency |
85
|
|
|
* @param string $from |
86
|
|
|
* @param string $to |
87
|
|
|
* @return array |
88
|
|
|
* @throws Exception |
89
|
|
|
*/ |
90
|
1 |
View Code Duplication |
public function getMarketChartRange(string $id, string $vsCurrency, string $from, string $to): array |
|
|
|
|
91
|
|
|
{ |
92
|
1 |
|
$params['vs_currency'] = $vsCurrency; |
|
|
|
|
93
|
1 |
|
$params['from'] = $from; |
94
|
1 |
|
$params['to'] = $to; |
95
|
1 |
|
return $this->get('/coins/' . $id . '/market_chart/range', $params); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @param string $id |
100
|
|
|
* @param array $params |
101
|
|
|
* @return array |
102
|
|
|
* @throws Exception |
103
|
|
|
*/ |
104
|
1 |
|
public function getStatusUpdates(string $id, array $params = []): array |
105
|
|
|
{ |
106
|
1 |
|
return $this->get('/coins/' . $id . '/status_updates', $params); |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArray
is initialized the first time when the foreach loop is entered. You can also see that the value of thebar
key is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.