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