Skip to main content

bulk_client/msgs/
conditional.rs

1use crate::transaction::{Action, ActionMeta};
2use serde::{Deserialize, Serialize};
3use std::sync::Arc;
4
5/// Information for either a Stop or Take-Profit Order
6#[derive(Clone, Debug, Serialize, Deserialize)]
7pub struct StopOrTP {
8    /// Which Instrument
9    #[serde(rename = "c")]
10    pub symbol: Arc<str>,
11
12    /// Indicates whether above or below threshold to trigger
13    #[serde(rename = "d")]
14    pub is_above: bool,
15
16    /// Size to be done if triggered
17    #[serde(rename = "sz", with = "crate::msgs::fixed_point")]
18    pub size: f64,
19
20    /// Trigger threshold
21    #[serde(rename = "tr", with = "crate::msgs::fixed_point")]
22    pub threshold: f64,
23
24    /// Optional limit px if will trigger a limit order
25    #[serde(
26        rename = "lim",
27        with = "crate::msgs::opt_fixed_point",
28        default = "default_limit"
29    )]
30    pub limit: Option<f64>,
31
32    #[serde(skip)]
33    pub meta: ActionMeta,
34}
35
36/// A combined take-profit + stop operating in a collar
37#[derive(Clone, Debug, Serialize, Deserialize)]
38pub struct Range {
39    /// Which Instrument
40    #[serde(rename = "c")]
41    pub symbol: Arc<str>,
42
43    /// Indicates whether the underlying position is buy or sell
44    #[serde(rename = "d")]
45    pub is_buy: bool,
46
47    /// Size to be done if triggered
48    #[serde(rename = "sz", with = "crate::msgs::fixed_point")]
49    pub size: f64,
50
51    /// Trigger threshold (low)
52    #[serde(rename = "pmin", with = "crate::msgs::fixed_point")]
53    pub collar_min: f64,
54
55    /// Trigger threshold (high)
56    #[serde(rename = "pmax", with = "crate::msgs::fixed_point")]
57    pub collar_max: f64,
58
59    /// Limit price for low trigger (or none)
60    #[serde(
61        rename = "lmin",
62        with = "crate::msgs::opt_fixed_point",
63        default = "default_limit"
64    )]
65    pub limit_min: Option<f64>,
66
67    /// Limit price for low trigger (or none)
68    #[serde(
69        rename = "lmax",
70        with = "crate::msgs::opt_fixed_point",
71        default = "default_limit"
72    )]
73    pub limit_max: Option<f64>,
74
75    #[serde(skip)]
76    pub meta: ActionMeta,
77}
78
79/// Trigger evaluates a collection of actions when trigger reached
80#[derive(Clone, Debug, Serialize, Deserialize)]
81pub struct Trigger {
82    /// Which Instrument
83    #[serde(rename = "c")]
84    pub symbol: Arc<str>,
85
86    /// Indicates whether the trigger is above or below
87    #[serde(rename = "d")]
88    pub is_above: bool,
89
90    /// Trigger threshold
91    #[serde(rename = "tr", with = "crate::msgs::fixed_point")]
92    pub threshold: f64,
93
94    /// Actions to be evaluated on trigger
95    pub actions: Vec<Action>,
96
97    #[serde(skip)]
98    pub meta: ActionMeta,
99}
100
101/// Trailing stop configuration.
102///
103/// The executor materializes this as a protective stop leg plus a rotating
104/// sentinel leg that ratchets the stop when price moves favorably by `step_bps`.
105#[derive(Clone, Debug, Serialize, Deserialize)]
106#[serde(rename_all = "camelCase")]
107pub struct Trailing {
108    /// Which Instrument
109    #[serde(rename = "c")]
110    pub symbol: Arc<str>,
111
112    /// Indicates whether protected position direction is buy/long.
113    #[serde(rename = "b")]
114    pub is_buy: bool,
115
116    /// Size to be done if triggered
117    #[serde(rename = "sz", with = "crate::msgs::fixed_point")]
118    pub size: f64,
119
120    /// Trailing distance in basis points.
121    #[serde(rename = "trb")]
122    pub trail_bps: u32,
123
124    /// Favorable reset step in basis points.
125    #[serde(rename = "stb")]
126    pub step_bps: u32,
127
128    /// Optional limit px if stop trigger should place a limit order.
129    #[serde(
130        rename = "lim",
131        with = "crate::msgs::opt_fixed_point",
132        default = "default_limit"
133    )]
134    pub limit: Option<f64>,
135
136    #[serde(skip)]
137    pub meta: ActionMeta,
138}
139
140/// On-fill registration.
141///
142/// Registers follow-up actions that should execute once the parent action
143/// (identified by `parent_seqno` in the same transaction) receives its first fill.
144#[derive(Clone, Debug, Serialize, Deserialize)]
145#[serde(rename_all = "camelCase")]
146pub struct OnFill {
147    /// Parent action sequence index in the same transaction.
148    #[serde(rename = "p")]
149    pub parent_seqno: u32,
150
151    /// Actions to execute on first parent fill.
152    pub actions: Vec<Action>,
153
154    #[serde(skip)]
155    pub meta: ActionMeta,
156}
157
158fn default_limit() -> Option<f64> {
159    None
160}