Skip to main content

bybit/http/
spot_lever_token.rs

1use rust_decimal::Decimal;
2use serde::{Deserialize, Serialize};
3use serde_aux::prelude::deserialize_number_from_string as number;
4
5use crate::{LtOrderStatus, LtOrderType, LtStatus, Timestamp, serde::empty_string_as_none};
6
7// --- Get Leverage Token Info ---
8
9/// Query params for
10/// [`Client::get_leverage_token_info`](crate::http::Client::get_leverage_token_info).
11#[derive(Debug, Serialize, Clone)]
12#[serde(rename_all = "camelCase")]
13pub struct GetLeverageTokenInfoParams {
14    /// Abbreviation of the LT, such as `BTC3L`. Returns all tokens if not passed
15    #[serde(skip_serializing_if = "Option::is_none")]
16    pub lt_coin: Option<String>,
17}
18
19impl GetLeverageTokenInfoParams {
20    /// Create with the required fields; set the optional ones with the `with_*` methods.
21    pub fn new() -> Self {
22        Self { lt_coin: None }
23    }
24
25    /// Set `lt_coin`: abbreviation of the LT, such as `BTC3L`. Returns all tokens if not passed.
26    pub fn with_lt_coin(mut self, v: impl Into<String>) -> Self {
27        self.lt_coin = Some(v.into());
28        self
29    }
30}
31
32impl Default for GetLeverageTokenInfoParams {
33    fn default() -> Self {
34        Self::new()
35    }
36}
37
38/// Item of the list returned by `GET /v5/spot-lever-token/info` ([`Client::get_leverage_token_info`](crate::http::Client::get_leverage_token_info)).
39#[derive(Debug, Deserialize, PartialEq)]
40#[serde(rename_all = "camelCase")]
41pub struct LeverageTokenInfo {
42    /// Abbreviation.
43    pub lt_coin: String,
44    /// Full name of leveraged token.
45    pub lt_name: String,
46    /// Single maximum purchase amount
47    pub max_purchase: Decimal,
48    /// Single minimum purchase amount
49    pub min_purchase: Decimal,
50    /// Maximum purchase amount in a single day
51    pub max_purchase_daily: Decimal,
52    /// Single maximum redemption quantity
53    pub max_redeem: Decimal,
54    /// Single minimum redemption quantity
55    pub min_redeem: Decimal,
56    /// Maximum redemption quantity in a single day
57    pub max_redeem_daily: Decimal,
58    /// Purchase fee rate.
59    pub purchase_fee_rate: Decimal,
60    /// Redeem fee rate.
61    pub redeem_fee_rate: Decimal,
62    /// Whether the leverage token can be purchased or redeemed.
63    pub lt_status: LtStatus,
64    /// Funding fee charged daily for users holding the leveraged token
65    pub fund_fee: Decimal,
66    /// The time to charge funding fee.
67    #[serde(deserialize_with = "number")]
68    pub fund_fee_time: Timestamp,
69    /// Management fee rate.
70    pub manage_fee_rate: Decimal,
71    /// The time to charge management fee.
72    #[serde(deserialize_with = "number")]
73    pub manage_fee_time: Timestamp,
74    /// Nominal asset value
75    pub value: Decimal,
76    /// Net value.
77    pub net_value: Decimal,
78    /// Total purchase upper limit
79    pub total: Decimal,
80}
81
82// --- Get Leverage Token Market ---
83
84/// Query params for
85/// [`Client::get_leverage_token_market`](crate::http::Client::get_leverage_token_market).
86#[derive(Debug, Serialize, Clone)]
87#[serde(rename_all = "camelCase")]
88pub struct GetLeverageTokenMarketParams {
89    /// Abbreviation of the LT, such as `BTC3L`
90    pub lt_coin: String,
91}
92
93impl GetLeverageTokenMarketParams {
94    /// Create with the required fields; set the optional ones with the `with_*` methods.
95    pub fn new(lt_coin: impl Into<String>) -> Self {
96        let lt_coin: String = lt_coin.into();
97        Self { lt_coin }
98    }
99}
100
101/// Result of `GET /v5/spot-lever-token/reference` ([`Client::get_leverage_token_market`](crate::http::Client::get_leverage_token_market)).
102#[derive(Debug, Deserialize, PartialEq)]
103#[serde(rename_all = "camelCase")]
104pub struct LeverageTokenMarket {
105    /// Abbreviation of the LT, such as BTC3L.
106    pub lt_coin: String,
107    /// Net asset value
108    pub nav: Decimal,
109    /// Update time for net asset value (in milliseconds and UTC time zone).
110    #[serde(deserialize_with = "number")]
111    pub nav_time: Timestamp,
112    /// Circulating supply in the secondary market
113    pub circulation: Decimal,
114    /// Basket composition value
115    pub basket: Decimal,
116    /// Real leverage, calculated by the last traded price
117    pub leverage: Decimal,
118}
119
120// --- Purchase ---
121
122/// Request body for
123/// [`Client::purchase_leverage_token`](crate::http::Client::purchase_leverage_token).
124#[derive(Debug, Serialize, Clone)]
125#[serde(rename_all = "camelCase")]
126pub struct PurchaseLeverageTokenRequest {
127    /// Abbreviation of the LT, such as `BTC3L`
128    pub lt_coin: String,
129    /// Quantity to purchase
130    pub lt_amount: Decimal,
131    /// Custom order identifier
132    #[serde(skip_serializing_if = "Option::is_none")]
133    pub serial_no: Option<String>,
134}
135
136impl PurchaseLeverageTokenRequest {
137    /// Create with the required fields; set the optional ones with the `with_*` methods.
138    pub fn new(lt_coin: impl Into<String>, lt_amount: Decimal) -> Self {
139        let lt_coin: String = lt_coin.into();
140        Self {
141            lt_coin,
142            lt_amount,
143            serial_no: None,
144        }
145    }
146
147    /// Set `serial_no`: custom order identifier.
148    pub fn with_serial_no(mut self, v: impl Into<String>) -> Self {
149        self.serial_no = Some(v.into());
150        self
151    }
152}
153
154/// Result of `POST /v5/spot-lever-token/purchase` ([`Client::purchase_leverage_token`](crate::http::Client::purchase_leverage_token)).
155#[derive(Debug, Deserialize, PartialEq)]
156#[serde(rename_all = "camelCase")]
157pub struct PurchaseLeverageTokenResult {
158    /// Abbreviation of the LT, such as BTC3L.
159    pub lt_coin: String,
160    /// Order status. 1: completed, 2: in progress, 3: failed.
161    pub lt_order_status: LtOrderStatus,
162    /// Executed quantity of leverage tokens
163    pub exec_qty: Decimal,
164    /// Executed amount of leverage tokens
165    pub exec_amt: Decimal,
166    /// Total purchase amount submitted
167    pub amount: Decimal,
168    /// Order ID.
169    pub purchase_id: String,
170    /// Serial number, customised order ID.
171    #[serde(default, deserialize_with = "empty_string_as_none")]
172    pub serial_no: Option<String>,
173    /// Quote currency for the transaction
174    pub value_coin: String,
175}
176
177// --- Redeem ---
178
179/// Request body for
180/// [`Client::redeem_leverage_token`](crate::http::Client::redeem_leverage_token).
181#[derive(Debug, Serialize, Clone)]
182#[serde(rename_all = "camelCase")]
183pub struct RedeemLeverageTokenRequest {
184    /// Abbreviation of the LT, such as `BTC3L`
185    pub lt_coin: String,
186    /// Redeem quantity of the LT
187    pub quantity: Decimal,
188    /// Serial number.
189    #[serde(skip_serializing_if = "Option::is_none")]
190    pub serial_no: Option<String>,
191}
192
193impl RedeemLeverageTokenRequest {
194    /// Create with the required fields; set the optional ones with the `with_*` methods.
195    pub fn new(lt_coin: impl Into<String>, quantity: Decimal) -> Self {
196        let lt_coin: String = lt_coin.into();
197        Self {
198            lt_coin,
199            quantity,
200            serial_no: None,
201        }
202    }
203
204    /// Set `serial_no`: serial number.
205    pub fn with_serial_no(mut self, v: impl Into<String>) -> Self {
206        self.serial_no = Some(v.into());
207        self
208    }
209}
210
211/// Result of `POST /v5/spot-lever-token/redeem` ([`Client::redeem_leverage_token`](crate::http::Client::redeem_leverage_token)).
212#[derive(Debug, Deserialize, PartialEq)]
213#[serde(rename_all = "camelCase")]
214pub struct RedeemLeverageTokenResult {
215    /// Abbreviation of the LT.
216    pub lt_coin: String,
217    /// Order status. 1: completed, 2: in progress, 3: failed.
218    pub lt_order_status: LtOrderStatus,
219    /// Quantity.
220    pub quantity: Decimal,
221    /// Leverage token quantity executed
222    pub exec_qty: Decimal,
223    /// Executed amount of the LT
224    pub exec_amt: Decimal,
225    /// Order ID.
226    pub redeem_id: String,
227    /// Serial number.
228    #[serde(default, deserialize_with = "empty_string_as_none")]
229    pub serial_no: Option<String>,
230    /// Quote coin
231    pub value_coin: String,
232}
233
234// --- Get Purchase/Redemption Records ---
235
236/// Query params for
237/// [`Client::get_leverage_token_order_records`](crate::http::Client::get_leverage_token_order_records).
238#[derive(Clone, Debug, Serialize)]
239#[serde(rename_all = "camelCase")]
240pub struct GetLeverageTokenOrderRecordsParams {
241    /// Abbreviation of the LT, such as `BTC3L`
242    #[serde(skip_serializing_if = "Option::is_none")]
243    pub lt_coin: Option<String>,
244    /// Order ID.
245    #[serde(skip_serializing_if = "Option::is_none")]
246    pub order_id: Option<String>,
247    /// The start timestamp (ms).
248    #[serde(skip_serializing_if = "Option::is_none")]
249    pub start_time: Option<Timestamp>,
250    /// The end timestamp (ms).
251    #[serde(skip_serializing_if = "Option::is_none")]
252    pub end_time: Option<Timestamp>,
253    /// Limit for data size per page. [1, 500]. Default: 100
254    #[serde(skip_serializing_if = "Option::is_none")]
255    pub limit: Option<u64>,
256    /// LT order type. 1: purchase, 2: redemption.
257    #[serde(skip_serializing_if = "Option::is_none")]
258    pub lt_order_type: Option<LtOrderType>,
259    /// Serial number.
260    #[serde(skip_serializing_if = "Option::is_none")]
261    pub serial_no: Option<String>,
262}
263
264impl GetLeverageTokenOrderRecordsParams {
265    /// Create with the required fields; set the optional ones with the `with_*` methods.
266    pub fn new() -> Self {
267        Self {
268            lt_coin: None,
269            order_id: None,
270            start_time: None,
271            end_time: None,
272            limit: None,
273            lt_order_type: None,
274            serial_no: None,
275        }
276    }
277
278    /// Set `lt_coin`: abbreviation of the LT, such as `BTC3L`.
279    pub fn with_lt_coin(mut self, v: impl Into<String>) -> Self {
280        self.lt_coin = Some(v.into());
281        self
282    }
283    /// Set `order_id`: order ID.
284    pub fn with_order_id(mut self, v: impl Into<String>) -> Self {
285        self.order_id = Some(v.into());
286        self
287    }
288    /// Set `start_time`: the start timestamp (ms).
289    pub fn with_start_time(mut self, v: Timestamp) -> Self {
290        self.start_time = Some(v);
291        self
292    }
293    /// Set `end_time`: the end timestamp (ms).
294    pub fn with_end_time(mut self, v: Timestamp) -> Self {
295        self.end_time = Some(v);
296        self
297    }
298    /// Set `limit`: limit for data size per page. [1, 500]. Default: 100.
299    pub fn with_limit(mut self, v: u64) -> Self {
300        self.limit = Some(v);
301        self
302    }
303    /// Set `lt_order_type`: lT order type. 1: purchase, 2: redemption.
304    pub fn with_lt_order_type(mut self, v: LtOrderType) -> Self {
305        self.lt_order_type = Some(v);
306        self
307    }
308    /// Set `serial_no`: serial number.
309    pub fn with_serial_no(mut self, v: impl Into<String>) -> Self {
310        self.serial_no = Some(v.into());
311        self
312    }
313}
314
315impl Default for GetLeverageTokenOrderRecordsParams {
316    fn default() -> Self {
317        Self::new()
318    }
319}
320
321/// Item of the list returned by `GET /v5/spot-lever-token/order-record` ([`Client::get_leverage_token_order_records`](crate::http::Client::get_leverage_token_order_records)).
322#[derive(Debug, Deserialize, PartialEq)]
323#[serde(rename_all = "camelCase")]
324pub struct LeverageTokenOrderRecord {
325    /// Abbreviation of the LT, such as BTC3L.
326    pub lt_coin: String,
327    /// Order ID.
328    pub order_id: String,
329    /// LT order type. 1: purchase, 2: redeem.
330    pub lt_order_type: LtOrderType,
331    /// Order time.
332    pub order_time: Timestamp,
333    /// Last update time of the order status.
334    pub update_time: Timestamp,
335    /// Order status. 1: completed, 2: in progress, 3: failed.
336    pub lt_order_status: LtOrderStatus,
337    /// Trading fees.
338    pub fee: Decimal,
339    /// Order quantity of the LT
340    pub amount: Decimal,
341    /// Filled value
342    pub value: Decimal,
343    /// Quote coin.
344    pub value_coin: String,
345    /// Serial number.
346    #[serde(default, deserialize_with = "empty_string_as_none")]
347    pub serial_no: Option<String>,
348}