coinbase / coinbase-python

DEPRECATED — Coinbase Python API
Apache License 2.0
528 stars 217 forks source link

EUR-Wallet: APIError (id=invalid_request): Can't buy with this account #58

Closed jojohnjo closed 6 years ago

jojohnjo commented 6 years ago

Dear guys,

i am trying to do a trade on coinbase via script. I can pull the prices, i get the account data, the payment methods and so on....finally i would like to buy some coins with my EUR-Wallet. There is some amount of money on this account for testing purposes. The ID of the payment method etc shall be chosen correctly but nevertheless the error above in the headline arises. I would be glad for your experiences and help;) with kind regards, John

In the following ,i will try to describe all the actions done in my script for reproducing this error:

accounts=client.get_accounts()       #get my accounts (i have EUR-Wallet, ETH, LTC and BTC Accounts)
payment_method=client.get_payment_methods()[0]     #Chooses the EUR-Wallet as my paymentmethod

account=client.get_account("abcdefghihklmnoqrstuvwxyz") # Argument is the ID of EUR-Wallet

buy = account.buy(amount='0.00001', currency="LTC", payment_method=payment_method.id)

print payment_method 

shows:

{
  "allow_buy": true, 
  "allow_deposit": true, 
  "allow_sell": true, 
  "allow_withdraw": true, 
  "created_at": "2017-10-09T19:12:29Z", 
  "currency": "EUR", 
  "fiat_account": {
    "id": "abcdefghihklmnoqrstuvwxyz", 
    "resource": "account", 
    "resource_path": "/v2/accounts/abcdefghihklmnoqrstuvwxyz"
  }, 
  "id": "1234567891011121314151617", 
  "instant_buy": true, 
  "instant_sell": true, 
  "limits": {
    "buy": [
      {
        "description": "\u20ac9,000 of your \u20ac9,000 weekly Coinbase account limit remaining", 
        "label": "Total EUR limit", 
        "next_requirement": {
          "type": "identity_verification"
        }, 
        "period_in_days": 7, 
        "remaining": {
          "amount": "9000.00", 
          "currency": "EUR"
        }, 
        "total": {
          "amount": "9000.00", 
          "currency": "EUR"
        }
      }
    ], 
    "name": "Coinbase Account", 
    "sell": [
      {
        "description": "\u20ac9,000 of your \u20ac9,000 weekly Coinbase account limit remaining", 
        "label": "Total EUR limit", 
        "next_requirement": {
          "type": "identity_verification"
        }, 
        "period_in_days": 7, 
        "remaining": {
          "amount": "9000.00", 
          "currency": "EUR"
        }, 
        "total": {
          "amount": "9000.00", 
          "currency": "EUR"
        }
      }
    ], 
    "type": "fiat_account"
  }, 
  "name": "EUR Wallet", 
  "primary_buy": true, 
  "primary_sell": true, 
  "resource": "payment_method", 
  "resource_path": "/v2/payment-methods/1234567891011121314151617", 
  "type": "fiat_account", 
  "updated_at": "2017-10-09T19:12:29Z", 
  "verified": true
}

So as you can see i have the correct payment_method ID as well as the correct EUR-Wallet ID. And all my accounts are allowed to deal with the whole set of requests that coinbase API can offer. this is done in the configuration on my coinbase account. I would be glad for support.

This is the full error message:

Traceback (most recent call last):
  File "/home/pi/Desktop/First_Script.py", line 265, in <module>
    payment_method=payment_method.id)
  File "/usr/local/lib/python2.7/dist-packages/coinbase-2.0.6-py2.7.egg/coinbase/wallet/model.py", line 200, in buy
    return self.api_client.buy(self.id, **params)
  File "/usr/local/lib/python2.7/dist-packages/coinbase-2.0.6-py2.7.egg/coinbase/wallet/client.py", line 381, in buy
    response = self._post('v2', 'accounts', account_id, 'buys', data=params)
  File "/usr/local/lib/python2.7/dist-packages/coinbase-2.0.6-py2.7.egg/coinbase/wallet/client.py", line 132, in _post
    return self._request('post', *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/coinbase-2.0.6-py2.7.egg/coinbase/wallet/client.py", line 116, in _request
    return self._handle_response(response)
  File "/usr/local/lib/python2.7/dist-packages/coinbase-2.0.6-py2.7.egg/coinbase/wallet/client.py", line 125, in _handle_response
    raise build_api_error(response)
InvalidRequestError: APIError(id=invalid_request): Can't buy with this account

and this the relevant section in the package that throws the error:

def _request(self, method, *relative_path_parts, **kwargs):
    """Internal helper for creating HTTP requests to the Coinbase API.

    Raises an APIError if the response is not 20X. Otherwise, returns the
    response object. Not intended for direct use by API consumers.
    """
    uri = self._create_api_uri(*relative_path_parts)
    data = kwargs.get('data', None)
    if data and isinstance(data, dict):
      kwargs['data'] = encode_params(data)
    if self.VERIFY_SSL:
      kwargs.setdefault('verify', COINBASE_CRT_PATH)
    else:
      kwargs.setdefault('verify', False)
    kwargs.update(verify=self.VERIFY_SSL)
    response = getattr(self.session, method)(uri, **kwargs)
    return self._handle_response(response)

  def _handle_response(self, response):
    """Internal helper for handling API responses from the Coinbase server.

    Raises the appropriate exceptions when necessary; otherwise, returns the
    response.
    """
    if not str(response.status_code).startswith('2'):
      raise build_api_error(response)
    return response

  def _get(self, *args, **kwargs):
    return self._request('get', *args, **kwargs)

  def _post(self, *args, **kwargs):
    return self._request('post', *args, **kwargs)

  def _put(self, *args, **kwargs):
    return self._request('put', *args, **kwargs)
sds commented 6 years ago

Hey @jojohnjo, strongly recommend you contact our support team to understand what is going on with your account. Thanks!