This is a project I had to do for the Harvard Computer Science course on edX. It is a web app made with Python, Flask, Javascript, SQL, HTML, and CSS. I just used sqlite3 db to persist the data.
To start out you can register for an account which will then log the user in and start them off with a $10K cash balance. I used regex to enforce the 8 character minimum and alphanumeric characters.
Validation includes checking for empty data and ensuring passwords match or else you get a meme error message.
Once successfully registered redirects to root and flashes success message.
If you logout or close your browser you will need to login again. Login compares hashed password from request to hashed password in database to login successfully.
The quote tab allows user to input stock symbol to findout the latest price. Uses an api call to IEX.
A successful quote is flashed on the dashboard.
Buying stock requires stock symbol and number of shares. Combination of frontend validation from browser and backend validation ensures proper input. I used Javascript to add a feature that when a user enters a symbol the script uses a blur event listener on the text field that will fetch a quote via json and then inform the user the maximum number of shares possible to purchase that stock based on the latest price of the stock and their current cash balance.
Selling is similar to buying except using the change event listener on the select input field to find out via sql query how many shares of that symbol the user owns in order to display the maximum number of shares allowed to sell. The options in the select input field are populated via an sql query which finds the symbols they currently own.
The history tab will display all the users transactions ordered by company name first, then by transaction date ascending.