Skip to main content

rust_okx/api/finance/requests/
common.rs

1use serde::Serialize;
2
3/// Request for [`get_saving_balance`](crate::api::finance::Savings::get_saving_balance).
4#[derive(Debug, Clone, Default, Serialize)]
5pub struct CurrencyRequest<'a> {
6    /// Currency filter, e.g. `Some("USDT")`. `None` returns all currencies.
7    #[serde(skip_serializing_if = "Option::is_none")]
8    pub ccy: Option<&'a str>,
9}
10
11/// Request for [`set_lending_rate`](crate::api::finance::Savings::set_lending_rate).
12#[derive(Debug, Clone, Serialize)]
13pub struct SetLendingRateRequest<'a> {
14    /// Currency.
15    pub ccy: &'a str,
16    /// Lending rate.
17    pub rate: &'a str,
18}
19
20/// Request for purchase/redeem operations on staking products.
21#[derive(Debug, Clone, Serialize)]
22pub struct AmountRequest<'a> {
23    /// Amount.
24    pub amt: &'a str,
25}
26
27/// Request for [`cancel_redeem`] on staking products.
28#[derive(Debug, Clone, Serialize)]
29#[serde(rename_all = "camelCase")]
30pub struct CancelRedeemRequest<'a> {
31    /// Order ID to cancel.
32    pub ord_id: &'a str,
33}
34
35/// Request for [`apy_history`] on staking products.
36#[derive(Debug, Clone, Serialize)]
37pub struct ApyHistoryRequest<'a> {
38    /// Number of days of history, e.g. `"7"` or `"30"`.
39    pub days: &'a str,
40}
41
42/// Common currency and cursor pagination query used by finance history endpoints.
43#[derive(Debug, Clone, Default, Serialize)]
44pub struct FinanceHistoryRequest {
45    #[serde(skip_serializing_if = "Option::is_none")]
46    ccy: Option<String>,
47    #[serde(skip_serializing_if = "Option::is_none")]
48    after: Option<String>,
49    #[serde(skip_serializing_if = "Option::is_none")]
50    before: Option<String>,
51    #[serde(skip_serializing_if = "Option::is_none")]
52    limit: Option<u32>,
53}
54
55impl FinanceHistoryRequest {
56    /// Create an unfiltered history query.
57    pub fn new() -> Self {
58        Self::default()
59    }
60
61    /// Restrict the result to one currency.
62    pub fn currency(mut self, ccy: impl Into<String>) -> Self {
63        self.ccy = Some(ccy.into());
64        self
65    }
66
67    /// Set the endpoint-specific `after` cursor.
68    pub fn after(mut self, after: impl Into<String>) -> Self {
69        self.after = Some(after.into());
70        self
71    }
72
73    /// Set the endpoint-specific `before` cursor.
74    pub fn before(mut self, before: impl Into<String>) -> Self {
75        self.before = Some(before.into());
76        self
77    }
78
79    /// Set the number of records to return, from 1 through 100.
80    pub fn limit(mut self, limit: u32) -> Self {
81        self.limit = Some(limit);
82        self
83    }
84}