nautilus_binance/http/
models.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2025 Nautech Systems Pty Ltd. All rights reserved.
3//  https://nautechsystems.io
4//
5//  Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
6//  You may not use this file except in compliance with the License.
7//  You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
8//
9//  Unless required by applicable law or agreed to in writing, software
10//  distributed under the License is distributed on an "AS IS" BASIS,
11//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//  See the License for the specific language governing permissions and
13//  limitations under the License.
14// -------------------------------------------------------------------------------------------------
15
16//! Binance HTTP response models.
17//!
18//! This module contains data transfer objects for deserializing Binance REST API responses.
19
20use serde::{Deserialize, Serialize};
21use serde_json::Value;
22use ustr::Ustr;
23
24use crate::common::{
25    enums::{
26        BinanceContractStatus, BinanceFuturesOrderType, BinanceIncomeType, BinanceMarginType,
27        BinanceOrderStatus, BinancePositionSide, BinancePriceMatch, BinanceSelfTradePreventionMode,
28        BinanceSide, BinanceTimeInForce, BinanceTradingStatus, BinanceWorkingType,
29    },
30    models::BinanceRateLimit,
31};
32
33/// Server time response from `GET /api/v3/time`.
34///
35/// # References
36/// - <https://developers.binance.com/docs/binance-spot-api-docs/rest-api/general-endpoints>
37#[derive(Clone, Debug, Serialize, Deserialize)]
38#[serde(rename_all = "camelCase")]
39pub struct BinanceServerTime {
40    /// Server timestamp in milliseconds.
41    pub server_time: i64,
42}
43
44/// Spot exchange information response from `GET /api/v3/exchangeInfo`.
45///
46/// # References
47/// - <https://developers.binance.com/docs/binance-spot-api-docs/rest-api/general-endpoints>
48#[derive(Clone, Debug, Serialize, Deserialize)]
49#[serde(rename_all = "camelCase")]
50pub struct BinanceSpotExchangeInfo {
51    /// Server timezone.
52    pub timezone: String,
53    /// Server timestamp in milliseconds.
54    pub server_time: i64,
55    /// Rate limit definitions.
56    pub rate_limits: Vec<BinanceRateLimit>,
57    /// Exchange-level filters.
58    #[serde(default)]
59    pub exchange_filters: Vec<Value>,
60    /// Trading symbols.
61    pub symbols: Vec<BinanceSpotSymbol>,
62}
63
64/// Spot symbol definition.
65///
66/// # References
67/// - <https://developers.binance.com/docs/binance-spot-api-docs/rest-api/general-endpoints>
68#[derive(Clone, Debug, Serialize, Deserialize)]
69#[serde(rename_all = "camelCase")]
70pub struct BinanceSpotSymbol {
71    /// Symbol name (e.g., "BTCUSDT").
72    pub symbol: Ustr,
73    /// Trading status.
74    pub status: BinanceTradingStatus,
75    /// Base asset (e.g., "BTC").
76    pub base_asset: Ustr,
77    /// Base asset precision.
78    pub base_asset_precision: i32,
79    /// Quote asset (e.g., "USDT").
80    pub quote_asset: Ustr,
81    /// Quote asset precision.
82    pub quote_precision: i32,
83    /// Quote asset precision (duplicate field in some responses).
84    #[serde(default)]
85    pub quote_asset_precision: Option<i32>,
86    /// Allowed order types.
87    pub order_types: Vec<String>,
88    /// Whether iceberg orders are allowed.
89    pub iceberg_allowed: bool,
90    /// Whether OCO orders are allowed.
91    #[serde(default)]
92    pub oco_allowed: Option<bool>,
93    /// Whether quote order quantity market orders are allowed.
94    #[serde(default)]
95    pub quote_order_qty_market_allowed: Option<bool>,
96    /// Whether trailing delta is allowed.
97    #[serde(default)]
98    pub allow_trailing_stop: Option<bool>,
99    /// Whether spot trading is allowed.
100    #[serde(default)]
101    pub is_spot_trading_allowed: Option<bool>,
102    /// Whether margin trading is allowed.
103    #[serde(default)]
104    pub is_margin_trading_allowed: Option<bool>,
105    /// Symbol filters (price, lot size, notional, etc.).
106    pub filters: Vec<Value>,
107    /// Permissions for the symbol.
108    #[serde(default)]
109    pub permissions: Vec<String>,
110    /// Permission sets.
111    #[serde(default)]
112    pub permission_sets: Vec<Vec<String>>,
113    /// Default self trade prevention mode.
114    #[serde(default)]
115    pub default_self_trade_prevention_mode: Option<String>,
116    /// Allowed self trade prevention modes.
117    #[serde(default)]
118    pub allowed_self_trade_prevention_modes: Vec<String>,
119}
120
121/// USD-M Futures exchange information response from `GET /fapi/v1/exchangeInfo`.
122///
123/// # References
124/// - <https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Exchange-Information>
125#[derive(Clone, Debug, Serialize, Deserialize)]
126#[serde(rename_all = "camelCase")]
127pub struct BinanceFuturesUsdExchangeInfo {
128    /// Server timezone.
129    pub timezone: String,
130    /// Server timestamp in milliseconds.
131    pub server_time: i64,
132    /// Rate limit definitions.
133    pub rate_limits: Vec<BinanceRateLimit>,
134    /// Exchange-level filters.
135    #[serde(default)]
136    pub exchange_filters: Vec<Value>,
137    /// Asset definitions.
138    #[serde(default)]
139    pub assets: Vec<BinanceFuturesAsset>,
140    /// Trading symbols.
141    pub symbols: Vec<BinanceFuturesUsdSymbol>,
142}
143
144/// Futures asset definition.
145#[derive(Clone, Debug, Serialize, Deserialize)]
146#[serde(rename_all = "camelCase")]
147pub struct BinanceFuturesAsset {
148    /// Asset name.
149    pub asset: Ustr,
150    /// Whether margin is available.
151    pub margin_available: bool,
152    /// Auto asset exchange threshold.
153    #[serde(default)]
154    pub auto_asset_exchange: Option<String>,
155}
156
157/// USD-M Futures symbol definition.
158///
159/// # References
160/// - <https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Exchange-Information>
161#[derive(Clone, Debug, Serialize, Deserialize)]
162#[serde(rename_all = "camelCase")]
163pub struct BinanceFuturesUsdSymbol {
164    /// Symbol name (e.g., "BTCUSDT").
165    pub symbol: Ustr,
166    /// Trading pair (e.g., "BTCUSDT").
167    pub pair: Ustr,
168    /// Contract type (PERPETUAL, CURRENT_QUARTER, NEXT_QUARTER).
169    pub contract_type: String,
170    /// Delivery date timestamp.
171    pub delivery_date: i64,
172    /// Onboard date timestamp.
173    pub onboard_date: i64,
174    /// Trading status.
175    pub status: BinanceTradingStatus,
176    /// Maintenance margin percent.
177    pub maint_margin_percent: String,
178    /// Required margin percent.
179    pub required_margin_percent: String,
180    /// Base asset.
181    pub base_asset: Ustr,
182    /// Quote asset.
183    pub quote_asset: Ustr,
184    /// Margin asset.
185    pub margin_asset: Ustr,
186    /// Price precision.
187    pub price_precision: i32,
188    /// Quantity precision.
189    pub quantity_precision: i32,
190    /// Base asset precision.
191    pub base_asset_precision: i32,
192    /// Quote precision.
193    pub quote_precision: i32,
194    /// Underlying type.
195    #[serde(default)]
196    pub underlying_type: Option<String>,
197    /// Underlying sub type.
198    #[serde(default)]
199    pub underlying_sub_type: Vec<String>,
200    /// Settle plan.
201    #[serde(default)]
202    pub settle_plan: Option<i64>,
203    /// Trigger protect threshold.
204    #[serde(default)]
205    pub trigger_protect: Option<String>,
206    /// Liquidation fee.
207    #[serde(default)]
208    pub liquidation_fee: Option<String>,
209    /// Market take bound.
210    #[serde(default)]
211    pub market_take_bound: Option<String>,
212    /// Allowed order types.
213    pub order_types: Vec<String>,
214    /// Time in force options.
215    pub time_in_force: Vec<String>,
216    /// Symbol filters.
217    pub filters: Vec<Value>,
218}
219
220/// COIN-M Futures exchange information response from `GET /dapi/v1/exchangeInfo`.
221///
222/// # References
223/// - <https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/Exchange-Information>
224#[derive(Clone, Debug, Serialize, Deserialize)]
225#[serde(rename_all = "camelCase")]
226pub struct BinanceFuturesCoinExchangeInfo {
227    /// Server timezone.
228    pub timezone: String,
229    /// Server timestamp in milliseconds.
230    pub server_time: i64,
231    /// Rate limit definitions.
232    pub rate_limits: Vec<BinanceRateLimit>,
233    /// Exchange-level filters.
234    #[serde(default)]
235    pub exchange_filters: Vec<Value>,
236    /// Trading symbols.
237    pub symbols: Vec<BinanceFuturesCoinSymbol>,
238}
239
240/// COIN-M Futures symbol definition.
241///
242/// # References
243/// - <https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/Exchange-Information>
244#[derive(Clone, Debug, Serialize, Deserialize)]
245#[serde(rename_all = "camelCase")]
246pub struct BinanceFuturesCoinSymbol {
247    /// Symbol name (e.g., "BTCUSD_PERP").
248    pub symbol: Ustr,
249    /// Trading pair (e.g., "BTCUSD").
250    pub pair: Ustr,
251    /// Contract type (PERPETUAL, CURRENT_QUARTER, NEXT_QUARTER).
252    pub contract_type: String,
253    /// Delivery date timestamp.
254    pub delivery_date: i64,
255    /// Onboard date timestamp.
256    pub onboard_date: i64,
257    /// Trading status.
258    #[serde(default)]
259    pub contract_status: Option<BinanceContractStatus>,
260    /// Contract size.
261    pub contract_size: i64,
262    /// Maintenance margin percent.
263    pub maint_margin_percent: String,
264    /// Required margin percent.
265    pub required_margin_percent: String,
266    /// Base asset.
267    pub base_asset: Ustr,
268    /// Quote asset.
269    pub quote_asset: Ustr,
270    /// Margin asset.
271    pub margin_asset: Ustr,
272    /// Price precision.
273    pub price_precision: i32,
274    /// Quantity precision.
275    pub quantity_precision: i32,
276    /// Base asset precision.
277    pub base_asset_precision: i32,
278    /// Quote precision.
279    pub quote_precision: i32,
280    /// Equal quantity precision.
281    #[serde(default, rename = "equalQtyPrecision")]
282    pub equal_qty_precision: Option<i32>,
283    /// Trigger protect threshold.
284    #[serde(default)]
285    pub trigger_protect: Option<String>,
286    /// Liquidation fee.
287    #[serde(default)]
288    pub liquidation_fee: Option<String>,
289    /// Market take bound.
290    #[serde(default)]
291    pub market_take_bound: Option<String>,
292    /// Allowed order types.
293    pub order_types: Vec<String>,
294    /// Time in force options.
295    pub time_in_force: Vec<String>,
296    /// Symbol filters.
297    pub filters: Vec<Value>,
298}
299
300/// 24hr ticker price change statistics for spot.
301///
302/// # References
303/// - <https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints>
304#[derive(Clone, Debug, Serialize, Deserialize)]
305#[serde(rename_all = "camelCase")]
306pub struct BinanceSpotTicker24hr {
307    /// Symbol name.
308    pub symbol: Ustr,
309    /// Price change in quote asset.
310    pub price_change: String,
311    /// Price change percentage.
312    pub price_change_percent: String,
313    /// Weighted average price.
314    pub weighted_avg_price: String,
315    /// Previous close price.
316    #[serde(default)]
317    pub prev_close_price: Option<String>,
318    /// Last traded price.
319    pub last_price: String,
320    /// Last traded quantity.
321    #[serde(default)]
322    pub last_qty: Option<String>,
323    /// Best bid price.
324    pub bid_price: String,
325    /// Best bid quantity.
326    #[serde(default)]
327    pub bid_qty: Option<String>,
328    /// Best ask price.
329    pub ask_price: String,
330    /// Best ask quantity.
331    #[serde(default)]
332    pub ask_qty: Option<String>,
333    /// Opening price.
334    pub open_price: String,
335    /// Highest price.
336    pub high_price: String,
337    /// Lowest price.
338    pub low_price: String,
339    /// Total traded base asset volume.
340    pub volume: String,
341    /// Total traded quote asset volume.
342    pub quote_volume: String,
343    /// Statistics open time.
344    pub open_time: i64,
345    /// Statistics close time.
346    pub close_time: i64,
347    /// First trade ID.
348    #[serde(default)]
349    pub first_id: Option<i64>,
350    /// Last trade ID.
351    #[serde(default)]
352    pub last_id: Option<i64>,
353    /// Total number of trades.
354    #[serde(default)]
355    pub count: Option<i64>,
356}
357
358/// 24hr ticker price change statistics for futures.
359///
360/// # References
361/// - <https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/24hr-Ticker-Price-Change-Statistics>
362#[derive(Clone, Debug, Serialize, Deserialize)]
363#[serde(rename_all = "camelCase")]
364pub struct BinanceFuturesTicker24hr {
365    /// Symbol name.
366    pub symbol: Ustr,
367    /// Price change in quote asset.
368    pub price_change: String,
369    /// Price change percentage.
370    pub price_change_percent: String,
371    /// Weighted average price.
372    pub weighted_avg_price: String,
373    /// Last traded price.
374    pub last_price: String,
375    /// Last traded quantity.
376    #[serde(default)]
377    pub last_qty: Option<String>,
378    /// Opening price.
379    pub open_price: String,
380    /// Highest price.
381    pub high_price: String,
382    /// Lowest price.
383    pub low_price: String,
384    /// Total traded base asset volume.
385    pub volume: String,
386    /// Total traded quote asset volume.
387    pub quote_volume: String,
388    /// Statistics open time.
389    pub open_time: i64,
390    /// Statistics close time.
391    pub close_time: i64,
392    /// First trade ID.
393    #[serde(default)]
394    pub first_id: Option<i64>,
395    /// Last trade ID.
396    #[serde(default)]
397    pub last_id: Option<i64>,
398    /// Total number of trades.
399    #[serde(default)]
400    pub count: Option<i64>,
401}
402
403/// Mark price and funding rate for futures.
404///
405/// # References
406/// - <https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Mark-Price>
407#[derive(Clone, Debug, Serialize, Deserialize)]
408#[serde(rename_all = "camelCase")]
409pub struct BinanceFuturesMarkPrice {
410    /// Symbol name.
411    pub symbol: Ustr,
412    /// Mark price.
413    pub mark_price: String,
414    /// Index price.
415    #[serde(default)]
416    pub index_price: Option<String>,
417    /// Estimated settle price (only for delivery contracts).
418    #[serde(default)]
419    pub estimated_settle_price: Option<String>,
420    /// Last funding rate.
421    #[serde(default)]
422    pub last_funding_rate: Option<String>,
423    /// Next funding time.
424    #[serde(default)]
425    pub next_funding_time: Option<i64>,
426    /// Interest rate.
427    #[serde(default)]
428    pub interest_rate: Option<String>,
429    /// Timestamp.
430    pub time: i64,
431}
432
433/// Recent trade from `GET /api/v3/trades` or `GET /fapi/v1/trades`.
434///
435/// # References
436/// - <https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints>
437#[derive(Clone, Debug, Serialize, Deserialize)]
438#[serde(rename_all = "camelCase")]
439pub struct BinanceTrade {
440    /// Trade ID.
441    pub id: i64,
442    /// Trade price.
443    pub price: String,
444    /// Trade quantity.
445    pub qty: String,
446    /// Quote asset quantity.
447    #[serde(default)]
448    pub quote_qty: Option<String>,
449    /// Trade timestamp in milliseconds.
450    pub time: i64,
451    /// Was the buyer the maker?
452    pub is_buyer_maker: bool,
453    /// Was this the best price match?
454    #[serde(default)]
455    pub is_best_match: Option<bool>,
456}
457
458/// Aggregated trade from `GET /api/v3/aggTrades` or `GET /fapi/v1/aggTrades`.
459///
460/// # References
461/// - <https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints>
462#[derive(Clone, Debug, Serialize, Deserialize)]
463#[serde(rename_all = "camelCase")]
464pub struct BinanceAggTrade {
465    /// Aggregate trade ID.
466    #[serde(rename = "a")]
467    pub agg_trade_id: i64,
468    /// Trade price.
469    #[serde(rename = "p")]
470    pub price: String,
471    /// Trade quantity.
472    #[serde(rename = "q")]
473    pub qty: String,
474    /// First trade ID.
475    #[serde(rename = "f")]
476    pub first_trade_id: i64,
477    /// Last trade ID.
478    #[serde(rename = "l")]
479    pub last_trade_id: i64,
480    /// Trade timestamp in milliseconds.
481    #[serde(rename = "T")]
482    pub time: i64,
483    /// Was the buyer the maker?
484    #[serde(rename = "m")]
485    pub is_buyer_maker: bool,
486    /// Was this the best price match? (spot only)
487    #[serde(default, rename = "M")]
488    pub is_best_match: Option<bool>,
489}
490
491/// Raw kline data as returned by Binance (array format).
492///
493/// Binance returns klines as arrays: `[openTime, open, high, low, close, volume, closeTime,
494/// quoteVolume, trades, takerBuyBaseVol, takerBuyQuoteVol, ignore]`
495///
496/// # References
497/// - <https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints>
498pub type BinanceKlineRaw = (
499    i64,    // 0: Open time
500    String, // 1: Open price
501    String, // 2: High price
502    String, // 3: Low price
503    String, // 4: Close price
504    String, // 5: Volume
505    i64,    // 6: Close time
506    String, // 7: Quote asset volume
507    i64,    // 8: Number of trades
508    String, // 9: Taker buy base asset volume
509    String, // 10: Taker buy quote asset volume
510    String, // 11: Ignore
511);
512
513/// Parsed kline/candlestick data.
514#[derive(Clone, Debug, Serialize, Deserialize)]
515pub struct BinanceKline {
516    /// Kline open timestamp in milliseconds.
517    pub open_time: i64,
518    /// Open price.
519    pub open: String,
520    /// High price.
521    pub high: String,
522    /// Low price.
523    pub low: String,
524    /// Close price.
525    pub close: String,
526    /// Base asset volume.
527    pub volume: String,
528    /// Kline close timestamp in milliseconds.
529    pub close_time: i64,
530    /// Quote asset volume.
531    pub quote_volume: String,
532    /// Number of trades.
533    pub trade_count: i64,
534    /// Taker buy base asset volume.
535    pub taker_buy_base_volume: String,
536    /// Taker buy quote asset volume.
537    pub taker_buy_quote_volume: String,
538}
539
540impl From<BinanceKlineRaw> for BinanceKline {
541    fn from(raw: BinanceKlineRaw) -> Self {
542        Self {
543            open_time: raw.0,
544            open: raw.1,
545            high: raw.2,
546            low: raw.3,
547            close: raw.4,
548            volume: raw.5,
549            close_time: raw.6,
550            quote_volume: raw.7,
551            trade_count: raw.8,
552            taker_buy_base_volume: raw.9,
553            taker_buy_quote_volume: raw.10,
554        }
555    }
556}
557
558/// Order book depth snapshot from `GET /api/v3/depth` or `GET /fapi/v1/depth`.
559///
560/// # References
561/// - <https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints>
562#[derive(Clone, Debug, Serialize, Deserialize)]
563#[serde(rename_all = "camelCase")]
564pub struct BinanceOrderBook {
565    /// Last update ID.
566    pub last_update_id: i64,
567    /// Bid levels as `[price, quantity]` arrays.
568    pub bids: Vec<(String, String)>,
569    /// Ask levels as `[price, quantity]` arrays.
570    pub asks: Vec<(String, String)>,
571    /// Message output time (futures only).
572    #[serde(default, rename = "E")]
573    pub event_time: Option<i64>,
574    /// Transaction time (futures only).
575    #[serde(default, rename = "T")]
576    pub transaction_time: Option<i64>,
577}
578
579/// Best bid/ask from `GET /api/v3/ticker/bookTicker` or `GET /fapi/v1/ticker/bookTicker`.
580///
581/// # References
582/// - <https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints>
583#[derive(Clone, Debug, Serialize, Deserialize)]
584#[serde(rename_all = "camelCase")]
585pub struct BinanceBookTicker {
586    /// Symbol name.
587    pub symbol: Ustr,
588    /// Best bid price.
589    pub bid_price: String,
590    /// Best bid quantity.
591    pub bid_qty: String,
592    /// Best ask price.
593    pub ask_price: String,
594    /// Best ask quantity.
595    pub ask_qty: String,
596    /// Event time (futures only).
597    #[serde(default)]
598    pub time: Option<i64>,
599}
600
601/// Price ticker from `GET /api/v3/ticker/price` or `GET /fapi/v1/ticker/price`.
602///
603/// # References
604/// - <https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints>
605#[derive(Clone, Debug, Serialize, Deserialize)]
606#[serde(rename_all = "camelCase")]
607pub struct BinancePriceTicker {
608    /// Symbol name.
609    pub symbol: Ustr,
610    /// Current price.
611    pub price: String,
612    /// Event time (futures only).
613    #[serde(default)]
614    pub time: Option<i64>,
615}
616
617/// Funding rate history record from `GET /fapi/v1/fundingRate` or `GET /dapi/v1/fundingRate`.
618///
619/// # References
620/// - <https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Get-Funding-Rate-History>
621#[derive(Clone, Debug, Serialize, Deserialize)]
622#[serde(rename_all = "camelCase")]
623pub struct BinanceFundingRate {
624    /// Symbol name.
625    pub symbol: Ustr,
626    /// Funding rate value.
627    pub funding_rate: String,
628    /// Funding time in milliseconds.
629    pub funding_time: i64,
630    /// Mark price at the funding time.
631    #[serde(default)]
632    pub mark_price: Option<String>,
633    /// Index price at the funding time.
634    #[serde(default)]
635    pub index_price: Option<String>,
636}
637
638/// Open interest record from `GET /fapi/v1/openInterest` or `GET /dapi/v1/openInterest`.
639///
640/// # References
641/// - <https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Open-Interest>
642#[derive(Clone, Debug, Serialize, Deserialize)]
643#[serde(rename_all = "camelCase")]
644pub struct BinanceOpenInterest {
645    /// Symbol name.
646    pub symbol: Ustr,
647    /// Total open interest.
648    pub open_interest: String,
649    /// Timestamp in milliseconds.
650    pub time: i64,
651}
652
653/// Futures account balance entry from `GET /fapi/v2/balance` or `GET /dapi/v1/balance`.
654///
655/// # References
656/// - <https://developers.binance.com/docs/derivatives/usds-margined-futures/user-data/account>
657/// - <https://developers.binance.com/docs/derivatives/coin-margined-futures/user-data/account>
658#[derive(Clone, Debug, Serialize, Deserialize)]
659#[serde(rename_all = "camelCase")]
660pub struct BinanceFuturesBalance {
661    /// Account alias (only USD-M).
662    #[serde(default)]
663    pub account_alias: Option<String>,
664    /// Asset code (e.g., "USDT").
665    pub asset: Ustr,
666    /// Total balance.
667    pub balance: String,
668    /// Cross wallet balance.
669    #[serde(default)]
670    pub cross_wallet_balance: Option<String>,
671    /// Unrealized PnL for cross positions.
672    #[serde(default)]
673    pub cross_un_pnl: Option<String>,
674    /// Available balance.
675    pub available_balance: String,
676    /// Maximum withdrawable amount.
677    #[serde(default)]
678    pub max_withdraw_amount: Option<String>,
679    /// Whether margin trading is available.
680    #[serde(default)]
681    pub margin_available: Option<bool>,
682    /// Timestamp of last update in milliseconds.
683    pub update_time: i64,
684    /// Withdrawable amount (COIN-M specific).
685    #[serde(default)]
686    pub withdraw_available: Option<String>,
687}
688
689/// Position risk record from `GET /fapi/v2/positionRisk` or `GET /dapi/v1/positionRisk`.
690///
691/// # References
692/// - <https://developers.binance.com/docs/derivatives/usds-margined-futures/user-data/account#position-information-v2-user_data>
693#[derive(Clone, Debug, Serialize, Deserialize)]
694#[serde(rename_all = "camelCase")]
695pub struct BinancePositionRisk {
696    /// Symbol name.
697    pub symbol: Ustr,
698    /// Position quantity.
699    pub position_amt: String,
700    /// Entry price.
701    pub entry_price: String,
702    /// Mark price.
703    pub mark_price: String,
704    /// Unrealized profit and loss.
705    #[serde(default)]
706    pub un_realized_profit: Option<String>,
707    /// Liquidation price.
708    #[serde(default)]
709    pub liquidation_price: Option<String>,
710    /// Applied leverage.
711    pub leverage: String,
712    /// Max notional value.
713    #[serde(default)]
714    pub max_notional_value: Option<String>,
715    /// Margin type (CROSSED or ISOLATED).
716    #[serde(default)]
717    pub margin_type: Option<BinanceMarginType>,
718    /// Isolated margin amount.
719    #[serde(default)]
720    pub isolated_margin: Option<String>,
721    /// Auto add margin flag.
722    #[serde(default)]
723    pub is_auto_add_margin: Option<bool>,
724    /// Position side (BOTH, LONG, SHORT).
725    #[serde(default)]
726    pub position_side: Option<BinancePositionSide>,
727    /// Notional position value.
728    #[serde(default)]
729    pub notional: Option<String>,
730    /// Isolated wallet balance.
731    #[serde(default)]
732    pub isolated_wallet: Option<String>,
733    /// ADL quantile indicator.
734    #[serde(default)]
735    pub adl_quantile: Option<u8>,
736    /// Last update time.
737    #[serde(default)]
738    pub update_time: Option<i64>,
739    /// Break-even price.
740    #[serde(default)]
741    pub break_even_price: Option<String>,
742    /// Bankruptcy price.
743    #[serde(default)]
744    pub bust_price: Option<String>,
745}
746
747/// Income history record from `GET /fapi/v1/income` or `GET /dapi/v1/income`.
748///
749/// # References
750/// - <https://developers.binance.com/docs/derivatives/usds-margined-futures/user-data/account#income-history-user_data>
751#[derive(Clone, Debug, Serialize, Deserialize)]
752#[serde(rename_all = "camelCase")]
753pub struct BinanceIncomeRecord {
754    /// Symbol name (may be empty for transfers).
755    #[serde(default)]
756    pub symbol: Option<Ustr>,
757    /// Income type (e.g., FUNDING_FEE, COMMISSION).
758    pub income_type: BinanceIncomeType,
759    /// Income amount.
760    pub income: String,
761    /// Asset code.
762    pub asset: Ustr,
763    /// Event time in milliseconds.
764    pub time: i64,
765    /// Additional info field.
766    #[serde(default)]
767    pub info: Option<String>,
768    /// Transaction ID.
769    #[serde(default)]
770    pub tran_id: Option<i64>,
771    /// Related trade ID.
772    #[serde(default)]
773    pub trade_id: Option<i64>,
774}
775
776/// User trade record from `GET /fapi/v1/userTrades` or `GET /dapi/v1/userTrades`.
777///
778/// # References
779/// - <https://developers.binance.com/docs/derivatives/usds-margined-futures/user-data/trade#account-trade-list-user_data>
780#[derive(Clone, Debug, Serialize, Deserialize)]
781#[serde(rename_all = "camelCase")]
782pub struct BinanceUserTrade {
783    /// Symbol name.
784    pub symbol: Ustr,
785    /// Trade ID.
786    pub id: i64,
787    /// Order ID.
788    pub order_id: i64,
789    /// Trade price.
790    pub price: String,
791    /// Executed quantity.
792    pub qty: String,
793    /// Quote quantity.
794    #[serde(default)]
795    pub quote_qty: Option<String>,
796    /// Realized PnL for the trade.
797    pub realized_pnl: String,
798    /// Buy/sell side.
799    pub side: BinanceSide,
800    /// Position side (BOTH, LONG, SHORT).
801    #[serde(default)]
802    pub position_side: Option<BinancePositionSide>,
803    /// Trade time in milliseconds.
804    pub time: i64,
805    /// Was the buyer the maker?
806    pub buyer: bool,
807    /// Was the trade maker liquidity?
808    pub maker: bool,
809    /// Commission paid.
810    #[serde(default)]
811    pub commission: Option<String>,
812    /// Commission asset.
813    #[serde(default)]
814    pub commission_asset: Option<Ustr>,
815    /// Margin asset (if provided).
816    #[serde(default)]
817    pub margin_asset: Option<Ustr>,
818}
819
820/// Futures order information returned by `GET /fapi/v1/order` or `GET /fapi/v1/openOrders`.
821///
822/// # References
823/// - <https://developers.binance.com/docs/derivatives/usds-margined-futures/user-data/order#query-order-user_data>
824#[derive(Clone, Debug, Serialize, Deserialize)]
825#[serde(rename_all = "camelCase")]
826pub struct BinanceFuturesOrder {
827    /// Symbol name.
828    pub symbol: Ustr,
829    /// Order ID.
830    pub order_id: i64,
831    /// Client order ID.
832    pub client_order_id: String,
833    /// Original order quantity.
834    pub orig_qty: String,
835    /// Executed quantity.
836    pub executed_qty: String,
837    /// Cumulative quote asset transacted.
838    pub cum_quote: String,
839    /// Original limit price.
840    pub price: String,
841    /// Average execution price.
842    #[serde(default)]
843    pub avg_price: Option<String>,
844    /// Stop price.
845    #[serde(default)]
846    pub stop_price: Option<String>,
847    /// Order status.
848    pub status: BinanceOrderStatus,
849    /// Time in force.
850    pub time_in_force: BinanceTimeInForce,
851    /// Order type.
852    #[serde(rename = "type")]
853    pub order_type: BinanceFuturesOrderType,
854    /// Original order type.
855    #[serde(default)]
856    pub orig_type: Option<BinanceFuturesOrderType>,
857    /// Order side (BUY/SELL).
858    pub side: BinanceSide,
859    /// Position side (BOTH/LONG/SHORT).
860    #[serde(default)]
861    pub position_side: Option<BinancePositionSide>,
862    /// Reduce-only flag.
863    #[serde(default)]
864    pub reduce_only: Option<bool>,
865    /// Close position flag (for stop orders).
866    #[serde(default)]
867    pub close_position: Option<bool>,
868    /// Trailing delta activation price.
869    #[serde(default)]
870    pub activate_price: Option<String>,
871    /// Trailing callback rate.
872    #[serde(default)]
873    pub price_rate: Option<String>,
874    /// Working type (CONTRACT_PRICE or MARK_PRICE).
875    #[serde(default)]
876    pub working_type: Option<BinanceWorkingType>,
877    /// Whether price protection is enabled.
878    #[serde(default)]
879    pub price_protect: Option<bool>,
880    /// Whether order uses isolated margin.
881    #[serde(default)]
882    pub is_isolated: Option<bool>,
883    /// Good till date (for GTD orders).
884    #[serde(default)]
885    pub good_till_date: Option<i64>,
886    /// Price match mode (futures only).
887    #[serde(default)]
888    pub price_match: Option<BinancePriceMatch>,
889    /// Self-trade prevention mode.
890    #[serde(default)]
891    pub self_trade_prevention_mode: Option<BinanceSelfTradePreventionMode>,
892    /// Last update time.
893    #[serde(default)]
894    pub update_time: Option<i64>,
895    /// Working order ID for tracking.
896    #[serde(default)]
897    pub working_type_id: Option<i64>,
898}