Skip to main content

bulk_client/msgs/
conditional.rs

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