This is the one of the exercise from CS50x - Introduction for Computer Science: Exercise detail
The target of this exercise:
- Implement a website that allow user to "buy" and "sell" stock and the following functions:
- Complete the implementation of register in such a way that it allows a user to register for an account via a form.
- Complete the implementation of quote in such a way that it allows a user to look up a stock’s current price.
- Complete the implementation of buy in such a way that it enables a user to buy stocks.
- Complete the implementation of index in such a way that it displays an HTML table summarizing, for the user currently logged in, which stocks the user owns, the numbers of shares owned, the current price of each stock, and the total value of each holding (i.e., shares times price). Also display the user’s current cash balance along with a grand total (i.e., stocks’ total value plus cash).
- Complete the implementation of sell in such a way that it enables a user to sell shares of a stock (that he or she owns).
- Complete the implementation of history in such a way that it displays an HTML table summarizing all of a user’s transactions ever, listing row by row each and every buy and every sell.
Apart from the function required and the built in function provided in this exercise, I also added some function to the website:
- Allow user to change their password but cannot same as current password
- Allow user to check their profit for the stock that they have bought
- Allow users to buy more shares or sell shares of stocks they already own via click the button on the index page, without having to type stocks’ symbols manually.
- Allow users to add more cash into their account via the add cash page
- Flask for backend development
- HTML for website strcuture
- Bootstrap for design
- IEX API to get the stocks valus in real time
- sqlite3 for storing users information (username and hashed password) and the transaction record (bought or sold)
Test account: user012 ; password: 123456
Every user after registered will have $10000 by default
-
Index page (after login your own accout): it will show about your stock info with the price when you bought and total price for total number of share when you bought. Also, it will show about the latest profit for your stock
-
Quote page (Input the stock symbol for checking the stock info):
-
Buy page (Input the stock symbol and number of shares to buy):
-
Sell page (Select the stock that you have bought in the drop-down list and input the number of shares to sell):
-
History page (Show all your action on the page such as sell, buy):
-
Change password (Allow user to change their password but cannot input the new password same as current password):
- Bootstrap https://getbootstrap.com/docs/5.1/getting-started/introduction/
- W3School
- Stack Overflow