Skip to content

Commit 3d850e6

Browse files
authored
coin-gecko: Add user-agent to requests (#24)
#### Problem The public Coin Gecko API isn't working with an error of: ``` {"status":{"error_code":403,"error_message":"Please add a descriptive User-Agent to your request. For higher rate limits & stable integration, please subscribe to our API plans: https://www.coingecko.com/en/api/pricing . If you think this is a mistake, please report here: https://forms.gle/3V2z8Mb3k2RMu5S2A"}} ``` #### Summary of changes Add a user-agent of "sys" so the requests work.
1 parent 3ca1c80 commit 3d850e6

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

src/coin_gecko.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ pub async fn get_current_price(token: &MaybeToken) -> Result<Decimal, Box<dyn st
127127
pyusd: Option<CurrencyList>,
128128
}
129129

130-
let coins = reqwest::get(url).await?.json::<Coins>().await?;
130+
let client = reqwest::Client::builder().user_agent("sys").build()?;
131+
let coins = client.get(url).send().await?.json::<Coins>().await?;
131132

132133
coins
133134
.solana
@@ -184,7 +185,10 @@ pub async fn get_historical_price(
184185
when.year()
185186
);
186187

187-
reqwest::get(url)
188+
let client = reqwest::Client::builder().user_agent("sys").build()?;
189+
client
190+
.get(url)
191+
.send()
188192
.await?
189193
.json::<HistoryResponse>()
190194
.await?

0 commit comments

Comments
 (0)