1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Codenixsv\MessariApi\Api; |
6
|
|
|
|
7
|
|
|
use Exception; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class Assets |
11
|
|
|
* @package Codenixsv\MessariApi\Api |
12
|
|
|
*/ |
13
|
|
|
class Assets extends Api |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* Get the paginated list of all assets and their metrics and profiles. |
17
|
|
|
* |
18
|
|
|
* @param bool $withMetrics existence of this query param filters assets to those with quantitative data |
19
|
|
|
* @param bool $withProfiles existence of this query param filters assets to those with qualitative data |
20
|
|
|
* @param string|null $fields pare down the returned fields (comma , separated, drill down with a slash /) |
21
|
|
|
* @param string|null $sort default sort is "marketcap desc", but the only valid value for this query |
22
|
|
|
* param is "id" which translates to "id asc", which is useful for a stable sort while paginating |
23
|
|
|
* @param int|null $page Page number, starts at 1. Increment to paginate through |
24
|
|
|
* results (until result is empty array) |
25
|
|
|
* @param int|null $limit default is 20, max is 500 |
26
|
|
|
* @return array |
27
|
|
|
* @throws Exception |
28
|
|
|
*/ |
29
|
2 |
|
public function getAll( |
30
|
|
|
bool $withMetrics = false, |
31
|
|
|
bool $withProfiles = false, |
32
|
|
|
?string $fields = null, |
33
|
|
|
?string $sort = null, |
34
|
|
|
?int $page = null, |
35
|
|
|
?int $limit = null |
36
|
|
|
): array { |
37
|
2 |
|
$params = compact('fields', 'sort', 'page', 'limit'); |
38
|
2 |
|
if (true === $withMetrics) { |
39
|
1 |
|
$params['with-metrics'] = ''; |
40
|
|
|
} |
41
|
2 |
|
if (true === $withProfiles) { |
42
|
1 |
|
$params['with-profiles'] = ''; |
43
|
|
|
} |
44
|
|
|
|
45
|
2 |
|
$query = $this->queryBuilder->buildQuery($params); |
46
|
2 |
|
$response = $this->client->getBaseClient()->get('/assets' . $query); |
47
|
|
|
|
48
|
2 |
|
return $this->transformer->transform($response); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Get basic metadata for an asset. |
53
|
|
|
* |
54
|
|
|
* @param string $assetKey This "key" can be the asset's ID (unique), slug (unique), or symbol (non-unique) |
55
|
|
|
* @param string|null $fields pare down the returned fields (comma , separated, drill down with a slash /) |
56
|
|
|
* @return array |
57
|
|
|
* @throws Exception |
58
|
|
|
*/ |
59
|
1 |
|
public function get(string $assetKey, ?string $fields = null): array |
60
|
|
|
{ |
61
|
1 |
|
$query = $this->queryBuilder->buildQuery(compact('fields')); |
62
|
1 |
|
$response = $this->client->getBaseClient()->get('/assets/' . strtolower($assetKey) . $query); |
63
|
|
|
|
64
|
1 |
|
return $this->transformer->transform($response); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Get all of our qualitative information for an asset. |
69
|
|
|
* |
70
|
|
|
* @param string $assetKey This "key" can be the asset's ID (unique), slug (unique), or symbol (non-unique) |
71
|
|
|
* @param string|null $fields pare down the returned fields (comma , separated, drill down with a slash /) |
72
|
|
|
* @return array |
73
|
|
|
* @throws Exception |
74
|
|
|
*/ |
75
|
1 |
|
public function getProfile(string $assetKey, ?string $fields = null): array |
76
|
|
|
{ |
77
|
1 |
|
$query = $this->queryBuilder->buildQuery(compact('fields')); |
78
|
1 |
|
$response = $this->client->getBaseClient()->get('/assets/' . strtolower($assetKey) . '/profile' . $query); |
79
|
|
|
|
80
|
1 |
|
return $this->transformer->transform($response); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Get all of our quantitative metrics for an asset. |
85
|
|
|
* |
86
|
|
|
* @param string $assetKey This "key" can be the asset's ID (unique), slug (unique), or symbol (non-unique) |
87
|
|
|
* @param string|null $fields pare down the returned fields (comma , separated, drill down with a slash /) |
88
|
|
|
* @return array |
89
|
|
|
* @throws Exception |
90
|
|
|
*/ |
91
|
1 |
|
public function getMetrics(string $assetKey, ?string $fields = null): array |
92
|
|
|
{ |
93
|
1 |
|
$query = $this->queryBuilder->buildQuery(compact('fields')); |
94
|
1 |
|
$response = $this->client->getBaseClient()->get('/assets/' . strtolower($assetKey) . '/metrics' . $query); |
95
|
|
|
|
96
|
1 |
|
return $this->transformer->transform($response); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Get the latest market data for an asset. This data is also included in the metrics endpoint, but if all you need |
101
|
|
|
* is market-data, use this. |
102
|
|
|
* |
103
|
|
|
* @param string $assetKey This "key" can be the asset's ID (unique), slug (unique), or symbol (non-unique) |
104
|
|
|
* @param string|null $fields pare down the returned fields (comma , separated, drill down with a slash /) |
105
|
|
|
* @return array |
106
|
|
|
* @throws Exception |
107
|
|
|
*/ |
108
|
1 |
|
public function getMarketData(string $assetKey, ?string $fields = null): array |
109
|
|
|
{ |
110
|
1 |
|
$query = $this->queryBuilder->buildQuery(compact('fields')); |
111
|
1 |
|
$response = $this->client->getBaseClient()->get('/assets/' . strtolower($assetKey) . '/metrics' |
112
|
1 |
|
. '/market-data' . $query); |
113
|
|
|
|
114
|
1 |
|
return $this->transformer->transform($response); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Retrieve historical timeseries data for an asset. |
119
|
|
|
* |
120
|
|
|
* @param string $assetKey This "key" can be the asset's ID (unique), slug (unique), or symbol (non-unique) |
121
|
|
|
* @param string $metricID The metricID is a unique identifier which describes the type of data returned by |
122
|
|
|
* time-series endpoints. |
123
|
|
|
* @param string|null $start The "start" query parameter can be used to set the start date after which points |
124
|
|
|
* are returned. |
125
|
|
|
* @param string|null $end The "end" query parameter can be used to set the end date after which no more points |
126
|
|
|
* will be returned. |
127
|
|
|
* @param string|null $interval Defines what interval the resulting points will be returned in. |
128
|
|
|
* @param string|null $columns A comma separated list of strings that controls which columns will be returned and |
129
|
|
|
* in what order. |
130
|
|
|
* @param string|null $order Order controls whether points in the response are returned in ascending or |
131
|
|
|
* descending order. |
132
|
|
|
* @param string|null $format Specify format = csv to download data as CSV. |
133
|
|
|
* @return array |
134
|
|
|
* @throws Exception |
135
|
|
|
*/ |
136
|
2 |
|
public function getTimeseries( |
137
|
|
|
string $assetKey, |
138
|
|
|
string $metricID, |
139
|
|
|
?string $start = null, |
140
|
|
|
?string $end = null, |
141
|
|
|
?string $interval = null, |
142
|
|
|
?string $columns = null, |
143
|
|
|
?string $order = null, |
144
|
|
|
?string $format = null |
145
|
|
|
): array { |
146
|
2 |
|
$query = $this->queryBuilder->buildQuery(compact('start', 'end', 'interval', 'columns', 'order', 'format')); |
147
|
2 |
|
$response = $this->client->getBaseClient()->get('/assets/' . strtolower($assetKey) . '/metrics/' |
148
|
2 |
|
. $metricID . '/time-series' . $query); |
149
|
|
|
|
150
|
2 |
|
return $this->transformer->transform($response); |
151
|
|
|
} |
152
|
|
|
} |
153
|
|
|
|