Skip to content

This simple app illustrates how to retrieve stock data (JSON format) from a backend server, and then show the graph and statistics data at frontend site.

License

Notifications You must be signed in to change notification settings

PacificDou/flask_vue_demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Single Page App using Vue.js and Flask

This simple app illustrates how to retrieve stock data (JSON format) from a backend server, and then show the graph and statistics data at frontend site.

Backend (Python 3)

  • Flask is used as the backend framework.
  • yfinance is used for downloading daily stock prices.
  • Currently, only 3 stocks are supported: GOOG, AAPL, MSFT. However, it's easy to add more stocks by appending stock codes to stock_names in app.py.
  • Backend has a dedicated thread for downloading stock data (current interval: 4 hours).
  • For simplicity, database is NOT used. Each time you restart the server, it will download the stock data again and store them in the memory.

ULR entries

  • /: only for test purpose, return a message "Hello World! :)".
  • /stock/<start_date>: start_date has the format YYYY-MM-DD.
    It returns a list of stock objects with fields: name (string), dates (list of string), prices (list of float), cumulative_return (float), annualized_return (float), annualized_volatility (float)

Formulas for stock statistics

Installation guide

  1. Install dependencies (better to run in a new virtual env)
cd backend
pip install -r requirements.txt
  1. Try
python app.py
curl http://localhost:11280/stock/2023-05-01

Frontend (Vue 3)

  • Vue is used as the frontend framework.
  • Each time user select a new start date and click "Reload", it will talk with the backend to get latest data. (Yes, as you noticed, we can improve the performance by client cache).
  • canvasJS is used for drawing the graph.

Installation guide

  1. Install dependencies
cd frontend
npm install
  1. Try (make sure the backend server is running)
npm run dev -- --host 0.0.0.0

Now use your browser to access http://localhost:12801/

About

This simple app illustrates how to retrieve stock data (JSON format) from a backend server, and then show the graph and statistics data at frontend site.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published