feat(fxt): wire broker check subcommand into CLI
Add Broker variant to Commands enum with BrokerArgs (flatten), route to execute_broker_command in match block (no JWT required), exit(1) on check failure. Clone config.api_gateway_url to avoid partial move. Add two CLI parsing tests for broker check. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -21,6 +21,7 @@ use fxt::{
|
||||
agent::{execute_agent_command, AgentArgs},
|
||||
auth::{execute_auth_command, AuthCommand},
|
||||
backtest_ml::{execute_backtest_ml_command, BacktestMlArgs},
|
||||
broker::{execute_broker_command, BrokerArgs},
|
||||
model::{execute_model_command, ModelCommand},
|
||||
trade::{execute_trade_command, TradeArgs},
|
||||
train::{execute_train_command, TrainCommand},
|
||||
@@ -212,6 +213,21 @@ enum Commands {
|
||||
trade_args: TradeArgs,
|
||||
},
|
||||
|
||||
/// Broker connectivity check
|
||||
#[clap(
|
||||
long_about = "Validate broker connectivity.\n\n\
|
||||
Checks:\n\
|
||||
1. Direct IB Gateway: TCP + ibapi handshake\n\
|
||||
2. Broker Gateway gRPC: HealthCheck + SessionStatus\n\n\
|
||||
Examples:\n\
|
||||
fxt broker check\n\
|
||||
fxt broker check --host 10.0.0.5 --port 4002\n\
|
||||
fxt broker check --skip-ibkr"
|
||||
)]
|
||||
Broker {
|
||||
#[command(flatten)]
|
||||
broker_args: BrokerArgs,
|
||||
},
|
||||
}
|
||||
|
||||
/// JWT token claims structure for validation
|
||||
@@ -381,7 +397,7 @@ async fn main() -> Result<()> {
|
||||
// Merge: CLI args override config file (precedence: CLI > Config > Default)
|
||||
if cli.api_gateway_url == "http://localhost:50051" {
|
||||
// Using default, check if config has override
|
||||
cli.api_gateway_url = config.api_gateway_url;
|
||||
cli.api_gateway_url = config.api_gateway_url.clone();
|
||||
}
|
||||
|
||||
if cli.log_level == "info" {
|
||||
@@ -432,6 +448,13 @@ async fn main() -> Result<()> {
|
||||
let jwt_token = load_jwt_token(&cli.api_gateway_url).await?;
|
||||
execute_trade_command(trade_args, &cli.api_gateway_url, &jwt_token).await
|
||||
}
|
||||
Commands::Broker { broker_args } => {
|
||||
let passed = execute_broker_command(broker_args, &config).await?;
|
||||
if !passed {
|
||||
std::process::exit(1);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
#[cfg(test)]
|
||||
@@ -537,4 +560,31 @@ mod tests {
|
||||
_ => panic!("Expected Auth command"),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cli_parsing_broker_check() {
|
||||
let cli = Cli::parse_from(&["fxt", "broker", "check"]);
|
||||
match cli.command {
|
||||
Commands::Broker { .. } => {},
|
||||
_ => panic!("Expected Broker command"),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cli_parsing_broker_check_with_flags() {
|
||||
let cli = Cli::parse_from(&[
|
||||
"fxt",
|
||||
"broker",
|
||||
"check",
|
||||
"--host",
|
||||
"10.0.0.5",
|
||||
"--port",
|
||||
"4001",
|
||||
"--skip-gateway",
|
||||
]);
|
||||
match cli.command {
|
||||
Commands::Broker { .. } => {},
|
||||
_ => panic!("Expected Broker command"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user