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}
18
19impl<'a> PositionsRequest<'a> {
20    /// Create an unfiltered positions query.
21    pub fn new() -> Self {
22        Self::default()
23    }
24
25    /// Set the instrument type filter.
26    pub fn inst_type(mut self, inst_type: InstType) -> Self {
27        self.inst_type = Some(inst_type);
28        self
29    }
30
31    /// Set the instrument ID filter.
32    pub fn inst_id(mut self, inst_id: impl Into<Cow<'a, str>>) -> Self {
33        self.inst_id = Some(inst_id.into());
34        self
35    }
36}
37
38/// Request for [`get_position_risk`](crate::api::account::Account::get_position_risk).
39#[derive(Debug, Clone, Default, Serialize)]
40#[serde(rename_all = "camelCase")]
41pub struct PositionRiskRequest {
42    #[serde(skip_serializing_if = "Option::is_none")]
43    inst_type: Option<InstType>,
44}
45
46impl PositionRiskRequest {
47    /// Create an unfiltered position-risk query.
48    pub fn new() -> Self {
49        Self::default()
50    }
51
52    /// Set the instrument type filter.
53    pub fn inst_type(mut self, inst_type: InstType) -> Self {
54        self.inst_type = Some(inst_type);
55        self
56    }
57}