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
//! Crypto-bank telegram bot balances command.

use telegram_client::Message;

use cxmr_balances::IntoPrice;
use cxmr_broker::SharedBroker;
use cxmr_exchanges::Market;

use crate::{ChatClient, Error};

/// Bitcoin price command.
pub async fn btc(
    chat: &ChatClient,
    msg: &Message,
    broker: &SharedBroker,
) -> Result<Message, Error> {
    chat.send(
        &msg.chat,
        format!(
            "Current BTC price: ${:.2}",
            broker
                .read()
                .await
                .get_market(Market::BinanceBtcUsdt)?
                .bids()
                .first()?
                .into_price()
        ),
    )
    .await
}