hyper_agent_core/services/
position.rs1use crate::position_manager::{Position, PositionManager};
2
3pub async fn list_open(pm: &PositionManager) -> Result<Vec<Position>, String> {
4 pm.list_open().await.map_err(|e| e.to_string())
5}
6
7pub async fn list_closed(pm: &PositionManager, limit: usize) -> Result<Vec<Position>, String> {
8 pm.list_closed(limit).await.map_err(|e| e.to_string())
9}
10
11pub async fn close_all(pm: &PositionManager, reason: &str) -> Result<usize, String> {
12 let positions = pm.list_open().await.map_err(|e| e.to_string())?;
13 let count = positions.len();
14 for pos in &positions {
15 let price = pos.current_price.unwrap_or(pos.entry_price);
16 pm.close_position(&pos.id, price, reason)
17 .await
18 .map_err(|e| e.to_string())?;
19 }
20 Ok(count)
21}