longbridge/trade/requests/
submit_multileg.rs1use rust_decimal::Decimal;
2use serde::Serialize;
3
4use crate::trade::{MultiLegStrategy, OrderSide, OrderType};
5
6#[derive(Debug, Serialize, Clone)]
8pub struct SubmitMultiLegOrderLeg {
9 symbol: String,
11 ratio_quantity: Decimal,
16}
17
18impl SubmitMultiLegOrderLeg {
19 #[inline]
21 pub fn new(symbol: impl Into<String>, ratio_quantity: Decimal) -> Self {
22 Self {
23 symbol: symbol.into(),
24 ratio_quantity,
25 }
26 }
27}
28
29#[derive(Debug, Serialize, Clone)]
31pub struct SubmitMultiLegOrderOptions {
32 side: OrderSide,
33 order_type: OrderType,
34 submitted_quantity: Decimal,
35 strategy: MultiLegStrategy,
36 legs: Vec<SubmitMultiLegOrderLeg>,
37 #[serde(skip_serializing_if = "Option::is_none")]
38 submitted_price: Option<Decimal>,
39 #[serde(skip_serializing_if = "Option::is_none")]
40 remark: Option<String>,
41 #[serde(skip_serializing_if = "Option::is_none")]
42 client_request_id: Option<String>,
43}
44
45impl SubmitMultiLegOrderOptions {
46 #[inline]
48 pub fn new(
49 side: OrderSide,
50 order_type: OrderType,
51 submitted_quantity: Decimal,
52 strategy: MultiLegStrategy,
53 legs: impl IntoIterator<Item = SubmitMultiLegOrderLeg>,
54 ) -> Self {
55 Self {
56 side,
57 order_type,
58 submitted_quantity,
59 strategy,
60 legs: legs.into_iter().collect(),
61 submitted_price: None,
62 remark: None,
63 client_request_id: None,
64 }
65 }
66
67 #[inline]
71 #[must_use]
72 pub fn submitted_price(self, submitted_price: Decimal) -> Self {
73 Self {
74 submitted_price: Some(submitted_price),
75 ..self
76 }
77 }
78
79 #[inline]
81 #[must_use]
82 pub fn remark(self, remark: impl Into<String>) -> Self {
83 Self {
84 remark: Some(remark.into()),
85 ..self
86 }
87 }
88
89 #[inline]
95 #[must_use]
96 pub fn client_request_id(self, id: impl Into<String>) -> Self {
97 Self {
98 client_request_id: Some(id.into()),
99 ..self
100 }
101 }
102}