man-c / pycoingecko

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

How to use the "get_coin_market_chart_range_from_contract_address_by_id()" function? #39

Closed andrewcaniglia closed 3 years ago

andrewcaniglia commented 3 years ago

I'm trying to use the function with this code:

cg.get_coin_market_chart_range_from_contract_address_by_id(id = 'ethereum', contract_address = '0x514910771af9ca656af840dff83e8264ecf986ca', vs_currency = 'usd', from_timestamp = 1593650267, to_timestamp = 1593650267)

and it's just giving me this output:

{'prices': [], 'market_caps': [], 'total_volumes': []}

I get this no matter what erc-20 token address I use and no matter what I change the timestamps to. What am I doing wrong here?

andrewcaniglia commented 3 years ago

Actually, I realize now that the "to" unix timestamp has to be far enough away from the "from" unix timestamp to contain the specific hour in coingecko's records. This means it should be 3600 more than the "from" timestamp to be safe.

man-c commented 3 years ago

Yes, as I checked the endpoint seems to work fine by giving a small range to the timestamps.

For example:

>>> cg.get_coin_market_chart_range_from_contract_address_by_id('ethereum', '0x514910771af9ca656af840dff83e8264ecf986ca' ,'usd', 1593650267, 1593655000 )
{'prices': [[1593651883020, 4.767133017286734]], 'market_caps': [[1593651883020, 1818501613.1182184]], 'total_volumes': [[1593651883020, 312022091.0165991]]}