man-c / pycoingecko

Python wrapper for the CoinGecko API
MIT License
1.04k stars 268 forks source link

Any version beyond 2.2.0 is breaking my application #74

Closed pir8radio closed 1 year ago

pir8radio commented 1 year ago

Hi, not quite sure where the issue is, but i get freezing of my application if i try to use 2.3.0+ but with 2.2.0 my app will not freeze but sometimes returns no values... it seems with 2.3.0 the no values become feezing.. Not quite sure how to troubleshoot. still looking into the cause. just FYI

man-c commented 1 year ago

Hi, It seems like you are getting a server error response and the python wrapper retries the request. If so, the application doesn't really freezes, it waits retrying until it doesn't get any relevant server error responses. By default, the wrapper is configured to retry totally 5 times (with a backoff_factor=0.5), and forces retries on the following server error codes [502, 503, 504]:

https://github.com/man-c/pycoingecko/blob/0abd51ba706d06d2a1fad5f506cdd1f7ba265401/pycoingecko/api.py#L23

This happens after version 2.3.0+ because the retying functionality was fixed at this version (before version 2.3.0 retying wasn't working properly). You can see CHANGELOG for such changes:

https://github.com/man-c/pycoingecko/blob/0abd51ba706d06d2a1fad5f506cdd1f7ba265401/CHANGELOG.md?plain=1#L22-L29

You can deactivate retying in any newer version (2.3.0+) by initializing pycoingecko with param reties=0 to check if you are getting same results with previous version (2.2.0):

from pycoingecko import CoinGeckoAPI

cg=CoinGeckoAPI(retries=0)

Maybe, you are reaching API's rate limit (in API's doc: Free API has a rate limit of 10-50 calls/minute10-50 calls/minute), or getting other error from API that causes retrying instead of getting empty results.

pir8radio commented 1 year ago

thank you, I couldn't find documents on what params were available. good to know i can set retries=0 ill give that a go! https://github.com/pir8radio/signum-explorer/blob/master/scan/caching_data/exchange.py It seems coingecko api is blocking me if i try 1 request more than 2 mins apart.. very strange. maybe my IP got added to some extended limit? Have you heard of that? So i can only request 1 every 120 seconds.. i cache the data, but would rather it update quicker. I will reach out to them.. thanks again. ill upgrade and test with retries=0

man-c commented 1 year ago

Thanks for the update! I haven't heard something relevant. I will include the parameters in the doc. Also, I will consider changing the default retries to 0 so the user can decide whether to enable the retrying.