Reputation: 31
Is there an API for getting all spot-prices of supported with just one call ?
For now, it seems possible only for each currency pair e.g.) BTC-USD
However, I've found the following API to support it but it's not officially listed on the developer site
https://api.coinbase.com/v2/prices/usd/spot
Can I use this API for getting all price data of all supported coins ?
Thanks
Upvotes: 2
Views: 5334
Reputation: 4446
I believe the only way to get the prices for all coins in a single request is to use the exchange-rates endpoint but it gets more than what coinbase trades and since this tells you how much you can get for 1 USD, you have to do the 1/rate
math to get the price.
for example
1 ATOM = 1 / 0.04149635869452455 = $24.0985
https://api.coinbase.com/v2/exchange-rates?currency=USD
{
"data": {
"currency": "USD",
"rates": {
"AED": "3.672973",
"AFN": "97.372693",
"ALL": "107.034241",
"AMD": "490.957033",
"ANG": "1.803208",
"AOA": "564",
"ARS": "101.5085",
"AUD": "1.399191",
"AWG": "1.8",
"AZN": "1.700805",
"BAM": "1.729247",
"BBD": "2",
"BDT": "85.824273",
"BGN": "1.72742",
"BHD": "0.377048",
"BIF": "1994.142167",
"BMD": "1",
"BND": "1.366618",
"BOB": "6.898625",
"BRL": "5.552737",
"BSD": "1",
"BTN": "75.524027",
"BWP": "11.716473",
"BYN": "2.536338",
...
}}}
Otherwise you'd probably need to get all the products and get the ticker price for each product but you'd have to throttle it so you don't make to many requests per second.
loop the results from
https://api.exchange.coinbase.com/products
and use
https://api.exchange.coinbase.com/products/{product_id}/ticker
to get the price.
Upvotes: 5