Description
This is my exact issue as well. Got halfway through writing this when I saw this post, so tacking on here.
I am attempting to use the Coinbase Pro Exchange API to convert between ETH and BTC within the Coinbase Pro account that I have. I am unable to successfully complete this conversion and am only receiving an error message stating:
{
"message": "Cannot convert ETH to BTC"
}
What I have tried
I have created an API key for the profile containing my ETH and BTC balances and grated it all three of View/Transfer/Trade permissions. I am able to successfully execute a GET
request against the API and return info about my account. This aligns accurately with what is online and on the app. No issues there. Now, when I attempt a POST
request as outlined in the documentation here I am unable to actually perform a successful conversion because of the above error. Nowhere online can I find that you are not allowed to convert between ETH and BTC, yet the API is preventing me from doing so.
Minimum Reproducible Example
I am using Python 3.9.2 with the following requirements installed:
certifi==2021.10.8
charset-normalizer==2.0.12
idna==3.3
requests==2.27.1
urllib3==1.26.9
and this being the minimum code example to reproduce the issue I am experiencing:
import base64
import hashlib
import hmac
import os
import time
import requests
from requests.auth import AuthBase
class CoinbaseAuth(AuthBase):
def __init__(self, api_key, secret_key, passphrase):
self.api_key = api_key or os.getenv("API_KEY")
self.secret_key = secret_key or os.getenv("SECRET_KEY")
self.passphrase = passphrase or os.getenv("PASSPHRASE")
def __call__(self, request):
timestamp = str(int(time.time()))
message = (
timestamp
+ request.method
+ request.path_url
+ (request.body.decode("utf8") if request.body else "")
)
sk = base64.b64decode(self.secret_key)
hmac_signature = hmac.new(
key=sk,
msg=message.encode("utf8),
digestmod=hashlib.sha256,
)
signature = base64.b64encode(hmac_signature.digest()).decode("utf8")
headers = {
"Accept": "application/json",
"Content-Type": "application/json",
"CB-ACCESS-KEY": self.api_key,
"CB-ACCESS-SIGN": signature,
"CB-ACCESS-TIMESTAMP": timestamp,
"CB-ACCESS-PASSPHRASE": self.passphrase,
}
request.headers.update(headers)
return request
auth = CoinbaseAuth(
api_key='<my-api-key>',
secret_key='<my-secret-key>',
passphrase='<my-passphrase>',
)
profile_response = requests.get("https://api.exchange.coinbase.com/profiles", auth=auth)
profiles = response.json()
# I only have 1 profile, but one could iterate through to find the default
profile_id = profiles[0]['id']
conversion_response = requests.post(
"https://api.exchange.coinbase.com/conversions",
auth=auth,
json={
"profile_id": profile_id,
"amount": "0.0002",
"from": "ETH",
"to": "BTC",
},
)
print(f"Status Code: {conversion_response.status_code}")
print(f'Response Body: {conversion_response.content.decode("utf8")}')
and the above code snippet should output the following (because it does for me):
Status Code: 400
Response Body: {"message":"Cannot convert ETH to BTC"}
I just saw this persons issue and it is my exact issue. We should be able to convert between any 2 currencies and not need to use USDC
as an intermediary. The Coinbase app allows you to do this so why wouldn’t the “Pro” app also support this same feature?