2026-06-09 16:07:46 +09:00
|
|
|
use clap::{Args, Parser, Subcommand};
|
2026-06-08 11:22:46 +00:00
|
|
|
use commands::account::AccountCommands;
|
|
|
|
|
use commands::api::ApiCommands;
|
2026-06-09 04:47:37 +00:00
|
|
|
use commands::cache::CacheCommands;
|
|
|
|
|
use commands::dart::DartCommands;
|
|
|
|
|
use commands::market::MarketCommand;
|
2026-06-08 11:22:46 +00:00
|
|
|
use commands::order::OrderCommands;
|
2026-06-09 04:47:37 +00:00
|
|
|
use commands::universe::UniverseCommands;
|
2026-06-08 11:22:46 +00:00
|
|
|
|
|
|
|
|
mod apis;
|
|
|
|
|
mod commands;
|
|
|
|
|
mod core;
|
|
|
|
|
mod providers;
|
|
|
|
|
|
|
|
|
|
#[derive(Parser)]
|
|
|
|
|
#[command(
|
|
|
|
|
name = env!("CARGO_PKG_NAME"),
|
|
|
|
|
about = "CLI로 사용하는 증권 API",
|
|
|
|
|
version = env!("CARGO_PKG_VERSION"),
|
|
|
|
|
help_template = "{name}:: {about}\n 사용방법:: {usage}\n\n{all-args}"
|
|
|
|
|
)]
|
|
|
|
|
struct Cli {
|
|
|
|
|
#[command(subcommand)]
|
|
|
|
|
command: Option<Commands>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Subcommand)]
|
|
|
|
|
enum Commands {
|
|
|
|
|
/// 애플리케이션 버젼 표시
|
|
|
|
|
Version,
|
|
|
|
|
|
2026-06-09 15:54:35 +09:00
|
|
|
/// 설치된 openstock 바이너리 업데이트
|
2026-06-09 16:07:46 +09:00
|
|
|
Update(UpdateCommand),
|
2026-06-09 15:54:35 +09:00
|
|
|
|
2026-06-08 11:22:46 +00:00
|
|
|
/// 증권사 API 리스트 조회 및 API 설정
|
|
|
|
|
Api {
|
|
|
|
|
#[command(subcommand)]
|
|
|
|
|
sub: ApiCommands,
|
|
|
|
|
},
|
|
|
|
|
|
2026-06-09 04:47:37 +00:00
|
|
|
/// OpenDART 공시정보 조회
|
|
|
|
|
Dart {
|
|
|
|
|
#[command(subcommand)]
|
|
|
|
|
sub: DartCommands,
|
|
|
|
|
},
|
|
|
|
|
|
2026-06-08 11:22:46 +00:00
|
|
|
/// 계좌 조회 및 관리
|
|
|
|
|
Account {
|
|
|
|
|
#[command(subcommand)]
|
|
|
|
|
sub: AccountCommands,
|
|
|
|
|
},
|
|
|
|
|
|
2026-06-09 04:47:37 +00:00
|
|
|
/// 로컬 캐시 상태 조회 및 용량 정리
|
|
|
|
|
Cache {
|
|
|
|
|
#[command(subcommand)]
|
|
|
|
|
sub: CacheCommands,
|
|
|
|
|
},
|
|
|
|
|
|
2026-06-08 11:22:46 +00:00
|
|
|
/// 주문 실행 및 조회
|
|
|
|
|
Order {
|
|
|
|
|
#[command(subcommand)]
|
|
|
|
|
sub: OrderCommands,
|
|
|
|
|
},
|
|
|
|
|
|
2026-06-09 04:47:37 +00:00
|
|
|
/// 종목 universe 캐시 구축 및 조회
|
|
|
|
|
Universe {
|
|
|
|
|
#[command(subcommand)]
|
|
|
|
|
sub: UniverseCommands,
|
|
|
|
|
},
|
|
|
|
|
|
2026-06-08 11:22:46 +00:00
|
|
|
/// 종목 검색
|
|
|
|
|
Search {
|
|
|
|
|
/// 종목명 또는 종목코드
|
|
|
|
|
query: String,
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/// 종목 정보 및 기업정보 조회
|
2026-06-09 04:47:37 +00:00
|
|
|
Market(MarketCommand),
|
2026-06-08 11:22:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
|
let cli = Cli::parse();
|
|
|
|
|
|
|
|
|
|
match &cli.command {
|
|
|
|
|
Some(Commands::Version) => commands::handle_version(),
|
2026-06-09 16:07:46 +09:00
|
|
|
Some(Commands::Update(command)) => commands::handle_update(command),
|
2026-06-08 11:22:46 +00:00
|
|
|
Some(Commands::Api { sub }) => commands::handle_api(sub),
|
2026-06-09 04:47:37 +00:00
|
|
|
Some(Commands::Dart { sub }) => commands::handle_dart(sub),
|
2026-06-08 11:22:46 +00:00
|
|
|
Some(Commands::Account { sub }) => commands::handle_account(sub),
|
2026-06-09 04:47:37 +00:00
|
|
|
Some(Commands::Cache { sub }) => commands::handle_cache(sub),
|
2026-06-08 11:22:46 +00:00
|
|
|
Some(Commands::Order { sub }) => commands::handle_order(sub),
|
2026-06-09 04:47:37 +00:00
|
|
|
Some(Commands::Universe { sub }) => commands::handle_universe(sub),
|
2026-06-08 11:22:46 +00:00
|
|
|
Some(Commands::Search { query }) => commands::handle_search(query),
|
2026-06-09 04:47:37 +00:00
|
|
|
Some(Commands::Market(command)) => commands::handle_market(command),
|
2026-06-08 11:22:46 +00:00
|
|
|
None => {
|
|
|
|
|
println!(
|
|
|
|
|
"{}",
|
|
|
|
|
core::output::explained(
|
|
|
|
|
"help",
|
|
|
|
|
"명령이 지정되지 않았을 때의 사용 안내",
|
|
|
|
|
vec![
|
|
|
|
|
core::output::field(
|
|
|
|
|
"program",
|
|
|
|
|
"실행한 CLI 프로그램 이름",
|
|
|
|
|
serde_json::json!(env!("CARGO_PKG_NAME")),
|
|
|
|
|
),
|
|
|
|
|
core::output::field(
|
|
|
|
|
"usage",
|
|
|
|
|
"도움말을 확인하는 명령",
|
|
|
|
|
serde_json::json!(format!("{} --help", env!("CARGO_PKG_NAME"))),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-06-09 16:07:46 +09:00
|
|
|
|
|
|
|
|
#[derive(Args)]
|
|
|
|
|
struct UpdateCommand {
|
|
|
|
|
/// 현재 버전과 같아도 최신 release asset으로 재설치
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
force: bool,
|
|
|
|
|
}
|