longport/trade/requests/
estimate_max_purchase_quantity.rs
1use rust_decimal::Decimal;
2use serde::Serialize;
3
4use crate::trade::{OrderSide, OrderType};
5
6#[derive(Debug, Serialize, Clone)]
8pub struct EstimateMaxPurchaseQuantityOptions {
9 symbol: String,
10 order_type: OrderType,
11 #[serde(skip_serializing_if = "Option::is_none")]
12 price: Option<Decimal>,
13 side: OrderSide,
14 #[serde(skip_serializing_if = "Option::is_none")]
15 currency: Option<String>,
16 #[serde(skip_serializing_if = "Option::is_none")]
17 order_id: Option<String>,
18 fractional_shares: bool,
19}
20
21impl EstimateMaxPurchaseQuantityOptions {
22 #[inline]
24 pub fn new(symbol: impl Into<String>, order_type: OrderType, side: OrderSide) -> Self {
25 Self {
26 symbol: symbol.into(),
27 order_type,
28 price: None,
29 side,
30 currency: None,
31 order_id: None,
32 fractional_shares: false,
33 }
34 }
35
36 #[inline]
38 #[must_use]
39 pub fn price(self, price: Decimal) -> Self {
40 Self {
41 price: Some(price),
42 ..self
43 }
44 }
45
46 #[inline]
48 #[must_use]
49 pub fn currency(self, currency: impl Into<String>) -> Self {
50 Self {
51 currency: Some(currency.into()),
52 ..self
53 }
54 }
55
56 #[inline]
58 #[must_use]
59 pub fn order_id(self, order_id: impl Into<String>) -> Self {
60 Self {
61 order_id: Some(order_id.into()),
62 ..self
63 }
64 }
65
66 pub fn fractional_shares(self) -> Self {
68 Self {
69 fractional_shares: true,
70 ..self
71 }
72 }
73}