rust_okx/api/account/requests/
risk.rs1use std::borrow::Cow;
2
3use serde::Serialize;
4
5use crate::model::InstType;
6
7#[derive(Debug, Clone, Serialize)]
9pub struct SimulatedPosition<'a> {
10 #[serde(rename = "instId")]
11 inst_id: Cow<'a, str>,
12 #[serde(skip_serializing_if = "Option::is_none")]
13 pos: Option<Cow<'a, str>>,
14 #[serde(rename = "avgPx", skip_serializing_if = "Option::is_none")]
15 avg_px: Option<Cow<'a, str>>,
16 #[serde(skip_serializing_if = "Option::is_none")]
17 lever: Option<Cow<'a, str>>,
18}
19
20impl<'a> SimulatedPosition<'a> {
21 pub fn new(inst_id: impl Into<Cow<'a, str>>) -> Self {
23 Self {
24 inst_id: inst_id.into(),
25 pos: None,
26 avg_px: None,
27 lever: None,
28 }
29 }
30
31 pub fn position(mut self, pos: impl Into<Cow<'a, str>>) -> Self {
33 self.pos = Some(pos.into());
34 self
35 }
36
37 pub fn average_price(mut self, avg_px: impl Into<Cow<'a, str>>) -> Self {
39 self.avg_px = Some(avg_px.into());
40 self
41 }
42
43 pub fn leverage(mut self, lever: impl Into<Cow<'a, str>>) -> Self {
45 self.lever = Some(lever.into());
46 self
47 }
48}
49
50#[derive(Debug, Clone, Serialize)]
52pub struct SimulatedAsset<'a> {
53 ccy: Cow<'a, str>,
54 #[serde(skip_serializing_if = "Option::is_none")]
55 eq: Option<Cow<'a, str>>,
56}
57
58impl<'a> SimulatedAsset<'a> {
59 pub fn new(ccy: impl Into<Cow<'a, str>>) -> Self {
61 Self {
62 ccy: ccy.into(),
63 eq: None,
64 }
65 }
66
67 pub fn equity(mut self, eq: impl Into<Cow<'a, str>>) -> Self {
69 self.eq = Some(eq.into());
70 self
71 }
72}
73
74#[derive(Debug, Clone, Default, Serialize)]
76pub struct SimulatedMarginRequest<'a> {
77 #[serde(rename = "instType", skip_serializing_if = "Option::is_none")]
78 inst_type: Option<InstType>,
79 #[serde(rename = "inclRealPos", skip_serializing_if = "Option::is_none")]
80 include_real_positions: Option<bool>,
81 #[serde(rename = "spotOffsetType", skip_serializing_if = "Option::is_none")]
82 spot_offset_type: Option<Cow<'a, str>>,
83 #[serde(rename = "simPos", skip_serializing_if = "Option::is_none")]
84 simulated_positions: Option<Vec<SimulatedPosition<'a>>>,
85}
86
87impl<'a> SimulatedMarginRequest<'a> {
88 pub fn new() -> Self {
90 Self::default()
91 }
92
93 pub fn inst_type(mut self, inst_type: InstType) -> Self {
95 self.inst_type = Some(inst_type);
96 self
97 }
98
99 pub fn include_real_positions(mut self, include_real_positions: bool) -> Self {
101 self.include_real_positions = Some(include_real_positions);
102 self
103 }
104
105 pub fn spot_offset_type(mut self, spot_offset_type: impl Into<Cow<'a, str>>) -> Self {
107 self.spot_offset_type = Some(spot_offset_type.into());
108 self
109 }
110
111 pub fn simulated_positions(mut self, simulated_positions: Vec<SimulatedPosition<'a>>) -> Self {
113 self.simulated_positions = Some(simulated_positions);
114 self
115 }
116}
117
118#[derive(Debug, Clone, Default, Serialize)]
120pub struct AccountPositionTiersRequest<'a> {
121 #[serde(rename = "instType", skip_serializing_if = "Option::is_none")]
122 inst_type: Option<InstType>,
123 #[serde(rename = "uly", skip_serializing_if = "Option::is_none")]
124 underlying: Option<Cow<'a, str>>,
125 #[serde(rename = "instFamily", skip_serializing_if = "Option::is_none")]
126 inst_family: Option<Cow<'a, str>>,
127}
128
129impl<'a> AccountPositionTiersRequest<'a> {
130 pub fn new() -> Self {
132 Self::default()
133 }
134
135 pub fn inst_type(mut self, inst_type: InstType) -> Self {
137 self.inst_type = Some(inst_type);
138 self
139 }
140
141 pub fn underlying(mut self, underlying: impl Into<Cow<'a, str>>) -> Self {
143 self.underlying = Some(underlying.into());
144 self
145 }
146
147 pub fn inst_family(mut self, inst_family: impl Into<Cow<'a, str>>) -> Self {
149 self.inst_family = Some(inst_family.into());
150 self
151 }
152}
153
154#[derive(Debug, Clone, Default, Serialize)]
156pub struct PositionBuilderRequest<'a> {
157 #[serde(rename = "acctLv", skip_serializing_if = "Option::is_none")]
158 acct_lv: Option<Cow<'a, str>>,
159 #[serde(rename = "inclRealPosAndEq", skip_serializing_if = "Option::is_none")]
160 include_real_positions_and_equity: Option<bool>,
161 #[serde(skip_serializing_if = "Option::is_none")]
162 lever: Option<Cow<'a, str>>,
163 #[serde(rename = "greeksType", skip_serializing_if = "Option::is_none")]
164 greeks_type: Option<Cow<'a, str>>,
165 #[serde(rename = "simPos", skip_serializing_if = "Option::is_none")]
166 simulated_positions: Option<Vec<SimulatedPosition<'a>>>,
167 #[serde(rename = "simAsset", skip_serializing_if = "Option::is_none")]
168 simulated_assets: Option<Vec<SimulatedAsset<'a>>>,
169 #[serde(rename = "idxVol", skip_serializing_if = "Option::is_none")]
170 index_volatility: Option<Cow<'a, str>>,
171}
172
173impl<'a> PositionBuilderRequest<'a> {
174 pub fn new() -> Self {
176 Self::default()
177 }
178
179 pub fn account_level(mut self, acct_lv: impl Into<Cow<'a, str>>) -> Self {
181 self.acct_lv = Some(acct_lv.into());
182 self
183 }
184
185 pub fn include_real_positions_and_equity(mut self, include: bool) -> Self {
187 self.include_real_positions_and_equity = Some(include);
188 self
189 }
190
191 pub fn leverage(mut self, lever: impl Into<Cow<'a, str>>) -> Self {
193 self.lever = Some(lever.into());
194 self
195 }
196
197 pub fn greeks_type(mut self, greeks_type: impl Into<Cow<'a, str>>) -> Self {
199 self.greeks_type = Some(greeks_type.into());
200 self
201 }
202
203 pub fn simulated_positions(mut self, simulated_positions: Vec<SimulatedPosition<'a>>) -> Self {
205 self.simulated_positions = Some(simulated_positions);
206 self
207 }
208
209 pub fn simulated_assets(mut self, simulated_assets: Vec<SimulatedAsset<'a>>) -> Self {
211 self.simulated_assets = Some(simulated_assets);
212 self
213 }
214
215 pub fn index_volatility(mut self, index_volatility: impl Into<Cow<'a, str>>) -> Self {
217 self.index_volatility = Some(index_volatility.into());
218 self
219 }
220}