use crate::position_manager::{Position, PositionManager};
pub async fn list_open(pm: &PositionManager) -> Result<Vec<Position>, String> {
pm.list_open().await.map_err(|e| e.to_string())
}
pub async fn list_closed(pm: &PositionManager, limit: usize) -> Result<Vec<Position>, String> {
pm.list_closed(limit).await.map_err(|e| e.to_string())
}
pub async fn close_all(pm: &PositionManager, reason: &str) -> Result<usize, String> {
let positions = pm.list_open().await.map_err(|e| e.to_string())?;
let count = positions.len();
for pos in &positions {
let price = pos.current_price.unwrap_or(pos.entry_price);
pm.close_position(&pos.id, price, reason)
.await
.map_err(|e| e.to_string())?;
}
Ok(count)
}