#[cfg(feature = "cli")]
use clap::builder::styling::{AnsiColor, Effects, Styles};
#[cfg(feature = "cli")]
use clap::{Args, Parser, Subcommand};
#[cfg(feature = "cli")]
fn styles() -> Styles {
Styles::styled()
.header(AnsiColor::Red.on_default() | Effects::BOLD)
.usage(AnsiColor::Red.on_default() | Effects::BOLD)
.literal(AnsiColor::Blue.on_default() | Effects::BOLD)
.error(AnsiColor::Red.on_default() | Effects::BOLD)
.placeholder(AnsiColor::Green.on_default())
}
#[cfg(feature = "cli")]
#[derive(Parser, Debug, Clone)]
#[command(
author = "Mahmoud Harmouch",
version,
name = "openbook",
propagate_version = true,
styles = styles(),
help_template = r#"{before-help}{name} {version}
{about-with-newline}
{usage-heading} {usage}
{all-args}{after-help}
AUTHORS:
{author}
"#,
about=r#"
████████
██████████
████ ████
████ ████
████ ███████████
████ ███████████
███ ████
██ ████
█ █████
████████
█████
📖1️⃣2️⃣ A CLI, TUI and SDK to interact with OpenBook V1 and V2 markets on the Solana blockchain.
FUNCTIONALITIES:
- Place Limit Bid: Place a limit bid in the OpenBook market.
- Cancel Order: Cancel an existing order in the OpenBook market.
- Settle Balance: Settle balances in the OpenBook market.
- Match Orders Transaction: Match orders transactions in the OpenBook market.
- Consume Events Instruction: Consume events instructions in the OpenBook market.
- Consume Events Permissioned Instruction: Consume events permissioned instructions in the OpenBook market.
- Load Orders For Owner: Load orders for a specific owner in the OpenBook market.
- Find Open Orders Accounts For Owner: Find open orders accounts for a specific owner in the OpenBook market.
USAGE:
openbook [OPTIONS] <COMMAND>
EXAMPLES:
Launch TUI:
openbook
Place a bid limit order on openbook v1 market:
openbook v1 place -t 5.0 -s bid -b 5. -e -p 2.1
Place a ask limit order on openbook v1 market:
openbook v1 place -t 5.0 -s ask -b 5. -e -p 2.1
Cancel all limit orders on openbook v1 market:
openbook v1 cancel -e
Settle balances on openbook v1 market:
openbook v1 settle -e
For more information, visit: github.com/gigadao/openbook
"#
)]
pub struct Cli {
#[arg(short, long, action = clap::ArgAction::Count)]
pub debug: u8,
#[command(subcommand)]
pub command: Option<Commands>,
}
#[cfg(feature = "cli")]
#[derive(Subcommand, Debug, Clone, PartialEq)]
pub enum Commands {
V1(V1),
V2(V2),
}
#[cfg(feature = "cli")]
#[derive(Args, Debug, Clone, PartialEq)]
pub struct V1 {
#[arg(short, long, default_value_t = String::from("8BnEgHoWFysVcuFFX7QztDmzuH8r5ZFvyP3sYwn1XTh6"))]
pub market_id: String,
#[command(subcommand)]
pub command: Option<V1ActionsCommands>,
}
#[cfg(feature = "cli")]
#[derive(Args, Debug, Clone, PartialEq)]
pub struct V2 {
#[arg(short, long, default_value_t = String::from("gQN1TNHiqj5x82ZQd7JZ8rm8WD4xwWtXxd4onReWZNK"))]
pub market_id: String,
#[command(subcommand)]
pub command: Option<V2ActionsCommands>,
}
#[cfg(feature = "cli")]
#[derive(Subcommand, Debug, Clone, PartialEq)]
pub enum V1ActionsCommands {
Place(Place),
Cancel(Cancel),
Settle(Settle),
Match(Match),
CancelSettlePlace(CancelSettlePlace),
CancelSettlePlaceBid(CancelSettlePlaceBid),
CancelSettlePlaceAsk(CancelSettlePlaceAsk),
Consume(Consume),
ConsumePermissioned(ConsumePermissioned),
Load(Load),
Find(Find),
Info(Info),
}
#[cfg(feature = "cli")]
#[derive(Subcommand, Debug, Clone, PartialEq)]
pub enum V2ActionsCommands {
Info(Info),
Place(PlaceV2),
}
#[cfg(feature = "cli")]
#[derive(Args, Debug, Clone, PartialEq)]
pub struct PlaceV2 {
#[arg(short, long)]
pub target_amount_quote: f64,
#[arg(short, long)]
pub side: String,
#[arg(short, long)]
pub price_target: f64,
}
#[cfg(feature = "cli")]
#[derive(Args, Debug, Clone, PartialEq)]
pub struct Place {
#[arg(short, long)]
pub target_amount_quote: f64,
#[arg(short, long)]
pub side: String,
#[arg(short, long)]
pub best_offset_usdc: f64,
#[arg(short, long)]
pub execute: bool,
#[arg(short, long)]
pub price_target: f64,
}
#[cfg(feature = "cli")]
#[derive(Args, Debug, Clone, PartialEq)]
pub struct CancelSettlePlace {
#[arg(short, long)]
pub usdc_ask_target: f64,
#[arg(short, long)]
pub target_usdc_bid: f64,
#[arg(short, long)]
pub price_jlp_usdc_bid: f64,
#[arg(short, long)]
pub ask_price_jlp_usdc: f64,
}
#[cfg(feature = "cli")]
#[derive(Args, Debug, Clone, PartialEq)]
pub struct CancelSettlePlaceBid {
#[arg(short, long)]
pub target_size_usdc_bid: f64,
#[arg(short, long)]
pub bid_price_jlp_usdc: f64,
}
#[cfg(feature = "cli")]
#[derive(Args, Debug, Clone, PartialEq)]
pub struct CancelSettlePlaceAsk {
#[arg(short, long)]
pub target_size_usdc_ask: f64,
#[arg(short, long)]
pub ask_price_jlp_usdc: f64,
}
#[cfg(feature = "cli")]
#[derive(Args, Debug, Clone, PartialEq)]
pub struct Cancel {
#[arg(short, long)]
pub execute: bool,
}
#[cfg(feature = "cli")]
#[derive(Args, Debug, Clone, PartialEq)]
pub struct Settle {
#[arg(short, long)]
pub execute: bool,
}
#[cfg(feature = "cli")]
#[derive(Args, Debug, Clone, PartialEq)]
pub struct Match {
#[arg(short, long)]
pub limit: u16,
}
#[cfg(feature = "cli")]
#[derive(Args, Debug, Clone, PartialEq)]
pub struct Consume {
#[arg(short, long)]
pub limit: u16,
}
#[cfg(feature = "cli")]
#[derive(Args, Debug, Clone, PartialEq)]
pub struct ConsumePermissioned {
#[arg(short, long)]
pub limit: u16,
}
#[cfg(feature = "cli")]
#[derive(Args, Debug, Clone, PartialEq)]
pub struct Load {}
#[cfg(feature = "cli")]
#[derive(Args, Debug, Clone, PartialEq)]
pub struct Find {}
#[cfg(feature = "cli")]
#[derive(Args, Debug, Clone, PartialEq)]
pub struct Info {}