Skip to main content

rust_okx/api/finance/requests/
savings.rs

1use std::borrow::Cow;
2
3use serde::Serialize;
4
5/// Request body for `POST /api/v5/finance/savings/purchase-redempt`.
6#[derive(Debug, Clone, Serialize)]
7pub struct SavingsPurchaseRedemptionRequest<'a> {
8    ccy: Cow<'a, str>,
9    amt: Cow<'a, str>,
10    side: Cow<'a, str>,
11    #[serde(skip_serializing_if = "Option::is_none")]
12    rate: Option<Cow<'a, str>>,
13}
14
15impl<'a> SavingsPurchaseRedemptionRequest<'a> {
16    /// Create a Simple Earn purchase or redemption request.
17    ///
18    /// `side` must be `purchase` or `redempt`.
19    pub fn new(
20        ccy: impl Into<Cow<'a, str>>,
21        amt: impl Into<Cow<'a, str>>,
22        side: impl Into<Cow<'a, str>>,
23    ) -> Self {
24        Self {
25            ccy: ccy.into(),
26            amt: amt.into(),
27            side: side.into(),
28            rate: None,
29        }
30    }
31
32    /// Set the minimum annual lending rate for a purchase.
33    ///
34    /// OKX documents the accepted range as `0.01` through `3.65` (1%–365%).
35    pub fn rate(mut self, rate: impl Into<Cow<'a, str>>) -> Self {
36        self.rate = Some(rate.into());
37        self
38    }
39}