Skip to main content

rust_okx/api/account/responses/
bills.rs

1use std::fmt;
2
3use serde::{Deserialize, Deserializer};
4
5use crate::model::NumberString;
6
7/// Account bill row.
8#[derive(Debug, Clone, Deserialize)]
9#[serde(rename_all = "camelCase")]
10#[non_exhaustive]
11pub struct AccountBill {
12    /// Bill ID.
13    #[serde(default)]
14    pub bill_id: String,
15    /// Instrument type.
16    #[serde(default)]
17    pub inst_type: String,
18    /// Instrument ID.
19    #[serde(default)]
20    pub inst_id: String,
21    /// Currency.
22    #[serde(default)]
23    pub ccy: String,
24    /// Margin mode.
25    #[serde(default)]
26    pub mgn_mode: String,
27    /// Bill type.
28    #[serde(rename = "type", default)]
29    pub bill_type: String,
30    /// Bill subtype.
31    #[serde(default)]
32    pub sub_type: String,
33    /// Balance change.
34    #[serde(default)]
35    pub bal_chg: NumberString,
36    /// Quantity.
37    #[serde(default)]
38    pub sz: NumberString,
39    /// Balance after the change.
40    #[serde(default)]
41    pub bal: NumberString,
42    /// Balance change at the position level.
43    #[serde(default)]
44    pub pos_bal_chg: NumberString,
45    /// Balance at the position level.
46    #[serde(default)]
47    pub pos_bal: NumberString,
48    /// Price related to the bill subtype.
49    #[serde(default)]
50    pub px: NumberString,
51    /// Profit and loss.
52    #[serde(default)]
53    pub pnl: NumberString,
54    /// Fee.
55    #[serde(default)]
56    pub fee: NumberString,
57    /// Auto earn amount.
58    #[serde(default)]
59    pub earn_amt: NumberString,
60    /// Auto earn APR.
61    #[serde(default)]
62    pub earn_apr: NumberString,
63    /// Order ID.
64    #[serde(default)]
65    pub ord_id: String,
66    /// Liquidity taker or maker.
67    #[serde(default)]
68    pub exec_type: String,
69    /// The remitting account.
70    #[serde(default)]
71    pub from: String,
72    /// The beneficiary account.
73    #[serde(default)]
74    pub to: String,
75    /// Notes.
76    #[serde(default)]
77    pub notes: String,
78    /// Interest.
79    #[serde(default)]
80    pub interest: NumberString,
81    /// Order tag.
82    #[serde(default)]
83    pub tag: String,
84    /// Last filled time.
85    #[serde(default)]
86    pub fill_time: NumberString,
87    /// Last traded ID.
88    #[serde(default)]
89    pub trade_id: String,
90    /// Client Order ID.
91    #[serde(default)]
92    pub cl_ord_id: String,
93    /// Index price at the moment of trade execution.
94    #[serde(default)]
95    pub fill_idx_px: NumberString,
96    /// Mark price when filled.
97    #[serde(default)]
98    pub fill_mark_px: NumberString,
99    /// Implied volatility when filled.
100    #[serde(default)]
101    pub fill_px_vol: NumberString,
102    /// Options price when filled, in USD.
103    #[serde(default)]
104    pub fill_px_usd: NumberString,
105    /// Forward price when filled.
106    #[serde(default)]
107    pub fill_fwd_px: NumberString,
108    /// Mark volatility when filled.
109    #[serde(default)]
110    pub fill_mark_vol: NumberString,
111    /// Timestamp (Unix milliseconds).
112    #[serde(default)]
113    pub ts: NumberString,
114}
115
116/// Mapping for an account bill type and its subtypes.
117#[derive(Debug, Clone, Deserialize)]
118#[serde(rename_all = "camelCase")]
119#[non_exhaustive]
120pub struct BillSubtypeMapping {
121    /// Bill type.
122    #[serde(rename = "type", default)]
123    pub bill_type: String,
124    /// Bill type description. Empty means the type is not enabled.
125    #[serde(default)]
126    pub type_desc: String,
127    /// Sub-type details.
128    #[serde(default)]
129    pub sub_type_details: Vec<BillSubtypeDetail>,
130}
131
132/// Account bill subtype details.
133#[derive(Debug, Clone, Deserialize)]
134#[serde(rename_all = "camelCase")]
135#[non_exhaustive]
136pub struct BillSubtypeDetail {
137    /// Bill subtype.
138    #[serde(default)]
139    pub sub_type: String,
140    /// Bill subtype description. Empty means the subtype is not enabled.
141    #[serde(default)]
142    pub sub_type_desc: String,
143}
144
145/// Status returned after applying for a historical bills archive.
146#[derive(Debug, Clone, PartialEq, Eq, Hash)]
147#[non_exhaustive]
148pub enum BillsHistoryArchiveStatus {
149    /// A download link already exists.
150    LinkAvailable,
151    /// The file is being generated.
152    Generating,
153    /// A value not modeled by this crate version.
154    Unknown(String),
155}
156
157impl BillsHistoryArchiveStatus {
158    /// Return the OKX wire representation of this status.
159    pub fn as_str(&self) -> &str {
160        match self {
161            Self::LinkAvailable => "true",
162            Self::Generating => "false",
163            Self::Unknown(value) => value,
164        }
165    }
166}
167
168impl From<&str> for BillsHistoryArchiveStatus {
169    fn from(value: &str) -> Self {
170        match value {
171            "true" => Self::LinkAvailable,
172            "false" => Self::Generating,
173            other => Self::Unknown(other.to_owned()),
174        }
175    }
176}
177
178impl fmt::Display for BillsHistoryArchiveStatus {
179    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
180        formatter.write_str(self.as_str())
181    }
182}
183
184impl<'de> Deserialize<'de> for BillsHistoryArchiveStatus {
185    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
186    where
187        D: Deserializer<'de>,
188    {
189        let value = String::deserialize(deserializer)?;
190        Ok(Self::from(value.as_str()))
191    }
192}
193
194/// Result returned after applying for historical account-bills archive generation.
195#[derive(Debug, Clone, Deserialize)]
196#[serde(rename_all = "camelCase")]
197#[non_exhaustive]
198pub struct ApplyBillsHistoryArchiveResult {
199    /// Whether the download link already exists or is being generated.
200    #[serde(rename = "result")]
201    pub status: BillsHistoryArchiveStatus,
202    /// First request time received by OKX, as Unix milliseconds.
203    #[serde(default)]
204    pub ts: NumberString,
205}
206
207/// Download-link state for historical account-bills archive files.
208#[derive(Debug, Clone, PartialEq, Eq, Hash)]
209#[non_exhaustive]
210pub enum BillsHistoryArchiveFileState {
211    /// The download link is ready.
212    Finished,
213    /// The archive file is still being generated.
214    Ongoing,
215    /// File generation failed; apply again.
216    Failed,
217    /// A value not modeled by this crate version.
218    Unknown(String),
219}
220
221impl BillsHistoryArchiveFileState {
222    /// Return the OKX wire representation of this state.
223    pub fn as_str(&self) -> &str {
224        match self {
225            Self::Finished => "finished",
226            Self::Ongoing => "ongoing",
227            Self::Failed => "failed",
228            Self::Unknown(value) => value,
229        }
230    }
231}
232
233impl From<&str> for BillsHistoryArchiveFileState {
234    fn from(value: &str) -> Self {
235        match value {
236            "finished" => Self::Finished,
237            "ongoing" => Self::Ongoing,
238            "failed" => Self::Failed,
239            other => Self::Unknown(other.to_owned()),
240        }
241    }
242}
243
244impl fmt::Display for BillsHistoryArchiveFileState {
245    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
246        formatter.write_str(self.as_str())
247    }
248}
249
250impl<'de> Deserialize<'de> for BillsHistoryArchiveFileState {
251    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
252    where
253        D: Deserializer<'de>,
254    {
255        let value = String::deserialize(deserializer)?;
256        Ok(Self::from(value.as_str()))
257    }
258}
259
260/// Historical account-bills archive download-link information.
261#[derive(Debug, Clone, Deserialize)]
262#[serde(rename_all = "camelCase")]
263#[non_exhaustive]
264pub struct BillsHistoryArchiveFile {
265    /// Download file link.
266    #[serde(default)]
267    pub file_href: String,
268    /// Download-link status.
269    pub state: BillsHistoryArchiveFileState,
270    /// First request time received by OKX, as Unix milliseconds.
271    #[serde(default)]
272    pub ts: NumberString,
273}