Existing Ethereum Price - Coinbase API

Asked 2 years ago, Updated 2 years ago, 124 views

Using the Python coinbase API, functions such as -- get_buy_price, get_sell_price, get_spot_price, and get_historical_data seem to return only bitcoin prices. Is there any way to know the Ethereum price?

current_pair='BTC-USD' does not work if it appears to be similarly changeable, such as current_pair='ETH-USD'

Officially supported by documentation

Get the total price to buy one bitcoin or ether

With the exception of , we expect the API to simply not support this.

The quote='true' flag can be used to resolve this issue for purchase/sales requests, but this is only forward, so we want existing data.

python python-3.x ethereum coinbase-api

2022-09-21 15:14

3 Answers

The source code will always be your friend.

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)

You can see that both functions call the same API last point. You can see that get_spot_price supports current_pair and passes it as part of an API call, but get_historic_presses does not.

What will happen if it is possible :

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"
        },
        .....

It's a success I can use my code snippet now before I send it for publicity.


2022-09-21 15:14

For the past few days, when I tried this, I had the problem that using the 'current_pair' parameter with the 'old' parameter would produce a one-second granularity record.

So instead, we used the GDAX client API with the GDAX Python client to solve this problem.

Installing the GDAX Python client:

pip install gdax 

You can then use some of the public APIs without a GDAX account.

import gdax

client = gdax.PublicClient()
client.get_product_historic_rates('ETH-USD', granularity=60*60*24)

To obtain an available list (cryptocurrency or FIAT current pair)

 client.get_products() 

Use to search for id objects.


2022-09-21 15:14

It was helpful that I had a similar problem due to the exchange rate problem.

coinbase\wallet\client.py

From

response = self._get('v2', 'prices', 'spot', data=params) B

response = self._get('v2', 'prices', 'spot', params=params)

Change the parameters to .


2022-09-21 15:14

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.