From f8a34d88d1687c66a3069a5dcfcfae8652dddcf7 Mon Sep 17 00:00:00 2001 From: H4CK3R-01 Date: Thu, 12 May 2022 17:25:10 +0200 Subject: [PATCH] Skip stocks where count is 0 --- api/app/blueprints/portfolio.py | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/api/app/blueprints/portfolio.py b/api/app/blueprints/portfolio.py index 9ead66b..67afdec 100644 --- a/api/app/blueprints/portfolio.py +++ b/api/app/blueprints/portfolio.py @@ -33,20 +33,23 @@ def get_portfolio(): # Otherwise calculate portfolio if transactions is not None: for row in transactions: - data = { - "isin": row[0], - "comment": row[1], - "count": row[2], - # "calculated_price": row[3], - "last_transaction": row[4], - 'current_price': 0 - } + if count == 0: + continue + else: + data = { + "isin": row[0], + "comment": row[1], + "count": row[2], + # "calculated_price": row[3], + "last_transaction": row[4], + 'current_price': 0 + } - # Add current share value to portfolio - query_share_price = db.session.query(SharePrice).filter_by(isin=row[0]).order_by(SharePrice.date.desc()).first() - if query_share_price is not None: - data['current_price'] = query_share_price.as_dict()['price'] + # Add current share value to portfolio + query_share_price = db.session.query(SharePrice).filter_by(isin=row[0]).order_by(SharePrice.date.desc()).first() + if query_share_price is not None: + data['current_price'] = query_share_price.as_dict()['price'] - return_portfolio.append(data) + return_portfolio.append(data) return make_response(return_portfolio, 200, "Successfully loaded symbols")