06/01 Adding porfolio charts

This commit is contained in:
2026-06-01 17:19:24 -04:00
parent 4406d9734c
commit e040f0a0f8
3 changed files with 393 additions and 37 deletions
+20 -1
View File
@@ -6,7 +6,7 @@ from wtforms.validators import DataRequired, Optional, NumberRange, Length
from app.extensions import db
from app.models.investment import Investment, InvestmentTransaction
from app.services.investment_service import (
get_portfolio_summary, update_prices, fetch_price,
get_portfolio_summary, update_prices, fetch_price, fetch_price_history,
ASSET_COLORS, ASSET_TYPE_LABELS
)
from datetime import date
@@ -273,3 +273,22 @@ def api_price(ticker):
'price': price,
'error': error,
})
@investments_bp.route('/api/history/<ticker>')
@login_required
def api_price_history(ticker):
"""
Return OHLC history + day/period change for a ticker.
Query param: tf = 1W | 1M | 3M | 6M | 1Y (default 1M)
Used by the portfolio page inline charts.
"""
tf = request.args.get('tf', '1M').upper()
if tf not in ('1W', '1M', '3M', '6M', '1Y'):
tf = '1M'
data = fetch_price_history(ticker.upper().strip(), tf)
if data is None:
return jsonify({'error': f'No history data available for {ticker}'}), 404
return jsonify(data)