From 85cd363c06df2fa4b6db066e2f6eec247d3d8c71 Mon Sep 17 00:00:00 2001 From: H4CK3R-01 Date: Thu, 7 Apr 2022 12:40:55 +0200 Subject: [PATCH] Always use the most recent share price --- api/app/blueprints/portfolio.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/api/app/blueprints/portfolio.py b/api/app/blueprints/portfolio.py index 2d2cde9..e5eb5fb 100644 --- a/api/app/blueprints/portfolio.py +++ b/api/app/blueprints/portfolio.py @@ -1,11 +1,10 @@ import os from apiflask import APIBlueprint - -from app.models import SharePrice from app.auth import auth from app.db import database as db from app.helper_functions import make_response, get_email_or_abort_401 +from app.models import SharePrice from app.schema import PortfolioResponseSchema portfolio_blueprint = APIBlueprint('portfolio', __name__, url_prefix='/api') @@ -32,7 +31,7 @@ def get_portfolio(): 'current_price': 0 } - query_share_price = db.session.query(SharePrice).filter_by(symbol=row[0]).first() + query_share_price = db.session.query(SharePrice).filter_by(symbol=row[0]).order_by(SharePrice.date.desc()).first() if query_share_price is not None: data['current_price'] = query_share_price.as_dict()['price']