rust_okx/api/account/requests/
risk.rs1use serde::Serialize;
2
3use crate::model::InstType;
4
5#[derive(Debug, Clone, Serialize)]
7pub struct SimulatedPosition {
8 #[serde(rename = "instId")]
9 inst_id: String,
10 #[serde(skip_serializing_if = "Option::is_none")]
11 pos: Option<String>,
12 #[serde(rename = "avgPx", skip_serializing_if = "Option::is_none")]
13 avg_px: Option<String>,
14 #[serde(skip_serializing_if = "Option::is_none")]
15 lever: Option<String>,
16}
17
18impl SimulatedPosition {
19 pub fn new(inst_id: impl Into<String>) -> Self {
21 Self {
22 inst_id: inst_id.into(),
23 pos: None,
24 avg_px: None,
25 lever: None,
26 }
27 }
28
29 pub fn position(mut self, pos: impl Into<String>) -> Self {
31 self.pos = Some(pos.into());
32 self
33 }
34
35 pub fn average_price(mut self, avg_px: impl Into<String>) -> Self {
37 self.avg_px = Some(avg_px.into());
38 self
39 }
40
41 pub fn leverage(mut self, lever: impl Into<String>) -> Self {
43 self.lever = Some(lever.into());
44 self
45 }
46}
47
48#[derive(Debug, Clone, Serialize)]
50pub struct SimulatedAsset {
51 ccy: String,
52 #[serde(skip_serializing_if = "Option::is_none")]
53 eq: Option<String>,
54}
55
56impl SimulatedAsset {
57 pub fn new(ccy: impl Into<String>) -> Self {
59 Self {
60 ccy: ccy.into(),
61 eq: None,
62 }
63 }
64
65 pub fn equity(mut self, eq: impl Into<String>) -> Self {
67 self.eq = Some(eq.into());
68 self
69 }
70}
71
72#[derive(Debug, Clone, Default, Serialize)]
74pub struct SimulatedMarginRequest {
75 #[serde(rename = "instType", skip_serializing_if = "Option::is_none")]
76 inst_type: Option<InstType>,
77 #[serde(rename = "inclRealPos", skip_serializing_if = "Option::is_none")]
78 include_real_positions: Option<bool>,
79 #[serde(rename = "spotOffsetType", skip_serializing_if = "Option::is_none")]
80 spot_offset_type: Option<String>,
81 #[serde(rename = "simPos", skip_serializing_if = "Option::is_none")]
82 simulated_positions: Option<Vec<SimulatedPosition>>,
83}
84
85impl SimulatedMarginRequest {
86 pub fn new() -> Self {
88 Self::default()
89 }
90
91 pub fn inst_type(mut self, inst_type: InstType) -> Self {
93 self.inst_type = Some(inst_type);
94 self
95 }
96
97 pub fn include_real_positions(mut self, include_real_positions: bool) -> Self {
99 self.include_real_positions = Some(include_real_positions);
100 self
101 }
102
103 pub fn spot_offset_type(mut self, spot_offset_type: impl Into<String>) -> Self {
105 self.spot_offset_type = Some(spot_offset_type.into());
106 self
107 }
108
109 pub fn simulated_positions(mut self, simulated_positions: Vec<SimulatedPosition>) -> Self {
111 self.simulated_positions = Some(simulated_positions);
112 self
113 }
114}
115
116#[derive(Debug, Clone, Default, Serialize)]
118pub struct AccountPositionTiersRequest {
119 #[serde(rename = "instType", skip_serializing_if = "Option::is_none")]
120 inst_type: Option<InstType>,
121 #[serde(rename = "uly", skip_serializing_if = "Option::is_none")]
122 underlying: Option<String>,
123 #[serde(rename = "instFamily", skip_serializing_if = "Option::is_none")]
124 inst_family: Option<String>,
125}
126
127impl AccountPositionTiersRequest {
128 pub fn new() -> Self {
130 Self::default()
131 }
132
133 pub fn inst_type(mut self, inst_type: InstType) -> Self {
135 self.inst_type = Some(inst_type);
136 self
137 }
138
139 pub fn underlying(mut self, underlying: impl Into<String>) -> Self {
141 self.underlying = Some(underlying.into());
142 self
143 }
144
145 pub fn inst_family(mut self, inst_family: impl Into<String>) -> Self {
147 self.inst_family = Some(inst_family.into());
148 self
149 }
150}
151
152#[derive(Debug, Clone, Default, Serialize)]
154pub struct PositionBuilderRequest {
155 #[serde(rename = "acctLv", skip_serializing_if = "Option::is_none")]
156 acct_lv: Option<String>,
157 #[serde(rename = "inclRealPosAndEq", skip_serializing_if = "Option::is_none")]
158 include_real_positions_and_equity: Option<bool>,
159 #[serde(skip_serializing_if = "Option::is_none")]
160 lever: Option<String>,
161 #[serde(rename = "greeksType", skip_serializing_if = "Option::is_none")]
162 greeks_type: Option<String>,
163 #[serde(rename = "simPos", skip_serializing_if = "Option::is_none")]
164 simulated_positions: Option<Vec<SimulatedPosition>>,
165 #[serde(rename = "simAsset", skip_serializing_if = "Option::is_none")]
166 simulated_assets: Option<Vec<SimulatedAsset>>,
167 #[serde(rename = "idxVol", skip_serializing_if = "Option::is_none")]
168 index_volatility: Option<String>,
169}
170
171impl PositionBuilderRequest {
172 pub fn new() -> Self {
174 Self::default()
175 }
176
177 pub fn account_level(mut self, acct_lv: impl Into<String>) -> Self {
179 self.acct_lv = Some(acct_lv.into());
180 self
181 }
182
183 pub fn include_real_positions_and_equity(mut self, include: bool) -> Self {
185 self.include_real_positions_and_equity = Some(include);
186 self
187 }
188
189 pub fn leverage(mut self, lever: impl Into<String>) -> Self {
191 self.lever = Some(lever.into());
192 self
193 }
194
195 pub fn greeks_type(mut self, greeks_type: impl Into<String>) -> Self {
197 self.greeks_type = Some(greeks_type.into());
198 self
199 }
200
201 pub fn simulated_positions(mut self, simulated_positions: Vec<SimulatedPosition>) -> Self {
203 self.simulated_positions = Some(simulated_positions);
204 self
205 }
206
207 pub fn simulated_assets(mut self, simulated_assets: Vec<SimulatedAsset>) -> Self {
209 self.simulated_assets = Some(simulated_assets);
210 self
211 }
212
213 pub fn index_volatility(mut self, index_volatility: impl Into<String>) -> Self {
215 self.index_volatility = Some(index_volatility.into());
216 self
217 }
218}