refactor: Simplify open position value calculation using trade summary data
This commit is contained in:
parent
6097ce6367
commit
217707b4d9
@ -1,5 +1,5 @@
|
|||||||
import streamlit as st
|
import streamlit as st
|
||||||
from trading.journal import get_latest_portfolio_value, get_open_trades_summary, get_open_trades
|
from trading.journal import get_latest_portfolio_value, get_open_trades_summary
|
||||||
from trading.position_calculator import PositionCalculator
|
from trading.position_calculator import PositionCalculator
|
||||||
from utils.data_utils import get_current_prices
|
from utils.data_utils import get_current_prices
|
||||||
|
|
||||||
@ -12,22 +12,20 @@ def trading_system_page():
|
|||||||
cash_balance = portfolio_data['cash_balance'] if portfolio_data else 0
|
cash_balance = portfolio_data['cash_balance'] if portfolio_data else 0
|
||||||
|
|
||||||
# Calculate total portfolio value including open positions
|
# Calculate total portfolio value including open positions
|
||||||
open_trades = get_open_trades()
|
open_summary = get_open_trades_summary() # Change to use summary instead of raw trades
|
||||||
total_position_value = 0
|
total_position_value = 0
|
||||||
|
|
||||||
if open_trades:
|
if open_summary:
|
||||||
# Get current prices for all open positions
|
# Get current prices for all open positions
|
||||||
tickers = list(set(trade['ticker'] for trade in open_trades))
|
tickers = list(set(summary['ticker'] for summary in open_summary))
|
||||||
current_prices = get_current_prices(tickers)
|
current_prices = get_current_prices(tickers)
|
||||||
|
|
||||||
# Calculate total value of open positions
|
# Calculate total value of open positions
|
||||||
position_values = {}
|
for summary in open_summary:
|
||||||
for trade in open_trades:
|
ticker = summary['ticker']
|
||||||
ticker = trade['ticker']
|
|
||||||
current_price = current_prices.get(ticker, 0)
|
current_price = current_prices.get(ticker, 0)
|
||||||
shares = trade['shares']
|
shares = summary['total_shares']
|
||||||
position_value = current_price * shares
|
position_value = current_price * shares
|
||||||
position_values[ticker] = position_values.get(ticker, 0) + position_value
|
|
||||||
total_position_value += position_value
|
total_position_value += position_value
|
||||||
|
|
||||||
total_portfolio_value = cash_balance + total_position_value
|
total_portfolio_value = cash_balance + total_position_value
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user