咨询:能否通过Coinbase API获取实时全量汇率?
Hey there! Great question—let me clear this up for you.
First off, you're totally right about the https://coinbase.com/api/v1/currencies/exchange_rates endpoint: it only updates once per day, so it's not suitable for real-time rate needs.
Luckily, Coinbase provides a v2 API endpoint that delivers real-time (or near-real-time) exchange rates. Here's what you need to know:
- The correct endpoint is
GET /v2/exchange-rates - You can specify a base currency using the
currencyquery parameter (e.g.,?currency=USDto get rates relative to US Dollars) - This endpoint returns up-to-date rates that reflect current market conditions, unlike the v1 version.
Example Request
If you send a request like this:
GET https://api.coinbase.com/v2/exchange-rates?currency=USD
You'll get a response containing real-time rates for a wide range of currencies, structured like this (simplified):
{ "data": { "currency": "USD", "rates": { "BTC": "0.000023", "EUR": "0.92", "GBP": "0.79", // ... many more currencies } } }
A quick note: While this endpoint is publicly accessible (no API key required for basic use), if you're integrating it into a production app, make sure to follow Coinbase's API rate limits and guidelines to avoid issues.
So to wrap up: ditch the v1 endpoint and use the v2 /v2/exchange-rates endpoint, and you'll get the real-time exchange rates you need.
内容的提问来源于stack exchange,提问作者Christose




