This project extracts data from coinbase API, and saves it in the DB via the API.
Clone this repository.
Please note that the following instructions have been tested on Windows 10 + WSL2 + Docker Desktop.
Things you will need to have installed:
Python 3.9
Navigate to the root of the project and execute the following command to create a virtual environment:
python3 -m venv venv
Activate the virtual environment:
source venv/bin/activate
Navigate to the root of the project and execute the following command to install the related dependencies:
pip install -r requirements.txt
Set the PYTHONPATH to the current project directory (this needs to be done for every new terminal you open):
export PYTHONPATH=$(pwd)
Navigate to the root of the project and execute the following command to run the API:
uvicorn app.api.main:app --host 127.0.0.1 --port 8000
Alternatively, you can run this command so that the API reloads automatically when there are code changes:
uvicorn app.api.main:app --host 127.0.0.1 --port 8000 --reload
Either way, you should be able to access the FastAPI API through your browser by visiting:
http://127.0.0.1:8000
It is highly recommended to at least consider interacting with the API through the browser as FastAPI's out of the box functionalities make it incredibly convenient. The built-in UI docs element allows interactive exploration, calling and testing the API directly from the browser. You can read more here: https://fastapi.tiangolo.com/features/
You can then run the script to import some sample data:
python3 app/etl/main.py
This script will populate the SQLite database with some historical data for "BTC-USD" by communicating with the API. The script pulls BTC-USD data from the Coinbase API for the date range 1.9.2021 - 31.10.2021 (for demo purposes), after which it sends a POST request to the custom API to store that data. At the end it fetches the data that was previously stored in the two supported formats: json and csv.
Navigate to the root of the project and execute the following command to build and run a Docker container:
docker-compose up
This should automatically build and run a Docker container called "fastapi-project-container" and the FastAPI API will automatically start to run.
If you want to, you should be able to access the FastAPI API (which runs in the Docker container) through your local machine's browser by visiting:
http://127.0.0.1:8000
You can then run the app/etl/main.py script by running the command:
python3 app/etl/main.py
This script will populate the SQLite database with some historical data for "BTC-USD" by communicating with the API.
The pytest testing framework was used. The unit tests can be executed by navigating to the root of the project and using the following commands:
python3 -m pytest -vvv
- FastAPI - FastAPI is a modern, fast (high-performance), web framework for building APIs with Python 3.6+ based on standard Python type hints.
- SQLAlchemy - SQLAlchemy is the Python SQL toolkit and Object Relational Mapper that gives application developers the full power and flexibility of SQL.
- FastAPI Documentation: https://fastapi.tiangolo.com/
- SQLAlchemy Documentation: https://docs.sqlalchemy.org/