daksjdkal
This commit is contained in:
@@ -27,6 +27,7 @@ struct AccountResponse {
|
||||
cash: f64,
|
||||
buying_power: f64,
|
||||
total_pnl: f64,
|
||||
daily_pnl: f64,
|
||||
position_count: usize,
|
||||
}
|
||||
|
||||
@@ -156,9 +157,13 @@ const HTML_TEMPLATE: &str = r#"<!DOCTYPE html>
|
||||
<div class="stat-label">Buying Power</div>
|
||||
<div class="stat-value" id="stat-buying-power">$0.00</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-label">Total P&L</div>
|
||||
<div class="stat-value" id="stat-total-pnl">$0.00</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-label">Today's P&L</div>
|
||||
<div class="stat-value" id="stat-pnl">$0.00</div>
|
||||
<div class="stat-value" id="stat-daily-pnl">$0.00</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-label">Open Positions</div>
|
||||
@@ -206,9 +211,11 @@ const HTML_TEMPLATE: &str = r#"<!DOCTYPE html>
|
||||
updateText('stat-portfolio-value', data.portfolio_value, true);
|
||||
updateText('stat-cash', data.cash, true);
|
||||
updateText('stat-buying-power', data.buying_power, true);
|
||||
updateText('stat-pnl', data.total_pnl, true, true);
|
||||
updateText('stat-total-pnl', data.total_pnl, true, true);
|
||||
updateClass('stat-total-pnl', data.total_pnl);
|
||||
updateText('stat-daily-pnl', data.daily_pnl, true, true);
|
||||
updateClass('stat-daily-pnl', data.daily_pnl);
|
||||
updateText('stat-positions', data.position_count);
|
||||
updateClass('stat-pnl', data.total_pnl);
|
||||
|
||||
} catch (error) { console.error('Error loading account stats:', error); }
|
||||
}
|
||||
@@ -324,6 +331,7 @@ async fn api_account(State(state): State<Arc<DashboardState>>) -> impl IntoRespo
|
||||
cash: 0.0,
|
||||
buying_power: 0.0,
|
||||
total_pnl: 0.0,
|
||||
daily_pnl: 0.0,
|
||||
position_count: 0,
|
||||
}),
|
||||
)
|
||||
@@ -341,11 +349,21 @@ async fn get_account_data(client: &AlpacaClient) -> anyhow::Result<AccountRespon
|
||||
.filter_map(|p| p.unrealized_pl.parse::<f64>().ok())
|
||||
.sum();
|
||||
|
||||
let daily_pnl: f64 = positions
|
||||
.iter()
|
||||
.filter_map(|p| {
|
||||
p.unrealized_intraday_pl
|
||||
.as_ref()
|
||||
.and_then(|s| s.parse::<f64>().ok())
|
||||
})
|
||||
.sum();
|
||||
|
||||
Ok(AccountResponse {
|
||||
portfolio_value: account.portfolio_value.parse().unwrap_or(0.0),
|
||||
cash: account.cash.parse().unwrap_or(0.0),
|
||||
buying_power: account.buying_power.parse().unwrap_or(0.0),
|
||||
total_pnl,
|
||||
daily_pnl,
|
||||
position_count: positions.len(),
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user