0

I am trying to create an ether buy and sell bot on coinbase. They have a truly wonderfull description on their developer page. There is one thing I am missing.

Somehow all functions automatically refer to bitcoin and not to ether. I assume there is a setting to change that in the code but I am not finding or succeeding in this. All examples on their developer page are with bitcoin. For example:

buy_price = client.get_buy_price(currency = 'EUR') 

This returns: amount, base and currency. So I noticed I can change the currency. Now I tried to change the base with

buy_price = client.get_buy_price(currency = 'EUR', base = 'ETH') 

It still returns BTC (bitcoin) as base.

Hope someone can help me out here.

Zuenie
  • 963
  • 2
  • 11
  • 30

1 Answers1

1

Try this:

buy_price = client.get_buy_price(currency_pair = 'ETH-USD')

From https://developers.coinbase.com/api/v2#get-exchange-rates

EDIT: the Python API seems not to work. But the raw GET request works, so here's a replacement function for you:

import urllib.request
import json

def myGetBuyPrice(crypto, fiat):
    ret = (urllib.request.urlopen("https://api.coinbase.com/v2/prices/"+crypto+"-"+fiat+"/buy").read()).decode("utf-8") 
    return json.loads(ret)["data"]

print myGetBuyPrice("ETH", "USD")