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    pub fn new() -> Self {
21        Self { lt_coin: None }
22    }
23
24    pub fn with_lt_coin(mut self, v: String) -> Self {
25        self.lt_coin = Some(v);
26        self
27    }
28}
29
30impl Default for GetLeverageTokenInfoParams {
31    fn default() -> Self {
32        Self::new()
33    }
34}
35
36#[derive(Debug, Deserialize, PartialEq)]
37#[serde(rename_all = "camelCase")]
38pub struct LeverageTokenInfo {
39    pub lt_coin: String,
40    pub lt_name: String,
41    /// Single maximum purchase amount
42    pub max_purchase: Decimal,
43    /// Single minimum purchase amount
44    pub min_purchase: Decimal,
45    /// Maximum purchase amount in a single day
46    pub max_purchase_daily: Decimal,
47    /// Single maximum redemption quantity
48    pub max_redeem: Decimal,
49    /// Single minimum redemption quantity
50    pub min_redeem: Decimal,
51    /// Maximum redemption quantity in a single day
52    pub max_redeem_daily: Decimal,
53    pub purchase_fee_rate: Decimal,
54    pub redeem_fee_rate: Decimal,
55    pub lt_status: LtStatus,
56    /// Funding fee charged daily for users holding the leveraged token
57    pub fund_fee: Decimal,
58    #[serde(deserialize_with = "number")]
59    pub fund_fee_time: Timestamp,
60    pub manage_fee_rate: Decimal,
61    #[serde(deserialize_with = "number")]
62    pub manage_fee_time: Timestamp,
63    /// Nominal asset value
64    pub value: Decimal,
65    pub net_value: Decimal,
66    /// Total purchase upper limit
67    pub total: Decimal,
68}
69
70// --- Get Leverage Token Market ---
71
72/// Query params for
73/// [`Client::get_leverage_token_market`](crate::http::Client::get_leverage_token_market).
74#[derive(Debug, Serialize, Clone)]
75#[serde(rename_all = "camelCase")]
76pub struct GetLeverageTokenMarketParams {
77    /// Abbreviation of the LT, such as `BTC3L`
78    pub lt_coin: String,
79}
80
81impl GetLeverageTokenMarketParams {
82    pub fn new(lt_coin: String) -> Self {
83        Self { lt_coin }
84    }
85}
86
87#[derive(Debug, Deserialize, PartialEq)]
88#[serde(rename_all = "camelCase")]
89pub struct LeverageTokenMarket {
90    pub lt_coin: String,
91    /// Net asset value
92    pub nav: Decimal,
93    #[serde(deserialize_with = "number")]
94    pub nav_time: Timestamp,
95    /// Circulating supply in the secondary market
96    pub circulation: Decimal,
97    /// Basket composition value
98    pub basket: Decimal,
99    /// Real leverage, calculated by the last traded price
100    pub leverage: Decimal,
101}
102
103// --- Purchase ---
104
105/// Request body for
106/// [`Client::purchase_leverage_token`](crate::http::Client::purchase_leverage_token).
107#[derive(Debug, Serialize, Clone)]
108#[serde(rename_all = "camelCase")]
109pub struct PurchaseLeverageTokenRequest {
110    /// Abbreviation of the LT, such as `BTC3L`
111    pub lt_coin: String,
112    /// Quantity to purchase
113    pub lt_amount: Decimal,
114    /// Custom order identifier
115    #[serde(skip_serializing_if = "Option::is_none")]
116    pub serial_no: Option<String>,
117}
118
119impl PurchaseLeverageTokenRequest {
120    pub fn new(lt_coin: String, lt_amount: Decimal) -> Self {
121        Self {
122            lt_coin,
123            lt_amount,
124            serial_no: None,
125        }
126    }
127
128    pub fn with_serial_no(mut self, v: String) -> Self {
129        self.serial_no = Some(v);
130        self
131    }
132}
133
134#[derive(Debug, Deserialize, PartialEq)]
135#[serde(rename_all = "camelCase")]
136pub struct PurchaseLeverageTokenResult {
137    pub lt_coin: String,
138    pub lt_order_status: LtOrderStatus,
139    /// Executed quantity of leverage tokens
140    pub exec_qty: Decimal,
141    /// Executed amount of leverage tokens
142    pub exec_amt: Decimal,
143    /// Total purchase amount submitted
144    pub amount: Decimal,
145    pub purchase_id: String,
146    #[serde(default, deserialize_with = "empty_string_as_none")]
147    pub serial_no: Option<String>,
148    /// Quote currency for the transaction
149    pub value_coin: String,
150}
151
152// --- Redeem ---
153
154/// Request body for
155/// [`Client::redeem_leverage_token`](crate::http::Client::redeem_leverage_token).
156#[derive(Debug, Serialize, Clone)]
157#[serde(rename_all = "camelCase")]
158pub struct RedeemLeverageTokenRequest {
159    /// Abbreviation of the LT, such as `BTC3L`
160    pub lt_coin: String,
161    /// Redeem quantity of the LT
162    pub quantity: Decimal,
163    #[serde(skip_serializing_if = "Option::is_none")]
164    pub serial_no: Option<String>,
165}
166
167impl RedeemLeverageTokenRequest {
168    pub fn new(lt_coin: String, quantity: Decimal) -> Self {
169        Self {
170            lt_coin,
171            quantity,
172            serial_no: None,
173        }
174    }
175
176    pub fn with_serial_no(mut self, v: String) -> Self {
177        self.serial_no = Some(v);
178        self
179    }
180}
181
182#[derive(Debug, Deserialize, PartialEq)]
183#[serde(rename_all = "camelCase")]
184pub struct RedeemLeverageTokenResult {
185    pub lt_coin: String,
186    pub lt_order_status: LtOrderStatus,
187    pub quantity: Decimal,
188    /// Leverage token quantity executed
189    pub exec_qty: Decimal,
190    /// Executed amount of the LT
191    pub exec_amt: Decimal,
192    pub redeem_id: String,
193    #[serde(default, deserialize_with = "empty_string_as_none")]
194    pub serial_no: Option<String>,
195    /// Quote coin
196    pub value_coin: String,
197}
198
199// --- Get Purchase/Redemption Records ---
200
201/// Query params for
202/// [`Client::get_leverage_token_order_records`](crate::http::Client::get_leverage_token_order_records).
203#[derive(Clone, Debug, Serialize)]
204#[serde(rename_all = "camelCase")]
205pub struct GetLeverageTokenOrderRecordsParams {
206    /// Abbreviation of the LT, such as `BTC3L`
207    #[serde(skip_serializing_if = "Option::is_none")]
208    pub lt_coin: Option<String>,
209    #[serde(skip_serializing_if = "Option::is_none")]
210    pub order_id: Option<String>,
211    #[serde(skip_serializing_if = "Option::is_none")]
212    pub start_time: Option<Timestamp>,
213    #[serde(skip_serializing_if = "Option::is_none")]
214    pub end_time: Option<Timestamp>,
215    /// Limit for data size per page. [1, 500]. Default: 100
216    #[serde(skip_serializing_if = "Option::is_none")]
217    pub limit: Option<u64>,
218    #[serde(skip_serializing_if = "Option::is_none")]
219    pub lt_order_type: Option<LtOrderType>,
220    #[serde(skip_serializing_if = "Option::is_none")]
221    pub serial_no: Option<String>,
222}
223
224impl GetLeverageTokenOrderRecordsParams {
225    pub fn new() -> Self {
226        Self {
227            lt_coin: None,
228            order_id: None,
229            start_time: None,
230            end_time: None,
231            limit: None,
232            lt_order_type: None,
233            serial_no: None,
234        }
235    }
236
237    pub fn with_lt_coin(mut self, v: String) -> Self {
238        self.lt_coin = Some(v);
239        self
240    }
241    pub fn with_order_id(mut self, v: String) -> Self {
242        self.order_id = Some(v);
243        self
244    }
245    pub fn with_start_time(mut self, v: Timestamp) -> Self {
246        self.start_time = Some(v);
247        self
248    }
249    pub fn with_end_time(mut self, v: Timestamp) -> Self {
250        self.end_time = Some(v);
251        self
252    }
253    pub fn with_limit(mut self, v: u64) -> Self {
254        self.limit = Some(v);
255        self
256    }
257    pub fn with_lt_order_type(mut self, v: LtOrderType) -> Self {
258        self.lt_order_type = Some(v);
259        self
260    }
261    pub fn with_serial_no(mut self, v: String) -> Self {
262        self.serial_no = Some(v);
263        self
264    }
265}
266
267impl Default for GetLeverageTokenOrderRecordsParams {
268    fn default() -> Self {
269        Self::new()
270    }
271}
272
273#[derive(Debug, Deserialize, PartialEq)]
274#[serde(rename_all = "camelCase")]
275pub struct LeverageTokenOrderRecord {
276    pub lt_coin: String,
277    pub order_id: String,
278    pub lt_order_type: LtOrderType,
279    pub order_time: Timestamp,
280    pub update_time: Timestamp,
281    pub lt_order_status: LtOrderStatus,
282    pub fee: Decimal,
283    /// Order quantity of the LT
284    pub amount: Decimal,
285    /// Filled value
286    pub value: Decimal,
287    pub value_coin: String,
288    #[serde(default, deserialize_with = "empty_string_as_none")]
289    pub serial_no: Option<String>,
290}