Skip to content

Track the markets you care about (Streamlit application)

Notifications You must be signed in to change notification settings

ethanknights/on-your-markets

Repository files navigation

On-Your-Markets - Market Tracker Application

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.

Local Quickstart

  1. Start API server from root: uvicorn src.fastAPI_app.app:app --reload
  2. Start a local postgreSQL container: docker compose up -d
  3. Run application, ensuring the root directory is on path: ./run.sh # export PYTHONPATH=$PYTHONPATH:$(pwd) && venv/bin/streamlit run src/streamlit_app/app.py
  4. Use application: http://localhost:8501

Prerequisites

  • Install python packages in a virtual environment: pip install -r requirements.txt
  • Install docker: brew docker
  • Create the psql data table (refer to the SQL snippet in the section: Database).
  • Add your API-Keys for each external service in sample.env.dev & rename this file to .env.dev.

Tech-Stack

  • Framework: Streamlit
  • Source Code: Python
  • Database: PostgreSQL
  • Outward API: FastAPI
  • CI/CD: GitHub Actions

Framework

The frontend & runtime is handled by Streamlit: venv/bin/streamlit run src/streamlit_app/app.py

Source Code

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 psql from external API sources.
  • Reading database data from FastAPI endpoints enabled in src/fastAPI_app/app.py.
  • Plotting all-time data interactively using plotly.

Database

First-time-setup

Connect to your PostgreSQL contained server in bash:

docker exec -it postgres-on_your_markets psql -U postgres -d postgres

Create 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
);

API

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')

CI/CD

Currently, basic linting & formatting (black & flake8) are applied by GitHub Actions for each repository push.

Notes

  • Heroku - Cloud application hosting (e.g. app & database) - redirect CNAME from owned DNS.

About

Track the markets you care about (Streamlit application)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published