give me python code to download crypto market cap history as csv file
- User
give me python code to download crypto market cap history as csv file
- Assistant
- User
Traceback (most recent call last): File "C:\Users\Fazel\PycharmProjects\indicators_calculate\get_cap_data.py", line 37, in download_crypto_history('bitcoin', 'max', 'daily') File "C:\Users\Fazel\PycharmProjects\indicators_calculate\get_cap_data.py", line 21, in download_crypto_history dates = [datetime.fromtimestamp(ms / 1000.0).strftime('%Y-%m-%d') for ms in data['prices']] File "C:\Users\Fazel\PycharmProjects\indicators_calculate\get_cap_data.py", line 21, in dates = [datetime.fromtimestamp(ms / 1000.0).strftime('%Y-%m-%d') for ms in data['prices']] TypeError: unsupported operand type(s) for /: 'list' and 'float'
- Assistant
The error you're encountering is due to attempting to divide a list by a float number. In the
data['prices']anddata['market_caps']lists from the CoinGecko API, each element is actually a list where the first element is the timestamp (in milliseconds) and the second is the value (price or market cap). You need to extract the timestamp correctly by accessing the first element of each nested list before performing the division to convert it to seconds. - User
what if i want to get market cap of all crypto market (total market cap) instead of bitcoin
- Assistant
- User
what if i want to get solana all hhourly historical data as csv file
- Assistant
- User
Traceback (most recent call last): File "C:\Users\Fazel\PycharmProjects\indicators_calculate\get_cap_data.py", line 42, in download_solana_hourly_history(30) # Fetches the last 30 days; adjust as needed. File "C:\Users\Fazel\PycharmProjects\indicators_calculate\get_cap_data.py", line 20, in download_solana_hourly_history timestamps = [datetime.fromtimestamp(point[0] / 1000.0) for point in data['prices']] KeyError: 'pri
- Assistant