Skip to content

Commit

Permalink
pcli: support --limit-order flag for tx orders
Browse files Browse the repository at this point in the history
  • Loading branch information
erwanor committed Jul 11, 2023
1 parent ea4d38c commit 2907908
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion crates/bin/pcli/src/command/tx/liquidity_position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ pub enum OrderCmd {
/// Only spend funds originally received by the given address index.
#[clap(long, default_value = "0")]
source: u32,
/// When set, tags the position as being a limit-sell order.
#[clap(long)]
limit_order: bool,
},
Sell {
/// The desired sale, formatted as a string, e.g. `[email protected]` would attempt
Expand All @@ -106,6 +109,9 @@ pub enum OrderCmd {
/// Only spend funds originally received by the given address index.
#[clap(long, default_value = "0")]
source: u32,
/// When set, tags the position as being a limit-sell order.
#[clap(long)]
limit_order: bool,
},
}

Expand All @@ -124,13 +130,20 @@ impl OrderCmd {
}
}

pub fn limit_order(&self) -> bool {
match self {
OrderCmd::Buy { limit_order, .. } => *limit_order,
OrderCmd::Sell { limit_order, .. } => *limit_order,
}
}

pub fn into_position<R: CryptoRngCore>(
&self,
// Preserved since we'll need it after denom metadata refactor
_asset_cache: &asset::Cache,
rng: R,
) -> Result<Position> {
let position = match self {
let mut position = match self {
OrderCmd::Buy { buy_order, .. } => {
tracing::info!(?buy_order, "parsing buy order");
let order = BuyOrder::parse_str(&buy_order)?;
Expand All @@ -144,6 +157,10 @@ impl OrderCmd {
};
tracing::info!(?position);

if self.limit_order() {
position.close_on_fill = true;
}

Ok(position)
}
}

0 comments on commit 2907908

Please sign in to comment.