mod activity;
mod builders;
mod holders;
mod live_volume;
mod open_interest;
mod positions;
mod traded;
mod trades;
use clap::{Subcommand, ValueEnum};
use color_eyre::eyre::Result;
use polyte_data::DataApi;
use crate::commands::data::{
activity::UserActivityCommand, holders::HoldersCommand, live_volume::LiveVolumeCommand,
open_interest::OpenInterestCommand, positions::PositionsCommand, traded::TradedCommand,
};
#[derive(Subcommand)]
pub enum DataCommand {
Health,
Activity(UserActivityCommand),
Builders {
#[command(subcommand)]
command: builders::BuildersCommand,
},
Holders(HoldersCommand),
Trades {
#[command(subcommand)]
command: trades::TradesCommand,
},
Traded(TradedCommand),
Positions(PositionsCommand),
OpenInterest(OpenInterestCommand),
LiveVolume(LiveVolumeCommand),
}
impl DataCommand {
pub async fn run(self) -> Result<()> {
let data = DataApi::new()?;
match self {
Self::Health => {
let health = data.health().check().await?;
println!("{}", serde_json::to_string_pretty(&health)?);
Ok(())
}
Self::Activity(cmd) => cmd.run(&data).await,
Self::Builders { command } => command.run(&data).await,
Self::Holders(cmd) => cmd.run(&data).await,
Self::Trades { command } => command.run(&data).await,
Self::Traded(cmd) => cmd.run(&data).await,
Self::Positions(cmd) => cmd.run(&data).await,
Self::OpenInterest(cmd) => cmd.run(&data).await,
Self::LiveVolume(cmd) => cmd.run(&data).await,
}
}
}
#[derive(Debug, Clone, Copy, ValueEnum, Default)]
pub enum SortOrder {
Asc,
#[default]
Desc,
}
impl From<SortOrder> for polyte_data::types::SortDirection {
fn from(order: SortOrder) -> Self {
match order {
SortOrder::Asc => Self::Asc,
SortOrder::Desc => Self::Desc,
}
}
}