Start tracking the markets you care about.
This application demonstrates how to use Streamlit with a FastAPI framework to:
- Collect external financial asset data from APIs using python.
- Write the requested data to a contained database server.
- Enable data consumption using an outward API framework.
- Visualise consumed data interactively.
- Start API server from root:
uvicorn src.fastAPI_app.app:app --reload - Start a local postgreSQL container:
docker compose up -d - Run application, ensuring the root directory is on path:
./run.sh# export PYTHONPATH=$PYTHONPATH:$(pwd) && venv/bin/streamlit run src/streamlit_app/app.py - Use application: http://localhost:8501
Prerequisites
- Install python packages in a virtual environment:
pip install -r requirements.txt - Install docker:
brew docker - Create the
psqldata table (refer to theSQLsnippet in the section: Database). - Add your API-Keys for each external service in
sample.env.dev& rename this file to.env.dev.
- Framework:
Streamlit - Source Code:
Python - Database:
PostgreSQL - Outward API:
FastAPI - CI/CD:
GitHub Actions
The frontend & runtime is handled by Streamlit: venv/bin/streamlit run src/streamlit_app/app.py
The bulk of this application is implemented in Python using src/streamlit_app/app.py with src/common/utils.py.
Generally the flow involves:
- Connecting to the PostrgreSQL database table using
psycopg2. - Triggering realtime data collection by button-press, which writes data to
psqlfrom external API sources. - Reading database data from FastAPI endpoints enabled in
src/fastAPI_app/app.py. - Plotting all-time data interactively using
plotly.
Connect to your PostgreSQL contained server in bash:
docker exec -it postgres-on_your_markets psql -U postgres -d postgresCreate the core table within the psql terminal:
CREATE TABLE on_your_market_prices (
id SERIAL PRIMARY KEY,
coin_name VARCHAR(50),
price INTEGER,
timestamp TIMESTAMP
);The FastAPI framework is used to setup endpoints (see src/fastAPI_app/app.py) for consuming historical asset value's from the database:
requests.get('http://127.0.0.1:8000/get_stocks_data')
Currently, basic linting & formatting (black & flake8) are applied by GitHub Actions for each repository push.
- Heroku - Cloud application hosting (e.g. app & database) - redirect CNAME from owned DNS.