I can't seem to get any price besides Bitcoin. Needing a little help with this.
I'm using this library and I'm afraid it's not being maintained: https://github.com/coinbase/coinbase-python
This works:
#!/usr/bin/python
from coinbase.wallet.client import Client
api_key = "<my key>"
api_secret = "<my secret>"
client = Client(api_key, api_secret)
price = client.get_buy_price(currency_pair = 'BTC')
print price
But this call brings back the exact same response even though I've specified LTC. I've also tried ETH and BCH and none of those work either.
#!/usr/bin/python
from coinbase.wallet.client import Client
api_key = "<my key>"
api_secret = "<my secret>"
client = Client(api_key, api_secret)
price = client.get_buy_price(currency_pair = 'LTC')
print price
Both give this exact same response:
{
"amount": "13155.51",
"base": "BTC",
"currency": "USD"
}
You can see that the currency ids aren't valid by calling client.get_currencies()
:
from coinbase.wallet.client import Client
api_key = "<Your API Key>"
api_secret = "<Your API Secret>"
client = Client(api_key, api_secret)
currencies = client.get_currencies()
names = [currency["id"] for currency in currencies["data"]]
print("LTC" in names)
print("ETH" in names)
print("BCH" in names)
This prints:
False
False
False
You can get a list of currency ids and their name like so:
from coinbase.wallet.client import Client
api_key = "<Your API Key>"
api_secret = "<Your API Secret>"
client = Client(api_key, api_secret)
currencies = client.get_currencies()
for currency in currencies["data"]:
print(currency["id"], currency["name"])
This prints out:
AED United Arab Emirates Dirham
AFN Afghan Afghani
ALL Albanian Lek
AMD Armenian Dram
ANG Netherlands Antillean Gulden
AOA Angolan Kwanza
ARS Argentine Peso
AUD Australian Dollar
AWG Aruban Florin
AZN Azerbaijani Manat
BAM Bosnia and Herzegovina Convertible Mark
BBD Barbadian Dollar
BDT Bangladeshi Taka
BGN Bulgarian Lev
BHD Bahraini Dinar
BIF Burundian Franc
...
...
...
Although, it does seem the same thing is happening to me with the prices being the same..:
print(client.get_buy_price(currency_pair="BTC-USD"))
print(client.get_buy_price(currency_pair="CAD-USD"))
also gives the same result:
{
"amount": "13142.02",
"base": "BTC",
"currency": "USD"
}
{
"amount": "13142.02",
"base": "BTC",
"currency": "USD"
}
If the api isn't being maintained, then I would recommend you look around for another api that can provide what you need.
I used this approach and it's working for me:
rates = client.get_exchange_rates(currency='LTC')
rate = rates['rates']['EUR']
But the prices doesn't seem to be updating very often. Hope this helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.