From a7d5a082f138c5a6eaf5531fc1de1e847e606758 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20Calder=C3=B3n?= Date: Wed, 2 Oct 2024 16:48:31 -0300 Subject: [PATCH] Add SmallOrder functions to format amounts --- src/order.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/order.rs b/src/order.rs index a6fa4c0..e01065d 100644 --- a/src/order.rs +++ b/src/order.rs @@ -251,4 +251,22 @@ impl SmallOrder { pub fn as_json(&self) -> Result { 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() + } + } }