Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coinbase Advanced Trader 401 Unauthorized Issue #22182

Open
tazengineering opened this issue Apr 17, 2024 · 17 comments
Open

Coinbase Advanced Trader 401 Unauthorized Issue #22182

tazengineering opened this issue Apr 17, 2024 · 17 comments
Assignees
Labels

Comments

@tazengineering
Copy link

Operating System

Windows

Programming Languages

Python

CCXT Version

4.2.64

Description

Issue when attempting to connect to Coinbase Advanced Trade.

Error: AuthenticationError: coinbase GET https://api.coinbase.com/api/v3/brokerage/products 401 Unauthorized Unauthorized

I have tried with both apiKey and Secret simplified or the full text shown when generating the API.

Code

import ccxt

# Connects to Binance
exchange = ccxt.coinbase({
    'apiKey': "organizations/XXXXXXXXXXXXXXXXXXXX/apiKeys/XXXXXXXXXXXXXXXXXXXXX",
    'secret': "-----BEGIN EC PRIVATE KEY-----\nXXXXXXXXXXXXXXXXXXXXXXXXXXX\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX//XXXXX/XXXXXXXXXXXXXX\nXXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX==\n-----END EC PRIVATE KEY-----\n",
})


# Define lot sizes for each symbol
lot_sizes = {'BTC/USDT:USDT': 0.001,
             'ETH/USDT:USDT': 0.01,
             'DOGE/USDT:USDT': 100,
             'BNB/USDT:USDT': 0.01,
             'ADA/USDT:USDT': 10,
             'EGLD/USDT:USDT': 0.01,
             'MATIC/USDT:USDT': 10,
             'TRX/USDT:USDT': 100,
             'LTC/USDT:USDT': 0.1,
             'SOL/USDT:USDT': 0.1}

# Get the account balance
balance = exchange.fetch_balance()
total_funds = float(balance['total']['USDT'])
#print(balance['info'])
print(total_funds)

@carlosmiei carlosmiei self-assigned this Apr 17, 2024
@carlosmiei
Copy link
Collaborator

Hello @tazengineering, cloud keys support was introduced recently, so you need to update your ccxt version to get it

@tazengineering
Copy link
Author

Hi @carlosmiei

I have updated to ccxt-4.2.100 and the issue persists.

@carlosmiei
Copy link
Collaborator

@tazengineering Can you please double-check your api keys/permissions/ip restrictions/etc?
I'm using it right now and seems to be working

@tazengineering
Copy link
Author

tazengineering commented Apr 17, 2024

@carlosmiei

Thank you for taking the time to support me.

Are you using the same format for API key and secret I shared?

I removed completely any IP restrictions.

Where do you setup permissions from?

Regards
Ciprian

@carlosmiei
Copy link
Collaborator

@tazengineering I'm using the keys from the file coinbase provides upon creating the keys

image

And I'm creating them here: https://portal.cloud.coinbase.com/access/api?keyType=trade&referrer=advanced_trade

@KRV1
Copy link

KRV1 commented Apr 18, 2024

Guys, sorry, must the secret key set as parameter "as is"?
I'm getting in PHP (version 4.2.100) in BigInteger.php error, because secret key transmitted to it as is - with "BEGIN PRIVATE KEY" etc.

@carlosmiei
Copy link
Collaborator

@KRV1 Are you reading the keys from a file? Can you check if the \n are properly escaped?

@carlosmiei
Copy link
Collaborator

@KRV1 Can you try to parse your secret doing this?

$private_key = str_replace('\n', "\n", $private_key);

@KRV1
Copy link

KRV1 commented Apr 18, 2024

@carlosmiei Thank you, yes problem was in the carriage return symbol
Seems it works now

@tazengineering
Copy link
Author

Thank you @carlosmiei

Unfortunately I could not manage to make it work in Python.

I see you have yours using .json and split into multiple keys - where I only have 'apiKey' and 'secret' key.

exchange = ccxt.coinbase({
    'apiKey': "organizations/XXXXXXXXXXXXXXXXXXXX/apiKeys/XXXXXXXXXXXXXXXXXXXXXXXXXX",
    'secret': "-----BEGIN EC PRIVATE KEY-----\nXXXXXXXXXXXXX==XXXXXXXXXXXXXXXXXXX==XXXXX\nXXXXXXXXXXXXXXXXXXXXXXX==XXXXXXXXXXXXXX\nXXXXXXXXX==XXXXXXXXXX==XXXXXXXXXXXXXXXX==XXXXXXXXXX==\n-----END EC PRIVATE KEY-----\n",
})

@bradym05
Copy link

issue is persisting for me

@reverendrenegade
Copy link

I am having the same issue as well. There doesn't seem to be anything conclusive anywhere I've looked. This seems to be a CB issue because there are many questions about it

@bradym05
Copy link

bradym05 commented May 7, 2024

I thought this was a CB issue as well so I decided to try using the CB advanced trade SDK. It works perfectly so I'm no longer using ccxt, hopefully this gets fixed.

@carlosmiei
Copy link
Collaborator

@reverendrenegade @bradym05 This is tricky because as I said locally things work as expected for us. What's your ccxt and python version?

@carlosmiei
Copy link
Collaborator

@bradym05 @bradym05 I can try to ask coinbase directly about your specific issue, can you share your accountId/email via pm in discord/telegram?

@reverendrenegade
Copy link

reverendrenegade commented May 8, 2024

@carlosmiei @bradym05

Thanks for the reply!

ccxt Version: 4.3.18
Python Version: 3.11.2 (main, May 8 2024, 11:29:38) [GCC 9.4.0]

After updating to the latest version of ccxt and Python this solved the issue. Thanks for everyone's time.

@carlosmiei
Copy link
Collaborator

@reverendrenegade Great, thanks for letting us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants
@KRV1 @carlosmiei @reverendrenegade @tazengineering @bradym05 and others