Skip to content

A RESTful web app that simulates managing portfolios of stocks, using real stocks’ prices by querying an API.

Notifications You must be signed in to change notification settings

DanielTsiang/stock-simulator

Repository files navigation

Stock Simulator

Stock Simulator Test App Status Known Vulnerabilities Visitors Code style: black Buymeacoffee

Description

A RESTful web app that simulates managing portfolios of stocks, using real stocks’ prices by querying an API.

Getting Started

  1. Visit the web application here.
  2. Register for an account!

Video Demo

Stock.Simulator.Demo.mp4

Specification

  • Design and build a RESTful web app using Python with Flask’s MVC framework, connected to a SQL database. Served by Gunicorn, a production-quality web server.
  • Users can create an account and login, check stock prices, buy and sell stocks, update cash amount, change password (stored as salted hashes for security), view and clear history of transactions.
  • Trading stocks will update the portfolio display and selectable options without page reload via AJAX calls.
  • Front-end is styled using CSS with Bootstrap framework, includes popup forms, loading animations and embedded confirmation alerts for enhanced user experience, as well as a mobile-friendly navbar layout.
  • Using JavaScript, users can search and sort the stock data displayed in tables.
  • User inputs are validated before form submission via jQuery and feedback is shown to user, e.g. error message if password does not meet strong complexity requirements.

Technologies Used

Python Flask Gunicorn Postgres HTML5 Bootstrap JavaScript jQuery GitHub Actions Dependabot Render

  • Python with Flask framework
  • Gunicorn
  • SQL (SQLite / PostgreSQL)
  • HTML5
  • CSS with Bootstrap framework
  • JavaScript with jQuery framework, and DataTables library
  • GitHub Actions workflows for CI to automate running unit tests
  • Dependabot to keep dependencies up to date and mitigate security vulnerabilities
  • Render for deployment

Python

Running locally with Python

  1. Export the following environment variables necessary to run the app, e.g. on MacOS/Linux:
    export DATABASE_URL=<PostgreSQL database URL>
    
  2. In the root folder where requirements.txt is contained, run the following in the terminal to install the requirements for this project:
    pip install -r requirements.txt
  3. To start the app, in the root folder, run the following command in the terminal:
    gunicorn --log-config logging.conf application:app --preload
  4. Visit the following URL in your web browser:
    localhost:8000
  5. To shut down the app, in the terminal hit CTRL+C.

Testing locally with Python

In the root folder, run the following commands in the terminal to install the requirements and then run the unit tests:

pip install -r requirements.txt -r requirements_test.txt
python -m pytest tests/

Docker

Running locally with Docker

  1. Ensure you have Docker installed.
  2. To build the Docker image, in the root folder where application.py is contained, run the following command in the terminal:
    sh docker/docker-build.sh
  3. Export the following environment variables necessary to run the app, e.g. on MacOS/Linux:
    export DATABASE_URL=<PostgreSQL database URL>
    
  4. To run the Docker container, in the root folder, run the following command in the terminal:
    sh docker/docker-run.sh
  5. Visit the following URL in your web browser:
    localhost:8000
  6. To shut down the app, in the terminal hit CTRL+C.

Testing locally with Docker

After building the Docker image, run the following command to run the unit tests:

sh docker/docker-test.sh