GithubHelp home page GithubHelp logo

Comments (7)

JLDevOps avatar JLDevOps commented on August 23, 2024 1

I'm getting the same issue, but have found the solution. In your python library, if you installed via pip, go to /site-packages/coinbase/wallet/client.py:

Change this section:

 def get_spot_price(self, **params):
    """https://developers.coinbase.com/api/v2#get-spot-price"""
    response = self._get('v2', 'prices', 'spot', data=params)
    return self._make_api_object(response, APIObject)

to:

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)

This will get you the correct results for ETH-USD prices.

The problem now is that, the client.py file in the repo has already been updated to the code above, but has not been pushed for pip installation, so either you install the package from the repo or have to go in and change the settings in Python.


Update:
If you don't like that option above (like messing with the client file), put this in your "own" python file:

def _get_COIN_prices_(price_option, coin_option, currency):
    """ Gets the prices of coins with "coin_option"
        "coin_options" = BTC, ETH, LTC
        "price_options" = buy, sell, spot
        "currency" = USD, EUR, etc

        Base API endpoint = "https://api.coinbase.com/v2/prices/

        Currently using version 2, if you want to use version 1, switch to:
        Base API endpoint = "https://api.coinbase.com/v1/prices/
    """
    url = "https://api.coinbase.com/v2/prices/" + coin_option + "-" + currency + "/" + price_option
    header = ({'Accept': 'application/json',
               'Content-Type': 'application/json',
               'User-Agent': 'coinbase/python/2.0'})
    response = requests.get(url, headers=header)
    jsonData = json.loads(response.content)
    return jsonData

Then in your main method do:

coin_price = _get_COIN_prices_("buy", "ETH", "USD")
ETH_price = coin_price['data']['amount']
print ETH_price

from coinbase-python.

mavieth avatar mavieth commented on August 23, 2024

Same issue.

from coinbase-python.

spiliopoulos avatar spiliopoulos commented on August 23, 2024

Take a look at my comment here . It might be that you have not updated your api version.

from coinbase-python.

jasonmellone avatar jasonmellone commented on August 23, 2024

I'm on 2.0.6 and getting the issue. I don't think this is a version thing.

from coinbase-python.

jasonmellone avatar jasonmellone commented on August 23, 2024

I chose to modify the client.py directly. Thanks

from coinbase-python.

lyx-x avatar lyx-x commented on August 23, 2024

This may be a silly question. I installed coinbase via pip(3). The package I got includes the old version of client where the 'currency_pair' isn't used. Will we get a new release or it is recommended to install from source?

from coinbase-python.

mego1st avatar mego1st commented on August 23, 2024

Just to update, if anyone is using the code above, changing

price = client.get_spot_price(currency_code = 'ETH-USD')

to

price = client.get_spot_price(currency_pair = 'ETH-USD')

makes the code work as intended.

from coinbase-python.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.