sudiptab2100 / stock-price-view

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

BSE Stock Viewer (Python & MongoDB)

Version Details

  • Python 3.11.7
  • MongoDB 7.0.2
  • cURL 8.4.0

Setup & Run

1. Clone the repository

git clone https://github.com/sudiptab2100/stock-price-view.git

2. Initialize Python Virtual Environment

Make sure Python virtual environment (virtualenv) is installed.

python -m venv env

3. Activate the virtual environment

source env/bin/activate

4. Install the dependencies

pip install -r requirements.txt

5. Run the application

python app.py

API Endpoints

1. Get Top k Stocks

Top stocks are the stocks with highest growth rate considering the oldest date in the database as the base date.

curl -X GET http://localhost:8000/get_top_k/<k>

2. Search Stock by Name

It searches for the stock by name and returns the stock with stock code, stock name, pnl & other details.

curl -X GET http://localhost:8000/search/<name>

3. Get Favorite Stocks

curl -X GET http://localhost:8000/get_favorites

4. Add Stock to Favorites

curl -X POST http://localhost:8000/add_favorite/<stock_code>

5. Remove Stock from Favorites

curl -X DELETE http://localhost:8000/remove_favorite/<stock_code>

6. Get Stock Price History

It returns the price history of the stock in the database. It returns a json object with two keys: days & prices, where days is a list of dates in ddmmyy format in sorted order and prices is a list of prices corresponding to the dates in days.

curl -X GET http://localhost:8000/get_price_history/<stock_code>

Chart UI

See the Chart UI at

http://localhost:8001/chart.html

Chart

Here you can see the price chart by putting the stock code in the input field.

Other Details

  • The app runs the preset script and then start API.

  • It download and stores past 50 days data (excluding weekends) of all the stocks in the database for the first time only, later it only updates the database with the latest data.

  • The DB can be refreshed by changing the refresh variable in app.py (line no. 42) to True.

    if __name__ == "__main__":
        preset(days=50, refresh=True)

About


Languages

Language:Python 82.5%Language:HTML 17.5%