Skip to content

Commit

Permalink
Add SmallOrder functions to format amounts
Browse files Browse the repository at this point in the history
  • Loading branch information
grunch committed Oct 2, 2024
1 parent 6146feb commit a7d5a08
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,4 +251,22 @@ impl SmallOrder {
pub fn as_json(&self) -> Result<String> {
Ok(serde_json::to_string(&self)?)
}

// Get the amount of sats or the string "Market price"
pub fn sats_amount(&self) -> String {
if self.amount == 0 {
"Market price".to_string()
} else {
self.amount.to_string()
}
}

// Get the fiat amount, if the order is a range order, return the range as min-max string
pub fn fiat_amount(&self) -> String {
if self.max_amount.is_some() {
format!("{}-{}", self.min_amount.unwrap(), self.max_amount.unwrap())
} else {
self.fiat_amount.to_string()
}
}
}

0 comments on commit a7d5a08

Please sign in to comment.