You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

如何通过Coinbase API获取以太坊价格数据?仅找到比特币相关方法

Fetching Ethereum Price Data via Coinbase API

Hey there! Great question—you absolutely can pull Ethereum (ETH) price data using the Coinbase API, even if the initial examples you found focused on Bitcoin. The core endpoints work the same way; you just need to adjust the currency pair parameter.

Using the Spot Price Endpoint

The simplest way to get the current ETH spot price is with the public /v2/prices/{currency_pair}/spot endpoint. No API keys are required for this public data.

Example with curl:

curl https://api.coinbase.com/v2/prices/ETH-USD/spot

Example with Python (using requests):

import requests

response = requests.get("https://api.coinbase.com/v2/prices/ETH-USD/spot")
if response.status_code == 200:
    eth_price = response.json()["data"]["amount"]
    print(f"Current ETH-USD price: ${eth_price}")
else:
    print(f"Error fetching data: {response.status_code}")

You can swap out USD for other fiat currencies too (like EUR, GBP, etc.) by changing the currency pair to ETH-EUR, ETH-GBP, etc.

Fetching Historical Price Data

If you need historical ETH prices, use the /v2/prices/{currency_pair}/historic endpoint. You can add query parameters to specify a date range:

Example curl for a 7-day date range:

curl "https://api.coinbase.com/v2/prices/ETH-USD/historic?start=2024-05-01T00:00:00Z&end=2024-05-07T23:59:59Z"

The response will include a list of timestamped price points you can parse for trends or analysis.

Quick Note

The Coinbase API docs do cover this, but sometimes examples are Bitcoin-focused. Just remember that any endpoint using a currency_pair parameter works with Ethereum (and most other supported assets) by replacing BTC with ETH in the pair string.

内容的提问来源于stack exchange,提问作者Siddharth Saxena

火山引擎 最新活动