Files
foxhunt/tli/examples/complete_client_example.rs
jgrusewski 6093eac7bf 🔧 Tonic 0.14 Upgrade: Auto-generated and build system changes
Wave 64-65 cleanup: Proto regeneration and build system updates from Tonic 0.12→0.14 upgrade

Files updated:
- Cargo.lock: Dependency resolution for Tonic 0.14.2
- All build.rs: Updated for tonic-prost-build
- Proto files: Regenerated with tonic-prost 0.14
- Examples/tests: Updated for new gRPC API

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-03 07:34:26 +02: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 tli::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:50052".to_string(),
)
.with_trading_config(TradingClientConfig {
endpoint: "http://localhost:50051".to_string(),
timeout_ms: 10_000,
})
.with_backtesting_config(BacktestingClientConfig {
endpoint: "http://localhost:50052".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(())
}