Skip to main content

hyper_agent_core/services/
strategy.rs

1use crate::error::{HyperAgentError, Result};
2use hyper_strategy::strategy_config::{load_strategy_groups_from_disk_pub, StrategyGroup};
3use hyper_strategy::strategy_templates::build_template;
4
5/// Resolve a strategy by ID (saved groups) or template name.
6pub fn resolve_strategy(id: &str, symbol: Option<&str>) -> Result<StrategyGroup> {
7    let groups = load_strategy_groups_from_disk_pub();
8    if let Some(sg) = groups.iter().find(|g| g.id == id) {
9        return Ok(sg.clone());
10    }
11    let sym = symbol.ok_or_else(|| {
12        HyperAgentError::StrategyNotFound(format!(
13            "Strategy '{}' not found. Provide --symbol for template.",
14            id
15        ))
16    })?;
17    build_template(id, sym)
18        .ok_or_else(|| HyperAgentError::StrategyNotFound(format!("Unknown strategy '{}'", id)))
19}