mod historical;
mod run;
use clap::{ArgAction, Parser, Subcommand as ClapSubcommand};
use std::error::Error;
const DEFAULT_SYMBOL: &str = "SOXL";
#[derive(Parser)]
#[command(
about = concat!(
env!("CARGO_PKG_DESCRIPTION"),
"\n\n",
"More information can be found at: ",
env!("CARGO_PKG_HOMEPAGE"),
),
version,
disable_version_flag = true
)]
struct Cli {
#[arg(short, long, help = "Print version", action = ArgAction::Version)]
_version: Option<bool>,
#[arg(long, default_value = "127.0.0.1:4001")]
address: String,
#[arg(long, default_value_t = 100)]
client_id: i32,
#[command(subcommand)]
command: Option<Subcommand>,
}
#[derive(ClapSubcommand)]
enum Subcommand {
#[command(about = "Run the trading bot (default)")]
Run(run::Args),
#[command(about = "Fetch historical market data as CSV")]
Historical(historical::Args),
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let cli = Cli::parse();
match cli.command {
Some(Subcommand::Run(args)) => run::run(&cli.address, cli.client_id, &args).await,
Some(Subcommand::Historical(args)) => {
historical::run(&cli.address, cli.client_id, &args).await
}
None => run::run(&cli.address, cli.client_id, &run::Args::default()).await,
}
}
#[cfg(test)]
mod tests {
use super::Cli;
use clap::CommandFactory;
#[test]
fn verify_cli() {
Cli::command().debug_assert();
}
}