nautilus_binance/common/fees.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 instrument fee fallbacks.
17
18use rust_decimal::Decimal;
19
20/// Default Spot maker and taker fee when account rates are unavailable.
21pub const BINANCE_SPOT_FEE_DEFAULT: Decimal = Decimal::from_parts(1, 0, 0, false, 3);
22
23/// Returns the documented USD-M VIP maker and taker rates used by legacy parity.
24///
25/// Tiers above 9 use tier 0 so an unknown venue value cannot silently grant a
26/// lower commission estimate.
27#[must_use]
28pub fn futures_fee_tier_rates(tier: u8) -> (Decimal, Decimal) {
29 match tier {
30 1 => (Decimal::new(16, 5), Decimal::new(4, 4)),
31 2 => (Decimal::new(14, 5), Decimal::new(35, 5)),
32 3 => (Decimal::new(12, 5), Decimal::new(32, 5)),
33 4 => (Decimal::new(1, 4), Decimal::new(3, 4)),
34 5 => (Decimal::new(8, 5), Decimal::new(27, 5)),
35 6 => (Decimal::new(6, 5), Decimal::new(25, 5)),
36 7 => (Decimal::new(4, 5), Decimal::new(22, 5)),
37 8 => (Decimal::new(2, 5), Decimal::new(2, 4)),
38 9 => (Decimal::ZERO, Decimal::new(17, 5)),
39 _ => (Decimal::new(2, 4), Decimal::new(5, 4)),
40 }
41}
42
43#[cfg(test)]
44mod tests {
45 use rstest::rstest;
46 use rust_decimal_macros::dec;
47
48 use super::*;
49
50 #[rstest]
51 #[case(0, dec!(0.0002), dec!(0.0005))]
52 #[case(4, dec!(0.0001), dec!(0.0003))]
53 #[case(9, dec!(0), dec!(0.00017))]
54 #[case(10, dec!(0.0002), dec!(0.0005))]
55 fn test_futures_fee_tier_rates(
56 #[case] tier: u8,
57 #[case] expected_maker: Decimal,
58 #[case] expected_taker: Decimal,
59 ) {
60 assert_eq!(
61 futures_fee_tier_rates(tier),
62 (expected_maker, expected_taker)
63 );
64 }
65}