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
use rust_decimal::Decimal;
use serde::Serialize;

use crate::trade::{OrderSide, OrderType};

/// Options for estimate maximum purchase quantity
#[derive(Debug, Serialize, Clone)]
pub struct EstimateMaxPurchaseQuantityOptions {
    symbol: String,
    order_type: OrderType,
    #[serde(skip_serializing_if = "Option::is_none")]
    price: Option<Decimal>,
    side: OrderSide,
    #[serde(skip_serializing_if = "Option::is_none")]
    currency: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    order_id: Option<String>,
}

impl EstimateMaxPurchaseQuantityOptions {
    /// Create a new `EstimateMaxPurchaseQuantityOptions`
    #[inline]
    pub fn new(symbol: impl Into<String>, order_type: OrderType, side: OrderSide) -> Self {
        Self {
            symbol: symbol.into(),
            order_type,
            price: None,
            side,
            currency: None,
            order_id: None,
        }
    }

    /// Set the price
    #[inline]
    #[must_use]
    pub fn price(self, price: Decimal) -> Self {
        Self {
            price: Some(price),
            ..self
        }
    }

    /// Set the currency
    #[inline]
    #[must_use]
    pub fn currency(self, currency: impl Into<String>) -> Self {
        Self {
            currency: Some(currency.into()),
            ..self
        }
    }

    /// Set the order id
    #[inline]
    #[must_use]
    pub fn order_id(self, order_id: impl Into<String>) -> Self {
        Self {
            order_id: Some(order_id.into()),
            ..self
        }
    }
}