coinbase / coinbase-advanced-py

The Advanced API Python SDK is a Python package that makes it easy to interact with the Coinbase Advanced API. The SDK handles authentication, HTTP connections, and provides helpful methods for interacting with the API.
https://docs.cdp.coinbase.com/advanced-trade/docs/welcome/
Apache License 2.0
98 stars 27 forks source link

get_candles throttling returns "401 Unauthorized" instead of "Too Many Requests" #60

Closed angelaponte closed 4 weeks ago

angelaponte commented 1 month ago

Greetings, thank you for the awesome package, great product, and services!

I implemented a Python function that uses get_candles() to pull historic data, 299 candles at a time, and throttles itself based on public rate limits.

This week, when pulling data, I started getting this error: HTTPError: 401 Client Error: Unauthorized Unauthorized

This was unexpected and I created a new API key as a result (unnecessarily; both API keys work), even though I'm invoking the public API; I normally get a "Too Many Requests" error when Coinbase needs me to dial it down to make room for large request volume on the exchange, beyond the publicly posted rate limits.

This morning, I added an exponential backoff whenever I get the "401 Unauthorized" exception, tried to pull the data, and it worked; I now have a full dataframe, like I did before this arose. My sense is that exponential backoff is a thoughtful way to protect resources.

It was confusing to get an "Unauthorized" message when "Too Many Requests" is expected and more accurate when Coinbase needs to throttle customers to conserve resources due to high volume on the exchange.

github-actions[bot] commented 1 month ago

Thank you for reporting! If this is an SDK specific issue, we will look into it and get back to you soon. If this is an API related request, report it in our Advanced API Discord instead (use this invite link if it's your first time accessing the Discord).

justinsogoni-cb commented 1 month ago

Hi, are you using the get_candles() endpoint or the get_public_candles() method from the SDK?

angelaponte commented 1 month ago

Thanks for the question; I'm using the get_candles() endpoint.

benjzyq commented 1 month ago

Hi, I got the similar problem. I tried to use list_orders and get_orders and it would randomly throw out 401 error, like, 2 out of 5 times.

urischwartz-cb commented 4 weeks ago

This is resolved now. Please let us know on Discord if you continue seeing issues. Thanks for raising!