use crate::cli::common::write_json_output;
use clap::{Args, Subcommand};
use polymarket_hft::client::alternativeme::{
Client, GetFearAndGreedRequest, GetGlobalRequest, GetTickerByIdRequest, GetTickerRequest,
};
#[allow(clippy::enum_variant_names)] #[derive(Subcommand)]
pub enum AlternativeMeCommands {
GetTicker {
#[command(flatten)]
params: GetTickerArgs,
},
GetTickerById {
id: String,
#[arg(short, long)]
convert: Option<String>,
},
GetGlobal {
#[arg(short, long)]
convert: Option<String>,
},
GetFearAndGreed {
#[command(flatten)]
params: GetFearAndGreedArgs,
},
}
#[derive(Args, Debug, Clone)]
pub struct GetTickerArgs {
#[arg(short, long)]
pub limit: Option<i32>,
#[arg(long)]
pub start: Option<i32>,
#[arg(short, long)]
pub convert: Option<String>,
#[arg(long)]
pub sort: Option<String>,
}
#[derive(Args, Debug, Clone)]
pub struct GetFearAndGreedArgs {
#[arg(short, long)]
pub limit: Option<i32>,
#[arg(long)]
pub date_format: Option<String>,
}
pub async fn handle(command: &AlternativeMeCommands) -> anyhow::Result<()> {
let client = Client::new();
match command {
AlternativeMeCommands::GetTicker { params } => {
let request = GetTickerRequest {
limit: params.limit,
start: params.start,
convert: params.convert.clone(),
sort: params.sort.clone(),
..Default::default()
};
let response = client.get_ticker(request).await?;
write_json_output(&response)?;
}
AlternativeMeCommands::GetTickerById { id, convert } => {
let request = GetTickerByIdRequest {
convert: convert.clone(),
..Default::default()
};
let response = client.get_ticker_by_id(id, request).await?;
write_json_output(&response)?;
}
AlternativeMeCommands::GetGlobal { convert } => {
let request = GetGlobalRequest {
convert: convert.clone(),
};
let response = client.get_global(request).await?;
write_json_output(&response)?;
}
AlternativeMeCommands::GetFearAndGreed { params } => {
let request = GetFearAndGreedRequest {
limit: params.limit,
date_format: params.date_format.clone(),
..Default::default()
};
let response = client.get_fear_and_greed(request).await?;
write_json_output(&response)?;
}
}
Ok(())
}