Files
foxhunt/bin/fxt/examples/complete_client_example.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

122 lines
4.1 KiB
Rust

//! Complete TLI Client Example
//!
//! This example demonstrates how to use the TLI client infrastructure
//! to connect to both Trading Service and Backtesting Service.
#![allow(unused_crate_dependencies)]
use fxt::prelude::*;
use tokio::time::{sleep, Duration};
use tracing::{error, info, warn};
#[tokio::main]
async fn main() -> TliResult<()> {
// Initialize logging
tracing_subscriber::fmt::init();
info!("Starting TLI Complete Client Example");
// Create client suite with both services
let client_suite = TliClientBuilder::new()
.with_service_endpoint(
"trading_service".to_string(),
"http://localhost:50051".to_string(),
)
.with_service_endpoint(
"backtesting_service".to_string(),
"http://localhost:50053".to_string(),
)
.with_trading_config(TradingClientConfig {
endpoint: "http://localhost:50051".to_string(),
timeout_ms: 10_000,
})
.with_backtesting_config(BacktestingClientConfig {
endpoint: "http://localhost:50053".to_string(),
timeout_ms: 10_000,
})
.build()
.await?;
info!("Client suite created successfully");
// Demonstrate trading operations
if let Some(mut trading_client) = client_suite.trading_client {
info!("Connecting to trading service...");
match trading_client.connect().await {
Ok(_) => {
info!("Connected to trading service successfully");
info!("Connection status: {}", trading_client.is_connected());
// Note: Actual trading operations would require implementing
// the gRPC service methods. This example shows the client setup.
info!("Trading client is ready for operations");
},
Err(e) => {
error!("Failed to connect to trading service: {}", e);
},
}
// Cleanup
trading_client.shutdown().await;
info!("Trading client shut down");
} else {
warn!("Trading client not available");
}
// Demonstrate backtesting operations
if let Some(mut backtesting_client) = client_suite.backtesting_client {
info!("Connecting to backtesting service...");
match backtesting_client.connect().await {
Ok(_) => {
info!("Connected to backtesting service successfully");
info!("Connection status: {}", backtesting_client.is_connected());
// Note: Actual backtesting operations would require implementing
// the gRPC service methods. This example shows the client setup.
info!("Backtesting client is ready for operations");
},
Err(e) => {
error!("Failed to connect to backtesting service: {}", e);
},
}
// Cleanup
backtesting_client.shutdown().await;
info!("Backtesting client shut down");
} else {
warn!("Backtesting client not available");
}
// Demonstrate ML training operations
if let Some(mut ml_client) = client_suite.ml_training_client {
info!("Connecting to ML training service...");
match ml_client.connect().await {
Ok(_) => {
info!("Connected to ML training service successfully");
info!("Connection status: {}", ml_client.is_connected());
// Note: Actual ML training operations would require implementing
// the gRPC service methods. This example shows the client setup.
info!("ML training client is ready for operations");
},
Err(e) => {
error!("Failed to connect to ML training service: {}", e);
},
}
// Cleanup
ml_client.shutdown().await;
info!("ML training client shut down");
} else {
warn!("ML training client not available");
}
// Allow some time for graceful shutdown
sleep(Duration::from_secs(1)).await;
info!("Example completed successfully");
Ok(())
}