Files
foxhunt/crates/adaptive-strategy/examples/basic_strategy.rs
jgrusewski 9c3d741a08 refactor: restructure repo — crates/, bin/, testing/ layout
Move 17 library crates into crates/, CLI binary into bin/fxt,
consolidate 10 test crates into testing/, split config crate
from deployment config files.

Root directory reduced from 38+ to ~17 directories.
All Cargo.toml paths and build.rs proto refs updated.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-25 11:56:00 +01:00

68 lines
2.1 KiB
Rust

#![allow(unused_crate_dependencies)]
//! Basic adaptive strategy example
//!
//! This example demonstrates how to set up and run a basic adaptive trading strategy
//! with ensemble models, risk management, and execution algorithms.
use adaptive_strategy::config::AdaptiveStrategyConfig;
use adaptive_strategy::AdaptiveStrategy;
use std::time::Duration;
use tokio::time::sleep;
use tracing::info;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Initialize logging
// DISABLED: tracing_subscriber not in dependencies - uncomment when added
// tracing_subscriber::fmt().with_max_level(Level::INFO).init();
info!("Starting basic adaptive strategy example");
// Create configuration
let config = create_strategy_config();
// Initialize the adaptive strategy
let strategy = AdaptiveStrategy::new(config).await?;
info!("Strategy initialized successfully");
// Get initial state
let initial_state = strategy.get_state().await;
info!(
"Initial strategy state: active={}, regime={}",
initial_state.active, initial_state.current_regime
);
// Simulate running for a short period (in production, this would run continuously)
info!("Running strategy simulation for 10 seconds...");
// Start the strategy (this would run indefinitely in production)
// For demo purposes, we'll use a timeout
let strategy_task = tokio::spawn(async move {
if let Err(e) = strategy.start().await {
eprintln!("Strategy error: {}", e);
}
});
// Let it run for 10 seconds
sleep(Duration::from_secs(10)).await;
info!("Stopping strategy simulation");
strategy_task.abort();
info!("Example completed successfully");
Ok(())
}
/// Create a comprehensive strategy configuration
fn create_strategy_config() -> AdaptiveStrategyConfig {
let mut config = AdaptiveStrategyConfig::default();
// Customize the execution interval for demo
config.general.execution_interval = Duration::from_millis(500);
config.general.error_backoff_duration = Duration::from_secs(2);
config
}