Save symbol price in database #41
@ -2,10 +2,11 @@ import os
|
|||||||
|
|
||||||
from apiflask import APIBlueprint
|
from apiflask import APIBlueprint
|
||||||
|
|
||||||
from app.schema import PortfolioResponseSchema
|
from app.models import SharePrice
|
||||||
|
from app.auth import auth
|
||||||
from app.db import database as db
|
from app.db import database as db
|
||||||
from app.helper_functions import make_response, get_email_or_abort_401
|
from app.helper_functions import make_response, get_email_or_abort_401
|
||||||
from app.auth import auth
|
from app.schema import PortfolioResponseSchema
|
||||||
|
|
||||||
portfolio_blueprint = APIBlueprint('portfolio', __name__, url_prefix='/api')
|
portfolio_blueprint = APIBlueprint('portfolio', __name__, url_prefix='/api')
|
||||||
__location__ = os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__)))
|
__location__ = os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__)))
|
||||||
@ -23,11 +24,18 @@ def get_portfolio():
|
|||||||
|
|
||||||
if transactions is not None:
|
if transactions is not None:
|
||||||
for row in transactions:
|
for row in transactions:
|
||||||
return_portfolio.append({
|
data = {
|
||||||
"symbol": row[0],
|
"symbol": row[0],
|
||||||
"count": row[1],
|
"count": row[1],
|
||||||
# "price": row[2],
|
# "calculated_price": row[2],
|
||||||
"last_transaction": row[3]
|
"last_transaction": row[3],
|
||||||
})
|
'current_price': 0
|
||||||
|
}
|
||||||
|
|
||||||
|
query_share_price = db.session.query(SharePrice).filter_by(symbol=row[0]).first()
|
||||||
|
if query_share_price is not None:
|
||||||
|
data['current_price'] = query_share_price.as_dict()['price']
|
||||||
|
|
||||||
|
return_portfolio.append(data)
|
||||||
|
|
||||||
return make_response(return_portfolio, 200, "Successfully loaded symbols")
|
return make_response(return_portfolio, 200, "Successfully loaded symbols")
|
||||||
|
Loading…
Reference in New Issue
Block a user