nautilus_binance/spot/
enums.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-specific enumerations.
17
18use nautilus_model::enums::OrderType;
19use serde::{Deserialize, Serialize};
20
21/// Spot order type enumeration.
22#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
23#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
24pub enum BinanceSpotOrderType {
25    /// Limit order.
26    Limit,
27    /// Market order.
28    Market,
29    /// Stop loss (triggers market sell when price drops to stop price).
30    StopLoss,
31    /// Stop loss limit (triggers limit sell when price drops to stop price).
32    StopLossLimit,
33    /// Take profit (triggers market sell when price rises to stop price).
34    TakeProfit,
35    /// Take profit limit (triggers limit sell when price rises to stop price).
36    TakeProfitLimit,
37    /// Limit maker (post-only, rejected if would match immediately).
38    LimitMaker,
39    /// Unknown or undocumented value.
40    #[serde(other)]
41    Unknown,
42}
43
44/// Spot order response type.
45#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]
46#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
47pub enum BinanceOrderResponseType {
48    /// Acknowledge only (fastest).
49    Ack,
50    /// Result with order details.
51    Result,
52    /// Full response with fills.
53    #[default]
54    Full,
55}
56
57/// Cancel/replace mode for order modification.
58#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
59#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
60pub enum BinanceCancelReplaceMode {
61    /// Stop if cancel fails.
62    StopOnFailure,
63    /// Continue with new order even if cancel fails.
64    AllowFailure,
65}
66
67/// Converts a Nautilus order type to Binance Spot order type.
68///
69/// # Errors
70///
71/// Returns an error if the order type is not supported on Binance Spot.
72pub fn order_type_to_binance_spot(
73    order_type: OrderType,
74    post_only: bool,
75) -> anyhow::Result<BinanceSpotOrderType> {
76    match (order_type, post_only) {
77        (OrderType::Market, _) => Ok(BinanceSpotOrderType::Market),
78        (OrderType::Limit, true) => Ok(BinanceSpotOrderType::LimitMaker),
79        (OrderType::Limit, false) => Ok(BinanceSpotOrderType::Limit),
80        (OrderType::StopMarket, _) => Ok(BinanceSpotOrderType::StopLoss),
81        (OrderType::StopLimit, _) => Ok(BinanceSpotOrderType::StopLossLimit),
82        _ => anyhow::bail!("Unsupported order type for Binance Spot: {order_type:?}"),
83    }
84}