1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
//! Coins API endpoints
use super::types::*;
use crate::client::Client;
use crate::error::Result;
/// Coins API
pub struct CoinsApi<'a> {
client: &'a Client,
}
impl<'a> CoinsApi<'a> {
pub fn new(client: &'a Client) -> Self {
Self { client }
}
/// List all coins (id, name, symbol)
pub async fn list(&self) -> Result<Vec<CoinListItem>> {
self.client.get("/coins/list").await
}
/// List coins with platform contract addresses
pub async fn list_with_platforms(&self) -> Result<Vec<CoinListItem>> {
self.client.get("/coins/list?include_platform=true").await
}
/// Get coin market data
///
/// # Example
/// ```no_run
/// # async fn example() -> gecko::error::Result<()> {
/// let client = gecko::Client::new()?;
/// let markets = client.coins().markets("usd").await?;
/// for coin in markets.iter().take(5) {
/// println!("{}: ${:.2}", coin.name, coin.current_price.unwrap_or(0.0));
/// }
/// # Ok(())
/// # }
/// ```
pub async fn markets(&self, vs_currency: &str) -> Result<Vec<CoinMarket>> {
let path = format!("/coins/markets?vs_currency={}", vs_currency);
self.client.get(&path).await
}
/// Get coin market data with options
pub async fn markets_with_options(
&self,
vs_currency: &str,
options: &MarketsOptions,
) -> Result<Vec<CoinMarket>> {
let path = format!(
"/coins/markets?vs_currency={}{}",
vs_currency,
options.to_query_string()
);
self.client.get(&path).await
}
/// Get coin data by ID
pub async fn get(&self, id: &str) -> Result<CoinData> {
let path = format!("/coins/{}", id);
self.client.get(&path).await
}
/// Get coin tickers
pub async fn tickers(&self, id: &str) -> Result<CoinTickers> {
let path = format!("/coins/{}/tickers", id);
self.client.get(&path).await
}
/// Get coin market chart
///
/// # Arguments
/// * `id` - Coin ID
/// * `vs_currency` - Target currency
/// * `days` - Data range (1, 7, 14, 30, 90, 180, 365, "max")
pub async fn market_chart(
&self,
id: &str,
vs_currency: &str,
days: &str,
) -> Result<MarketChart> {
let path = format!(
"/coins/{}/market_chart?vs_currency={}&days={}",
id, vs_currency, days
);
self.client.get(&path).await
}
/// Get coin market chart by date range
pub async fn market_chart_range(
&self,
id: &str,
vs_currency: &str,
from: u64,
to: u64,
) -> Result<MarketChart> {
let path = format!(
"/coins/{}/market_chart/range?vs_currency={}&from={}&to={}",
id, vs_currency, from, to
);
self.client.get(&path).await
}
/// Get OHLC data
///
/// # Arguments
/// * `id` - Coin ID
/// * `vs_currency` - Target currency
/// * `days` - Data range (1, 7, 14, 30, 90, 180, 365)
pub async fn ohlc(&self, id: &str, vs_currency: &str, days: u32) -> Result<OhlcData> {
let path = format!(
"/coins/{}/ohlc?vs_currency={}&days={}",
id, vs_currency, days
);
self.client.get(&path).await
}
/// Get coin historical data for a specific date
///
/// # Arguments
/// * `id` - Coin ID
/// * `date` - Date in dd-mm-yyyy format
pub async fn history(&self, id: &str, date: &str) -> Result<CoinHistory> {
let path = format!("/coins/{}/history?date={}", id, date);
self.client.get(&path).await
}
/// Get coin historical data with localization option
pub async fn history_with_localization(
&self,
id: &str,
date: &str,
localization: bool,
) -> Result<CoinHistory> {
let path = format!(
"/coins/{}/history?date={}&localization={}",
id, date, localization
);
self.client.get(&path).await
}
/// Get top gainers and losers
///
/// # Arguments
/// * `vs_currency` - Target currency (e.g., "usd")
/// * `duration` - Time duration: "1h", "24h", "7d", "14d", "30d", "60d", "1y"
pub async fn top_gainers_losers(
&self,
vs_currency: &str,
duration: &str,
) -> Result<TopMoversResponse> {
let path = format!(
"/coins/top_gainers_losers?vs_currency={}&duration={}",
vs_currency, duration
);
self.client.get(&path).await
}
/// Get recently added coins
pub async fn recently_added(&self) -> Result<Vec<RecentlyAddedCoin>> {
self.client.get("/coins/list/new").await
}
/// Get OHLC data by date range (Pro API only)
///
/// # Arguments
/// * `id` - Coin ID
/// * `vs_currency` - Target currency
/// * `from` - Unix timestamp start
/// * `to` - Unix timestamp end
pub async fn ohlc_range(
&self,
id: &str,
vs_currency: &str,
from: u64,
to: u64,
) -> Result<OhlcData> {
let path = format!(
"/coins/{}/ohlc/range?vs_currency={}&from={}&to={}",
id, vs_currency, from, to
);
self.client.get(&path).await
}
/// Get coin data by contract address
pub async fn by_contract(
&self,
platform_id: &str,
contract_address: &str,
) -> Result<CoinContractData> {
let path = format!("/coins/{}/contract/{}", platform_id, contract_address);
self.client.get(&path).await
}
/// Get market chart by contract address
pub async fn contract_market_chart(
&self,
platform_id: &str,
contract_address: &str,
vs_currency: &str,
days: &str,
) -> Result<MarketChart> {
let path = format!(
"/coins/{}/contract/{}/market_chart?vs_currency={}&days={}",
platform_id, contract_address, vs_currency, days
);
self.client.get(&path).await
}
/// Get market chart by contract address within date range
pub async fn contract_market_chart_range(
&self,
platform_id: &str,
contract_address: &str,
vs_currency: &str,
from: u64,
to: u64,
) -> Result<MarketChart> {
let path = format!(
"/coins/{}/contract/{}/market_chart/range?vs_currency={}&from={}&to={}",
platform_id, contract_address, vs_currency, from, to
);
self.client.get(&path).await
}
/// Get historical circulating supply chart (Enterprise API only)
///
/// # Arguments
/// * `id` - Coin ID
/// * `days` - Data range (any number, "max")
pub async fn circulating_supply_chart(&self, id: &str, days: &str) -> Result<SupplyChart> {
let path = format!("/coins/{}/circulating_supply_chart?days={}", id, days);
self.client.get(&path).await
}
/// Get historical circulating supply chart by date range (Enterprise API only)
pub async fn circulating_supply_chart_range(
&self,
id: &str,
from: u64,
to: u64,
) -> Result<SupplyChart> {
let path = format!(
"/coins/{}/circulating_supply_chart/range?from={}&to={}",
id, from, to
);
self.client.get(&path).await
}
/// Get historical total supply chart (Enterprise API only)
///
/// # Arguments
/// * `id` - Coin ID
/// * `days` - Data range (any number, "max")
pub async fn total_supply_chart(&self, id: &str, days: &str) -> Result<SupplyChart> {
let path = format!("/coins/{}/total_supply_chart?days={}", id, days);
self.client.get(&path).await
}
/// Get historical total supply chart by date range (Enterprise API only)
pub async fn total_supply_chart_range(
&self,
id: &str,
from: u64,
to: u64,
) -> Result<SupplyChart> {
let path = format!(
"/coins/{}/total_supply_chart/range?from={}&to={}",
id, from, to
);
self.client.get(&path).await
}
}