This project contains two scripts for extracting cryptocurrency data from the CoinCap API and storing it either in a CSV file or a PostgreSQL database.
- Python 3.6+
requests
librarypsycopg2
library (for PostgreSQL version only)
Install the required libraries using: pip
This script fetches cryptocurrency data from the CoinCap API and exports it to a CSV file.
- Ensure you have the required libraries installed.
- Run the script:python crypto_to_csv.py
- The script will create a file named
cryptocurrency_data.csv
in the same directory.
- Fetches real-time cryptocurrency data
- Exports data to a CSV file
- Includes error handling for API requests and file operations
This script fetches cryptocurrency data from the CoinCap API, performs some transformations, and imports it into a PostgreSQL database.
- PostgreSQL database server
- Database and user credentials
Update the db_params
dictionary in the script with your PostgreSQL connection details:
db_params = { "host": "localhost", "database": "your_database_name", "user": "your_username", "password": "your_password" }
- Ensure you have the required libraries installed and PostgreSQL set up.
- Run the script: python crypto_to_postgres.py
- Fetches real-time cryptocurrency data.
- Performs ETL operations:
- Extracts relevant fields.
- Transforms data (adds a 'performance' metric).
- Loads data into PostgreSQL.
- Uses UPSERT operation to handle existing records.
- Includes error handling for API requests and database operations.
Both scripts handle the following data fields:
id
name
symbol
price
price_change
The PostgreSQL script additionally calculates and stores:
performance
(based on price change).
- Both scripts include error handling for API requests.
- The PostgreSQL script also includes error handling for database operations.
- Regularly check the CoinCap API documentation for any changes to the endpoint or data structure.
- For the PostgreSQL script, ensure your database is properly maintained and backed up.