mostro_client/cli/
list_orders.rs1use anyhow::Result;
2use mostro_core::order::{Kind, Status};
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<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(Kind::from_str(k).expect("Not valid order kind! Please check"));
33 println!("You are searching {} orders", kind_checked.unwrap());
34 }
35
36 if let Some(curr) = currency {
38 upper_currency = Some(curr.to_uppercase());
39 println!(
40 "You are searching orders with currency {}",
41 upper_currency.clone().unwrap()
42 );
43 }
44
45 println!(
46 "Requesting orders from mostro pubId - {}",
47 mostro_key.clone()
48 );
49
50 let table_of_orders = get_orders_list(
52 mostro_key,
53 status_checked.unwrap(),
54 upper_currency,
55 kind_checked,
56 client,
57 )
58 .await?;
59 let table = print_orders_table(table_of_orders)?;
60 println!("{table}");
61
62 Ok(())
63}