简体   繁体   English

coinbase-api python库入门

[英]coinbase-api python library getting started

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 我正在使用此库,但恐怕无法对其进行维护: 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. 但是,即使我指定了LTC,此调用也会返回完全相同的响应。 I've also tried ETH and BCH and none of those work either. 我也尝试过ETH和BCH,但这些都不起作用。

#!/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"
}

TLDR; TLDR; From my findings, all of the currency buy prices from this api are all sending the same results, as you said. 根据您的发现,从我的发现来看,此api的所有货币购买价格都发送相同的结果。 With that being said, the currency names you are trying to use aren't in the list of supported currencies. 话虽如此,您要使用的货币名称不在受支持的货币列表中。 I would advise finding an alternative to this api. 我建议您找到此API的替代方法。

You can see that the currency ids aren't valid by calling client.get_currencies() : 您可以通过调用client.get_currencies()来查看货币ID无效:

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: 您可以像这样获取货币ID及其名称的列表:

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. 如果没有维护该api,那么我建议您到处看看可以提供所需内容的另一个api。

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. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM