1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use anyhow::Result;
use mostro_core::order::{Kind, Status};
use nostr_sdk::prelude::*;
use std::str::FromStr;

use crate::pretty_table::print_orders_table;
use crate::util::get_orders_list;

pub async fn execute_list_orders(
    kind: &Option<String>,
    currency: &Option<String>,
    status: &Option<String>,
    mostro_key: PublicKey,
    client: &Client,
) -> Result<()> {
    // Used to get upper currency string to check against a list of tickers
    let mut upper_currency: Option<String> = None;
    let mut status_checked: Option<Status> = Some(Status::from_str("pending").unwrap());
    let mut kind_checked: Option<Kind> = None;

    // New check against strings
    if let Some(s) = status {
        status_checked = Some(Status::from_str(s).expect("Not valid status! Please check"));
    }

    println!(
        "You are searching orders with status {:?}",
        status_checked.unwrap()
    );
    // New check against strings
    if let Some(k) = kind {
        kind_checked = Some(Kind::from_str(k).expect("Not valid order kind! Please check"));
        println!(
            "You are searching {} orders",
            kind_checked.unwrap().to_string()
        );
    }

    // Uppercase currency
    if let Some(curr) = currency {
        upper_currency = Some(curr.to_uppercase());
        println!(
            "You are searching orders with currency {}",
            upper_currency.clone().unwrap()
        );
    }

    println!(
        "Requesting orders from mostro pubId - {}",
        mostro_key.clone()
    );

    // Get orders from relays
    let table_of_orders = get_orders_list(
        mostro_key,
        status_checked.unwrap(),
        upper_currency,
        kind_checked,
        client,
    )
    .await?;
    let table = print_orders_table(table_of_orders)?;
    println!("{table}");

    Ok(())
}