Skip to main content

rust_okx/api/finance/requests/
common.rs

1use serde::Serialize;
2
3/// Common currency and cursor pagination query used by finance history endpoints.
4#[derive(Debug, Clone, Default, Serialize)]
5pub struct FinanceHistoryRequest {
6    #[serde(skip_serializing_if = "Option::is_none")]
7    ccy: Option<String>,
8    #[serde(skip_serializing_if = "Option::is_none")]
9    after: Option<String>,
10    #[serde(skip_serializing_if = "Option::is_none")]
11    before: Option<String>,
12    #[serde(skip_serializing_if = "Option::is_none")]
13    limit: Option<u32>,
14}
15
16impl FinanceHistoryRequest {
17    /// Create an unfiltered history query.
18    pub fn new() -> Self {
19        Self::default()
20    }
21
22    /// Restrict the result to one currency.
23    pub fn currency(mut self, ccy: impl Into<String>) -> Self {
24        self.ccy = Some(ccy.into());
25        self
26    }
27
28    /// Set the endpoint-specific `after` cursor.
29    pub fn after(mut self, after: impl Into<String>) -> Self {
30        self.after = Some(after.into());
31        self
32    }
33
34    /// Set the endpoint-specific `before` cursor.
35    pub fn before(mut self, before: impl Into<String>) -> Self {
36        self.before = Some(before.into());
37        self
38    }
39
40    /// Set the number of records to return, from 1 through 100.
41    pub fn limit(mut self, limit: u32) -> Self {
42        self.limit = Some(limit);
43        self
44    }
45}