以太坊历史价格 - Coinbase API
Historical ethereum prices - Coinbase API
使用 python coinbase API-- 函数-- get_buy_price
、get_sell_price
、get_spot_price
、get_historical_data
等。 .. 似乎都只 return 比特币价格。有没有办法查询以太坊价格?
似乎可以将 currency_pair = 'BTC-USD'
更改为类似于 currency_pair = 'ETH-USD'
的内容,尽管这没有任何效果。
我希望 API 根本不支持这一点,除了官方文档明确指出:
Get the total price to buy one bitcoin or ether
我可以通过在 buy/sell 请求中使用 quote='true'
标志来解决这个问题。然而,这只能向前推进,我想要历史数据。
source code永远是你的朋友。
def get_spot_price(self, **params):
"""https://developers.coinbase.com/api/v2#get-spot-price"""
if 'currency_pair' in params:
currency_pair = params['currency_pair']
else:
currency_pair = 'BTC-USD'
response = self._get('v2', 'prices', currency_pair, 'spot', data=params)
return self._make_api_object(response, APIObject)
def get_historic_prices(self, **params):
"""https://developers.coinbase.com/api/v2#get-historic-prices"""
response = self._get('v2', 'prices', 'historic', data=params)
return self._make_api_object(response, APIObject)
我们可以看到这两个函数调用相同的 api 端点。我们看到 get_spot_price
支持 currency_pair
参数并将其作为 api 调用的一部分传递。另一方面 get_historic_prices
没有。
我想知道如果这样做会发生什么。让我们试试吧:
from coinbase.wallet.client import Client
from coinbase.wallet.model import APIObject
client = Client(api_key, api_secret)
client._make_api_object(client._get('v2', 'prices', 'ETH-USD', 'historic'), APIObject)
<APIObject @ 0x10dd04938> {
"currency": "USD",
"prices": [
{
"price": "52.60",
"time": "2017-03-30T17:03:48Z"
},
{
"price": "52.60",
"time": "2017-03-30T17:03:38Z"
},
{
"price": "52.54",
"time": "2017-03-30T17:03:28Z"
},
{
"price": "52.54",
"time": "2017-03-30T17:03:18Z"
},
{
"price": "52.54",
"time": "2017-03-30T17:03:08Z"
},
{
"price": "52.53",
"time": "2017-03-30T17:02:58Z"
},
{
"price": "52.53",
"time": "2017-03-30T17:02:48Z"
},
{
"price": "52.53",
"time": "2017-03-30T17:02:38Z"
},
{
"price": "52.53",
"time": "2017-03-30T17:02:28Z"
},
.....
成功!
我会按照他们的方式发送 PR。但现在您可以使用我的代码片段。
我尝试了这个,但遇到了一个问题,即使用 'currency_pair' 参数和 'historic' 参数将只生成过去几天的 1 秒粒度的历史记录。
我通过使用 GDAX 客户端 API 以及 GDAX Python client:
解决了这个问题
安装GDAXPython客户端:
pip install gdax
那么即使没有GDAX账户也可以使用public API部分:
import gdax
client = gdax.PublicClient()
client.get_product_historic_rates('ETH-USD', granularity=60*60*24)
要获取可用产品列表(加密货币/法定货币对),请使用
client.get_products()
并扫描 ID 条目。
我遇到了类似的汇率问题,对我有用。
尝试更改
中的参数
coinbase\wallet\client.py
来自
response = self._get('v2', 'prices', 'spot', data=params)
至
response = self._get('v2', 'prices', 'spot', params=params)
使用 python coinbase API-- 函数-- get_buy_price
、get_sell_price
、get_spot_price
、get_historical_data
等。 .. 似乎都只 return 比特币价格。有没有办法查询以太坊价格?
似乎可以将 currency_pair = 'BTC-USD'
更改为类似于 currency_pair = 'ETH-USD'
的内容,尽管这没有任何效果。
我希望 API 根本不支持这一点,除了官方文档明确指出:
Get the total price to buy one bitcoin or ether
我可以通过在 buy/sell 请求中使用 quote='true'
标志来解决这个问题。然而,这只能向前推进,我想要历史数据。
source code永远是你的朋友。
def get_spot_price(self, **params):
"""https://developers.coinbase.com/api/v2#get-spot-price"""
if 'currency_pair' in params:
currency_pair = params['currency_pair']
else:
currency_pair = 'BTC-USD'
response = self._get('v2', 'prices', currency_pair, 'spot', data=params)
return self._make_api_object(response, APIObject)
def get_historic_prices(self, **params):
"""https://developers.coinbase.com/api/v2#get-historic-prices"""
response = self._get('v2', 'prices', 'historic', data=params)
return self._make_api_object(response, APIObject)
我们可以看到这两个函数调用相同的 api 端点。我们看到 get_spot_price
支持 currency_pair
参数并将其作为 api 调用的一部分传递。另一方面 get_historic_prices
没有。
我想知道如果这样做会发生什么。让我们试试吧:
from coinbase.wallet.client import Client
from coinbase.wallet.model import APIObject
client = Client(api_key, api_secret)
client._make_api_object(client._get('v2', 'prices', 'ETH-USD', 'historic'), APIObject)
<APIObject @ 0x10dd04938> {
"currency": "USD",
"prices": [
{
"price": "52.60",
"time": "2017-03-30T17:03:48Z"
},
{
"price": "52.60",
"time": "2017-03-30T17:03:38Z"
},
{
"price": "52.54",
"time": "2017-03-30T17:03:28Z"
},
{
"price": "52.54",
"time": "2017-03-30T17:03:18Z"
},
{
"price": "52.54",
"time": "2017-03-30T17:03:08Z"
},
{
"price": "52.53",
"time": "2017-03-30T17:02:58Z"
},
{
"price": "52.53",
"time": "2017-03-30T17:02:48Z"
},
{
"price": "52.53",
"time": "2017-03-30T17:02:38Z"
},
{
"price": "52.53",
"time": "2017-03-30T17:02:28Z"
},
.....
成功!
我会按照他们的方式发送 PR。但现在您可以使用我的代码片段。
我尝试了这个,但遇到了一个问题,即使用 'currency_pair' 参数和 'historic' 参数将只生成过去几天的 1 秒粒度的历史记录。
我通过使用 GDAX 客户端 API 以及 GDAX Python client:
解决了这个问题安装GDAXPython客户端:
pip install gdax
那么即使没有GDAX账户也可以使用public API部分:
import gdax
client = gdax.PublicClient()
client.get_product_historic_rates('ETH-USD', granularity=60*60*24)
要获取可用产品列表(加密货币/法定货币对),请使用
client.get_products()
并扫描 ID 条目。
我遇到了类似的汇率问题,对我有用。 尝试更改
中的参数coinbase\wallet\client.py
来自
response = self._get('v2', 'prices', 'spot', data=params)
至
response = self._get('v2', 'prices', 'spot', params=params)