nautilus_binance/spot/http/
models.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2026 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 Spot HTTP response models.
17//!
18//! These models represent Binance venue-specific response types decoded from SBE.
19
20use crate::common::sbe::spot::{
21    order_side::OrderSide, order_status::OrderStatus, order_type::OrderType,
22    self_trade_prevention_mode::SelfTradePreventionMode, time_in_force::TimeInForce,
23};
24
25/// Price/quantity level in an order book.
26#[derive(Debug, Clone, Copy, PartialEq)]
27pub struct BinancePriceLevel {
28    /// Price mantissa (multiply by 10^exponent to get actual price).
29    pub price_mantissa: i64,
30    /// Quantity mantissa (multiply by 10^exponent to get actual quantity).
31    pub qty_mantissa: i64,
32}
33
34/// Binance order book depth response.
35#[derive(Debug, Clone, PartialEq)]
36pub struct BinanceDepth {
37    /// Last update ID for this depth snapshot.
38    pub last_update_id: i64,
39    /// Price exponent for all price levels.
40    pub price_exponent: i8,
41    /// Quantity exponent for all quantity values.
42    pub qty_exponent: i8,
43    /// Bid price levels (best bid first).
44    pub bids: Vec<BinancePriceLevel>,
45    /// Ask price levels (best ask first).
46    pub asks: Vec<BinancePriceLevel>,
47}
48
49/// A single trade from Binance.
50#[derive(Debug, Clone, PartialEq)]
51pub struct BinanceTrade {
52    /// Trade ID.
53    pub id: i64,
54    /// Price mantissa.
55    pub price_mantissa: i64,
56    /// Quantity mantissa.
57    pub qty_mantissa: i64,
58    /// Quote quantity mantissa (price * qty).
59    pub quote_qty_mantissa: i64,
60    /// Trade timestamp in microseconds (SBE precision).
61    pub time: i64,
62    /// Whether the buyer is the maker.
63    pub is_buyer_maker: bool,
64    /// Whether this trade is the best price match.
65    pub is_best_match: bool,
66}
67
68/// Binance trades response.
69#[derive(Debug, Clone, PartialEq)]
70pub struct BinanceTrades {
71    /// Price exponent for all trades.
72    pub price_exponent: i8,
73    /// Quantity exponent for all trades.
74    pub qty_exponent: i8,
75    /// List of trades.
76    pub trades: Vec<BinanceTrade>,
77}
78
79/// A fill from an order execution.
80#[derive(Debug, Clone, PartialEq)]
81pub struct BinanceOrderFill {
82    /// Fill price mantissa.
83    pub price_mantissa: i64,
84    /// Fill quantity mantissa.
85    pub qty_mantissa: i64,
86    /// Commission mantissa.
87    pub commission_mantissa: i64,
88    /// Commission exponent.
89    pub commission_exponent: i8,
90    /// Commission asset.
91    pub commission_asset: String,
92    /// Trade ID (if available).
93    pub trade_id: Option<i64>,
94}
95
96/// New order response (FULL response type).
97#[derive(Debug, Clone, PartialEq)]
98pub struct BinanceNewOrderResponse {
99    /// Price exponent for this response.
100    pub price_exponent: i8,
101    /// Quantity exponent for this response.
102    pub qty_exponent: i8,
103    /// Exchange order ID.
104    pub order_id: i64,
105    /// Order list ID (for OCO orders).
106    pub order_list_id: Option<i64>,
107    /// Transaction time in microseconds.
108    pub transact_time: i64,
109    /// Order price mantissa.
110    pub price_mantissa: i64,
111    /// Original order quantity mantissa.
112    pub orig_qty_mantissa: i64,
113    /// Executed quantity mantissa.
114    pub executed_qty_mantissa: i64,
115    /// Cumulative quote quantity mantissa.
116    pub cummulative_quote_qty_mantissa: i64,
117    /// Order status.
118    pub status: OrderStatus,
119    /// Time in force.
120    pub time_in_force: TimeInForce,
121    /// Order type.
122    pub order_type: OrderType,
123    /// Order side.
124    pub side: OrderSide,
125    /// Stop price mantissa (for stop orders).
126    pub stop_price_mantissa: Option<i64>,
127    /// Working time in microseconds.
128    pub working_time: Option<i64>,
129    /// Self-trade prevention mode.
130    pub self_trade_prevention_mode: SelfTradePreventionMode,
131    /// Client order ID.
132    pub client_order_id: String,
133    /// Symbol.
134    pub symbol: String,
135    /// Order fills.
136    pub fills: Vec<BinanceOrderFill>,
137}
138
139/// Cancel order response.
140#[derive(Debug, Clone, PartialEq)]
141pub struct BinanceCancelOrderResponse {
142    /// Price exponent for this response.
143    pub price_exponent: i8,
144    /// Quantity exponent for this response.
145    pub qty_exponent: i8,
146    /// Exchange order ID.
147    pub order_id: i64,
148    /// Order list ID (for OCO orders).
149    pub order_list_id: Option<i64>,
150    /// Transaction time in microseconds.
151    pub transact_time: i64,
152    /// Order price mantissa.
153    pub price_mantissa: i64,
154    /// Original order quantity mantissa.
155    pub orig_qty_mantissa: i64,
156    /// Executed quantity mantissa.
157    pub executed_qty_mantissa: i64,
158    /// Cumulative quote quantity mantissa.
159    pub cummulative_quote_qty_mantissa: i64,
160    /// Order status.
161    pub status: OrderStatus,
162    /// Time in force.
163    pub time_in_force: TimeInForce,
164    /// Order type.
165    pub order_type: OrderType,
166    /// Order side.
167    pub side: OrderSide,
168    /// Self-trade prevention mode.
169    pub self_trade_prevention_mode: SelfTradePreventionMode,
170    /// Client order ID.
171    pub client_order_id: String,
172    /// Original client order ID.
173    pub orig_client_order_id: String,
174    /// Symbol.
175    pub symbol: String,
176}
177
178/// Query order response.
179#[derive(Debug, Clone, PartialEq)]
180pub struct BinanceOrderResponse {
181    /// Price exponent for this response.
182    pub price_exponent: i8,
183    /// Quantity exponent for this response.
184    pub qty_exponent: i8,
185    /// Exchange order ID.
186    pub order_id: i64,
187    /// Order list ID (for OCO orders).
188    pub order_list_id: Option<i64>,
189    /// Order price mantissa.
190    pub price_mantissa: i64,
191    /// Original order quantity mantissa.
192    pub orig_qty_mantissa: i64,
193    /// Executed quantity mantissa.
194    pub executed_qty_mantissa: i64,
195    /// Cumulative quote quantity mantissa.
196    pub cummulative_quote_qty_mantissa: i64,
197    /// Order status.
198    pub status: OrderStatus,
199    /// Time in force.
200    pub time_in_force: TimeInForce,
201    /// Order type.
202    pub order_type: OrderType,
203    /// Order side.
204    pub side: OrderSide,
205    /// Stop price mantissa (for stop orders).
206    pub stop_price_mantissa: Option<i64>,
207    /// Iceberg quantity mantissa.
208    pub iceberg_qty_mantissa: Option<i64>,
209    /// Order creation time in microseconds.
210    pub time: i64,
211    /// Last update time in microseconds.
212    pub update_time: i64,
213    /// Whether the order is working.
214    pub is_working: bool,
215    /// Working time in microseconds.
216    pub working_time: Option<i64>,
217    /// Original quote order quantity mantissa.
218    pub orig_quote_order_qty_mantissa: i64,
219    /// Self-trade prevention mode.
220    pub self_trade_prevention_mode: SelfTradePreventionMode,
221    /// Client order ID.
222    pub client_order_id: String,
223    /// Symbol.
224    pub symbol: String,
225}
226
227/// Account balance for a single asset.
228#[derive(Debug, Clone, PartialEq)]
229pub struct BinanceBalance {
230    /// Asset symbol.
231    pub asset: String,
232    /// Free (available) balance mantissa.
233    pub free_mantissa: i64,
234    /// Locked balance mantissa.
235    pub locked_mantissa: i64,
236    /// Balance exponent.
237    pub exponent: i8,
238}
239
240/// Account information response.
241#[derive(Debug, Clone, PartialEq)]
242pub struct BinanceAccountInfo {
243    /// Commission exponent.
244    pub commission_exponent: i8,
245    /// Maker commission rate mantissa.
246    pub maker_commission_mantissa: i64,
247    /// Taker commission rate mantissa.
248    pub taker_commission_mantissa: i64,
249    /// Buyer commission rate mantissa.
250    pub buyer_commission_mantissa: i64,
251    /// Seller commission rate mantissa.
252    pub seller_commission_mantissa: i64,
253    /// Whether trading is enabled.
254    pub can_trade: bool,
255    /// Whether withdrawals are enabled.
256    pub can_withdraw: bool,
257    /// Whether deposits are enabled.
258    pub can_deposit: bool,
259    /// Whether the account requires self-trade prevention.
260    pub require_self_trade_prevention: bool,
261    /// Whether to prevent self-trade by quote order ID.
262    pub prevent_sor: bool,
263    /// Account update time in microseconds.
264    pub update_time: i64,
265    /// Account type.
266    pub account_type: String,
267    /// Account balances.
268    pub balances: Vec<BinanceBalance>,
269}
270
271/// Price filter from SBE response.
272#[derive(Debug, Clone, PartialEq)]
273pub struct BinancePriceFilterSbe {
274    /// Price exponent for mantissa conversion.
275    pub price_exponent: i8,
276    /// Minimum price mantissa.
277    pub min_price: i64,
278    /// Maximum price mantissa.
279    pub max_price: i64,
280    /// Tick size mantissa.
281    pub tick_size: i64,
282}
283
284/// Lot size filter from SBE response.
285#[derive(Debug, Clone, PartialEq)]
286pub struct BinanceLotSizeFilterSbe {
287    /// Quantity exponent for mantissa conversion.
288    pub qty_exponent: i8,
289    /// Minimum quantity mantissa.
290    pub min_qty: i64,
291    /// Maximum quantity mantissa.
292    pub max_qty: i64,
293    /// Step size mantissa.
294    pub step_size: i64,
295}
296
297/// Symbol filters from SBE response.
298#[derive(Debug, Clone, Default, PartialEq)]
299pub struct BinanceSymbolFiltersSbe {
300    /// Price filter (required for trading).
301    pub price_filter: Option<BinancePriceFilterSbe>,
302    /// Lot size filter (required for trading).
303    pub lot_size_filter: Option<BinanceLotSizeFilterSbe>,
304}
305
306/// Symbol information from SBE exchange info response.
307#[derive(Debug, Clone, PartialEq)]
308pub struct BinanceSymbolSbe {
309    /// Symbol name (e.g., "BTCUSDT").
310    pub symbol: String,
311    /// Base asset (e.g., "BTC").
312    pub base_asset: String,
313    /// Quote asset (e.g., "USDT").
314    pub quote_asset: String,
315    /// Base asset precision.
316    pub base_asset_precision: u8,
317    /// Quote asset precision.
318    pub quote_asset_precision: u8,
319    /// Symbol status.
320    pub status: u8,
321    /// Order types bitset.
322    pub order_types: u16,
323    /// Whether iceberg orders are allowed.
324    pub iceberg_allowed: bool,
325    /// Whether OCO orders are allowed.
326    pub oco_allowed: bool,
327    /// Whether OTO orders are allowed.
328    pub oto_allowed: bool,
329    /// Whether quote order quantity market orders are allowed.
330    pub quote_order_qty_market_allowed: bool,
331    /// Whether trailing stop is allowed.
332    pub allow_trailing_stop: bool,
333    /// Whether cancel-replace is allowed.
334    pub cancel_replace_allowed: bool,
335    /// Whether amend is allowed.
336    pub amend_allowed: bool,
337    /// Whether spot trading is allowed.
338    pub is_spot_trading_allowed: bool,
339    /// Whether margin trading is allowed.
340    pub is_margin_trading_allowed: bool,
341    /// Symbol filters decoded from SBE.
342    pub filters: BinanceSymbolFiltersSbe,
343    /// Permission sets.
344    pub permissions: Vec<Vec<String>>,
345}
346
347/// Exchange information from SBE response.
348#[derive(Debug, Clone, PartialEq)]
349pub struct BinanceExchangeInfoSbe {
350    /// List of symbols.
351    pub symbols: Vec<BinanceSymbolSbe>,
352}
353
354/// Account trade history entry.
355#[derive(Debug, Clone, PartialEq)]
356pub struct BinanceAccountTrade {
357    /// Price exponent.
358    pub price_exponent: i8,
359    /// Quantity exponent.
360    pub qty_exponent: i8,
361    /// Commission exponent.
362    pub commission_exponent: i8,
363    /// Trade ID.
364    pub id: i64,
365    /// Order ID.
366    pub order_id: i64,
367    /// Order list ID (for OCO).
368    pub order_list_id: Option<i64>,
369    /// Trade price mantissa.
370    pub price_mantissa: i64,
371    /// Trade quantity mantissa.
372    pub qty_mantissa: i64,
373    /// Quote quantity mantissa.
374    pub quote_qty_mantissa: i64,
375    /// Commission mantissa.
376    pub commission_mantissa: i64,
377    /// Trade time in microseconds.
378    pub time: i64,
379    /// Whether the trade was as buyer.
380    pub is_buyer: bool,
381    /// Whether the trade was as maker.
382    pub is_maker: bool,
383    /// Whether this is the best price match.
384    pub is_best_match: bool,
385    /// Symbol.
386    pub symbol: String,
387    /// Commission asset.
388    pub commission_asset: String,
389}
390
391/// Kline (candlestick) data response.
392#[derive(Debug, Clone, PartialEq)]
393pub struct BinanceKlines {
394    /// Price exponent for all klines.
395    pub price_exponent: i8,
396    /// Quantity exponent for all klines.
397    pub qty_exponent: i8,
398    /// List of klines.
399    pub klines: Vec<BinanceKline>,
400}
401
402/// A single kline (candlestick) from Binance.
403#[derive(Debug, Clone, PartialEq)]
404pub struct BinanceKline {
405    /// Kline open time in milliseconds.
406    pub open_time: i64,
407    /// Open price mantissa.
408    pub open_price: i64,
409    /// High price mantissa.
410    pub high_price: i64,
411    /// Low price mantissa.
412    pub low_price: i64,
413    /// Close price mantissa.
414    pub close_price: i64,
415    /// Volume (base asset) as 128-bit bytes.
416    pub volume: [u8; 16],
417    /// Kline close time in milliseconds.
418    pub close_time: i64,
419    /// Quote volume as 128-bit bytes.
420    pub quote_volume: [u8; 16],
421    /// Number of trades.
422    pub num_trades: i64,
423    /// Taker buy base volume as 128-bit bytes.
424    pub taker_buy_base_volume: [u8; 16],
425    /// Taker buy quote volume as 128-bit bytes.
426    pub taker_buy_quote_volume: [u8; 16],
427}