0

Python 3.4 Coinbase 钱包 API V2


一段时间以来,我一直试图弄清楚这个购买调用(以及其他 api 调用,如 get_payment_methods() 和 get_accounts() )是否遇到身份验证错误。我已经成功地能够在单独的文件中单独运行其中一些 api 调用。


什么不起作用

class api_call(object):                                                                                                           

      def __init__(self):                                                                                                           
          self.CB_key = xxxxxxxx                                                                                                        
          self.CB_secret = yyyyyyyy                                                                                                    
          self.CB_account = zzzzzzzzz                                                                                                    
          self.CB_payment_method = aaaaaaaaaa

      def buy_c(self, exchange, b_amount):                                                                                
          client = Client(self.CB_key, self.CB_secret)                                                                          
          buy = client.buy(self.CB_account, amount=str(b_amount), currency="USD", payment_method=self.CB_payment_method)

api = api_call()
buy = api.buy('COIN-BS', 1)

我已经三次检查了我的帐户、密钥和机密,并且还尝试在类定义中对它们进行硬编码,而不是使用init成员。


什么有效:

 from coinbase.wallet.client import Client
 client = Client(<api_key>, <api_secret>)

 buy = client.buy('zzzzzzzz', amount='1', currency="USD", payment_method='aaaaaaaaaa')

错误如下:

Traceback (most recent call last):
File "api_call.py", line 126, in <module>
   buy = api.buy('COIN-BS', 1)
File "api_call.py", line 110, in buy
   buy = client.buy_c( self.CB_account, amount=str(amount), currency="USD", payment_method="XXXXXXXXXXXX")
File "/home/LA/.local/lib/python3.4/site-packages/coinbase/wallet/client.py", line 381, in buy
   response = self._post('v2', 'accounts', account_id, 'buys', data=params)
File "/home/LA/.local/lib/python3.4/site-packages/coinbase/wallet/client.py", line 132, in _post
   return self._request('post', *args, **kwargs)
File "/home/LA/.local/lib/python3.4/site-packages/coinbase/wallet/client.py", line 116, in _request
   return self._handle_response(response)
File "/home/LA/.local/lib/python3.4/site-packages/coinbase/wallet/client.py", line 125, in _handle_response
   raise build_api_error(response)

coinbase.wallet.error.AuthenticationError: APIError(id=authentication_error): invalid signature

我认为问题可能是由于在类文件的定义中使用了 API 购买方法,即我的 api_call.py 类。我认为这是因为我可以调用购买方法(和其他方法)就好了单独的文件,甚至在 api_call.py 内的类缩进之外。


有谁知道为什么这会引发身份验证错误?我在error.py中环顾四周,但还没有找到关于为什么会发生这种情况的线索。

与往常一样,非常感谢您对此事的任何帮助或想法!


编辑

在同一个文件上运行工作代码和非工作代码后,我成功地进行了两次购买。在尝试了其他一些事情之后,我发现显然任何使用这些全局修改变量、命令行参数和更新的对象成员变量的 API POST 都会产生此身份验证错误。这应该发生吗?

from coinbase.wallet.client import Client

#Globals
key = 'xxxxxx'
secret = 'yyyyyy'
account = 'zzzzzzz'
payment = 'aaaaaaa'

class api_call(object):                                                                                                           

  def __init__(self):                                                                                                           
      self.CB_key = None                                                                                                        
      self.CB_secret = None                                                                                                    
      self.CB_account = None                                                                                                    
      self.CB_payment_method = None

  def buy_c(self, exchange, b_amount):                                                                                
      client = Client(key, secret)                                                                          
      buy = client.buy(account, amount=str(b_amount), currency="USD", payment_method=payment)

client = Client(key, secret)
buy = client.buy(account, amount='1', currency="USD", payment_method=payment)

api = api_call()
buy = api.buy_c('COIN-BS', 1)
4

1 回答 1

0

经过广泛的静态分析,我得出结论,这可能是您的问题。

buy = api.buy('COIN-BS', 1) -> buy = api.buy_c('COIN-BS', 1)

还要弄清楚为什么你的堆栈跟踪有client.buy_c而不是client.buy

于 2016-06-23T00:50:54.430 回答