mostro_client/cli/
list_orders.rs1use anyhow::Result;
2use mostro_core::prelude::*;
3use nostr_sdk::prelude::*;
4use std::str::FromStr;
5
6use crate::pretty_table::print_orders_table;
7use crate::util::get_orders_list;
8
9pub async fn execute_list_orders(
10 kind: &Option<String>,
11 currency: &Option<String>,
12 status: &Option<String>,
13 mostro_key: PublicKey,
14 client: &Client,
15) -> Result<()> {
16 let mut upper_currency: Option<String> = None;
18 let mut status_checked: Option<Status> = Some(Status::from_str("pending").unwrap());
19 let mut kind_checked: Option<mostro_core::order::Kind> = None;
20
21 if let Some(s) = status {
23 status_checked = Some(Status::from_str(s).expect("Not valid status! Please check"));
24 }
25
26 println!(
27 "You are searching orders with status {:?}",
28 status_checked.unwrap()
29 );
30 if let Some(k) = kind {
32 kind_checked = Some(
33 mostro_core::order::Kind::from_str(k).expect("Not valid order kind! Please check"),
34 );
35 println!("You are searching {} orders", kind_checked.unwrap());
36 }
37
38 if let Some(curr) = currency {
40 upper_currency = Some(curr.to_uppercase());
41 println!(
42 "You are searching orders with currency {}",
43 upper_currency.clone().unwrap()
44 );
45 }
46
47 println!(
48 "Requesting orders from mostro pubId - {}",
49 mostro_key.clone()
50 );
51
52 let table_of_orders = get_orders_list(
54 mostro_key,
55 status_checked.unwrap(),
56 upper_currency,
57 kind_checked,
58 client,
59 )
60 .await?;
61 let table = print_orders_table(table_of_orders)?;
62 println!("{table}");
63
64 Ok(())
65}