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: n = string[0] if isinstance(string[0], int) else ord(string[0]), IndexError: index out of range #22256

Open
yz26cn opened this issue Apr 23, 2024 · 3 comments
Assignees

Comments

@yz26cn
Copy link

yz26cn commented Apr 23, 2024

Operating System

MacOS

Programming Languages

Python

CCXT Version

4.3.5

Description

For folks who got the issue n = string[0] if isinstance(string[0], int) else ord(string[0]) IndexError: index out of range, it is because the @staticmethod def encode(string): return string.encode('latin-1') in exchange.py will only encode the part of the string before its first \n line seperater. So the first step is to remove the '\n' line seperate in your secret.

Then input your secret in the format of this:
'''-----BEGIN EC PRIVATE KEY-----
xxxxxxxxxxxxxxx
xxxxxxxxxxxxxxx
xxxxxxxx
-----END EC PRIVATE KEY-----'''

You don't need to change the original key or password, here's an example:

exchange = ccxt.coinbase({
'apiKey': api_key,
'secret': '''-----BEGIN EC PRIVATE KEY-----
xxxxxxxxxxxxxxx
xxxxxxxxxxxxxxx
xxxxxxxx
-----END EC PRIVATE KEY-----''',
'password': api_passphrase,
})

Hope this issue could be solved soon, since I would not want to store my api secret in my code. Thanks

Code

  

@carlosmiei
Copy link
Collaborator

Hello @yz26cn,
Thanks for reporting it, but I'm not 100% clear on what the issue is yet. How can we reproduce it locally?

@carlosmiei carlosmiei self-assigned this Apr 23, 2024
@yz26cn
Copy link
Author

yz26cn commented Apr 23, 2024

exchange = ccxt.coinbase({
    'apiKey': 'organizations/xxxxxxx/apiKeys/xxxxxx',
    'secret': '-----BEGIN EC PRIVATE KEY-----\xxxxxxxxxxxxxxxx\n xxxxxxxxxxxxxxxx\n xxxxxxxxxxxxxxxx\n-----END EC PRIVATE KEY-----\n'
    'password': "my password",
})
exchange.fetch_total_balance()

I was working on this piece of code.

Conda virtual environment, Python=3.12, ccxi=4.3.5

Name: ccxt Version: 4.3.5 Summary: A JavaScript / TypeScript / Python / C# / PHP cryptocurrency trading library with support for 100+ exchanges Home-page: https://ccxt.com Author: Igor Kroitor Author-email: igor.kroitor@gmail.com License: MIT Location: /Users/xxxxxx/miniconda3/envs/tvb2/lib/python3.12/site-packages Requires: aiodns, aiohttp, certifi, cryptography, requests, setuptools, typing-extensions, yarl Required-by:

@carlosmiei
Copy link
Collaborator

@yz26cn Locally that works fine for me 🤔

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

No branches or pull requests

2 participants