Skip to main content

rust_okx/api/account/requests/
positions.rs

1use std::borrow::Cow;
2
3use serde::Serialize;
4
5use crate::model::InstType;
6
7/// Request for [`get_positions`](crate::api::account::Account::get_positions).
8///
9/// All fields are optional; omit both to return all open positions.
10#[derive(Debug, Clone, Default, Serialize)]
11#[serde(rename_all = "camelCase")]
12pub struct PositionsRequest<'a> {
13    #[serde(skip_serializing_if = "Option::is_none")]
14    inst_type: Option<InstType>,
15    #[serde(skip_serializing_if = "Option::is_none")]
16    inst_id: Option<Cow<'a, str>>,
17    #[serde(skip_serializing_if = "Option::is_none")]
18    pos_id: Option<Cow<'a, str>>,
19}
20
21impl<'a> PositionsRequest<'a> {
22    /// Create an unfiltered positions query.
23    pub fn new() -> Self {
24        Self::default()
25    }
26
27    /// Set the instrument type filter.
28    pub fn inst_type(mut self, inst_type: InstType) -> Self {
29        self.inst_type = Some(inst_type);
30        self
31    }
32
33    /// Set the instrument ID filter.
34    pub fn inst_id(mut self, inst_id: impl Into<Cow<'a, str>>) -> Self {
35        self.inst_id = Some(inst_id.into());
36        self
37    }
38
39    /// Set the position ID filter.
40    pub fn position_id(mut self, pos_id: impl Into<Cow<'a, str>>) -> Self {
41        self.pos_id = Some(pos_id.into());
42        self
43    }
44}
45
46/// Request for [`get_position_risk`](crate::api::account::Account::get_position_risk).
47#[derive(Debug, Clone, Default, Serialize)]
48#[serde(rename_all = "camelCase")]
49pub struct PositionRiskRequest {
50    #[serde(skip_serializing_if = "Option::is_none")]
51    inst_type: Option<InstType>,
52}
53
54impl PositionRiskRequest {
55    /// Create an unfiltered position-risk query.
56    pub fn new() -> Self {
57        Self::default()
58    }
59
60    /// Set the instrument type filter.
61    pub fn inst_type(mut self, inst_type: InstType) -> Self {
62        self.inst_type = Some(inst_type);
63        self
64    }
65}