Coder Social home page Coder Social logo

paulinakhew / web_trader Goto Github PK

View Code? Open in Web Editor NEW
26.0 6.0 19.0 6.95 MB

๐Ÿ“Š Python Flask game that consolidates data from Nasdaq, allowing the user to practice buying and selling stocks.

License: MIT License

Python 37.52% HTML 62.45% Procfile 0.03%
python stock nasdaq profit web-trader sqlite3-database sqlite3 html css bootstrap

web_trader's Introduction

forthebadge made-with-python

Build Status Coverage Status License: MIT Gitmoji

Web Trader

Web Trader is a trading website that consolidates data from Nasdaq, allowing the user to search up the ticker symbol and price of any stock. I employed HTML and CSS to format all the pages and used Python for the back end development. All of the user information, transactions, holdings, and balances are stored in a SQLite3 database. Not only can users search up stocks, they can buy and sell using their own funds. The goal is to end up with a large profit.

Setup

  • Clone (or download) the repository:
git clone [email protected]:Paulinakhew/web_trader.git
  • Download all the necessary packages:
  • MacOS Users
$ pip3 install -r requirements.txt
  • Linux Users
$ pip install -r requirements.txt
  • Create the sqlite3 database:
$ python3 schema.py
  • Seed the database:
$ python3 seed.py
  • Install pre-commit hook:
pre-commit install
  • Run the app locally:
$ python3 controller.py

Example Photos

This is the login menu where you can login or create a new user account. Login menu

This is the main menu that opens after you log in. Main menu

The dashboard is where you can see all of your previous transactions as well as current holdings. Dashboard

This page lets the user lookup ticker symbols and the last prices of stocks. Lookup and Quote Menu

The buy and sell menu lets the user input the ticker symbol and quantity of the stock that they want to purchase/sell. Buy and Sell Menu

SQLite3 Database

The database is created using SQLite3. There are five tables in total, each serving a different purpose. For example, the transactions table is used to store the date, number of shares, and ticker symbols of all the users' purchases. This is the code for the transactions table:

CREATE TABLE transactions(
    pk INTEGER PRIMARY KEY AUTOINCREMENT,
    ticker_symbol TEXT,
    num_shares FLOAT,
    owner_username INTEGER,
    last_price FLOAT,
    date TEXT,
    FOREIGN KEY(owner_username) REFERENCES user(username)
);

API

I used the flask_restful extension to create an api. The endpoints are as follows:

'/users'
'/transactions'
'/transactions/<username>'
'/holdings/<username>'

Testing

I use GitHub actions and Pytest to test the project. You can see the tests here. I also have the API Key for the Intrinio API set up as a Secret. Secrets are environment variables that are encrypted and only exposed to selected actions. Anyone with collaborator access to this repository can use these secrets in a workflow.

Security

Instead of storing passwords as plaintext, I stored the salt and the hash of the password. When users try to log in, the hashed password is compared to the hash in the database.

pwdhash = hashlib.pbkdf2_hmac(
    'sha512',
    password.encode('utf-8'),
    salt.encode('ascii'),
    100000
)

New Features โœจ

Feel free to create a GitHub issue for this repository if you have any new ideas!

web_trader's People

Contributors

dependabot[bot] avatar ishan3299 avatar paulinakhew avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

web_trader's Issues

Fix alert in create account page

After creating an account, the app does not redirect to the main menu page. Instead it stays on the same page with an alert that you should create a different account. The newly created account exists in the system.

  • Fix this bug ๐Ÿ›

Add docstrings to all functions and clean up code

  • this issue just has to do with code readability
  • in the future, when building this out, each function should be properly labeled and its purpose should be easy to identify
  • this website has a lot of popular docstrings formats
  • Add docstrings to all functions in model.py
  • Add docstrings to all functions in controller.py
  • Add line separations within functions
  • remove unnecessary commented out code
  • implement flake8

Create a redirect for when users log out

  • this is a better way to code user logouts than just immediately redirecting to the login page and changing the current_user in the SQLite3 database
  • Add the /logout page
  • Add an alert to the /login page once the user has logged out

Change return_list into a class

In the functions that involve db work, a list is passed as a param:

return_list = (last_price, brokerage_fee, current_balance, trade_volume, agg_balance, username, ticker_symbol, current_number_shares)

this should be converted into its own class in a different file that is imported at the top of models. This would also help with testing as we can use an __eq__ function

Image on Menu page not loading

Hi Paulina!

I tried out this app, and had an issue when rendering the menu page:
screen shot 2018-09-26 at 9 06 20 pm

I got a 403 error attempting to fetch this image. It looks like it is hosted on a third party storage platform, and doesn't have public read permissions set.

App doesn't actually log the user out upon exit

Screen Shot 2019-03-15 at 9 40 19 PM

  • I queried the database after I finished a session as paulinakhew and it still had my account under the current_user even after I signed out
  • Create a function that functions similarly to seed.py that resets the current user to the original
  • this issue is related to #14 since I need to make sure that the current user is always the seed user

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.