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/// Symbol information from SBE exchange info response.
272#[derive(Debug, Clone, PartialEq)]
273pub struct BinanceSymbolSbe {
274    /// Symbol name (e.g., "BTCUSDT").
275    pub symbol: String,
276    /// Base asset (e.g., "BTC").
277    pub base_asset: String,
278    /// Quote asset (e.g., "USDT").
279    pub quote_asset: String,
280    /// Base asset precision.
281    pub base_asset_precision: u8,
282    /// Quote asset precision.
283    pub quote_asset_precision: u8,
284    /// Symbol status.
285    pub status: u8,
286    /// Order types bitset.
287    pub order_types: u16,
288    /// Whether iceberg orders are allowed.
289    pub iceberg_allowed: bool,
290    /// Whether OCO orders are allowed.
291    pub oco_allowed: bool,
292    /// Whether OTO orders are allowed.
293    pub oto_allowed: bool,
294    /// Whether quote order quantity market orders are allowed.
295    pub quote_order_qty_market_allowed: bool,
296    /// Whether trailing stop is allowed.
297    pub allow_trailing_stop: bool,
298    /// Whether cancel-replace is allowed.
299    pub cancel_replace_allowed: bool,
300    /// Whether amend is allowed.
301    pub amend_allowed: bool,
302    /// Whether spot trading is allowed.
303    pub is_spot_trading_allowed: bool,
304    /// Whether margin trading is allowed.
305    pub is_margin_trading_allowed: bool,
306    /// Symbol filters (JSON embedded in SBE).
307    pub filters: Vec<serde_json::Value>,
308    /// Permission sets.
309    pub permissions: Vec<Vec<String>>,
310}
311
312/// Exchange information from SBE response.
313#[derive(Debug, Clone, PartialEq)]
314pub struct BinanceExchangeInfoSbe {
315    /// List of symbols.
316    pub symbols: Vec<BinanceSymbolSbe>,
317}
318
319/// Account trade history entry.
320#[derive(Debug, Clone, PartialEq)]
321pub struct BinanceAccountTrade {
322    /// Price exponent.
323    pub price_exponent: i8,
324    /// Quantity exponent.
325    pub qty_exponent: i8,
326    /// Commission exponent.
327    pub commission_exponent: i8,
328    /// Trade ID.
329    pub id: i64,
330    /// Order ID.
331    pub order_id: i64,
332    /// Order list ID (for OCO).
333    pub order_list_id: Option<i64>,
334    /// Trade price mantissa.
335    pub price_mantissa: i64,
336    /// Trade quantity mantissa.
337    pub qty_mantissa: i64,
338    /// Quote quantity mantissa.
339    pub quote_qty_mantissa: i64,
340    /// Commission mantissa.
341    pub commission_mantissa: i64,
342    /// Trade time in microseconds.
343    pub time: i64,
344    /// Whether the trade was as buyer.
345    pub is_buyer: bool,
346    /// Whether the trade was as maker.
347    pub is_maker: bool,
348    /// Whether this is the best price match.
349    pub is_best_match: bool,
350    /// Symbol.
351    pub symbol: String,
352    /// Commission asset.
353    pub commission_asset: String,
354}