From 20732387a6db45fadbc48d14ef5899113832775f Mon Sep 17 00:00:00 2001 From: Mukan Erkin Date: Sat, 25 Apr 2026 11:55:46 +0300 Subject: [PATCH] fix(mse): validate NOTIONAL filter before placing buy order SymbolFilters now parses minNotional from Binance NOTIONAL filter. strategy.rs checks qty*price >= minNotional before market_buy, returning a descriptive error instead of letting Binance reject with -1013. Co-Authored-By: Claude Sonnet 4.6 --- src/binance/client.rs | 6 +++++- src/binance/models.rs | 4 ++++ src/bot/strategy.rs | 6 ++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/binance/client.rs b/src/binance/client.rs index 2b2f7e9..67ab26a 100644 --- a/src/binance/client.rs +++ b/src/binance/client.rs @@ -223,6 +223,7 @@ impl BinanceClient { let mut price_decimals = 2usize; let mut step_size = 0.01f64; let mut min_qty = 0.0f64; + let mut min_notional = 0.0f64; for filter in filters { match filter["filterType"].as_str() { @@ -236,11 +237,14 @@ impl BinanceClient { let tick = filter["tickSize"].as_str().unwrap_or("0.01"); price_decimals = count_decimals(tick); } + Some("NOTIONAL") => { + min_notional = filter["minNotional"].as_str().unwrap_or("0").parse().unwrap_or(0.0); + } _ => {} } } - Ok(SymbolFilters { qty_decimals, price_decimals, step_size, min_qty }) + Ok(SymbolFilters { qty_decimals, price_decimals, step_size, min_qty, min_notional }) } /// Tüm USDT spot işlem çiftlerini döner — public endpoint, API key gerektirmez diff --git a/src/binance/models.rs b/src/binance/models.rs index edc8314..a5ee071 100644 --- a/src/binance/models.rs +++ b/src/binance/models.rs @@ -52,6 +52,7 @@ pub struct SymbolFilters { pub price_decimals: usize, pub step_size: f64, pub min_qty: f64, + pub min_notional: f64, } impl SymbolFilters { @@ -70,6 +71,9 @@ impl SymbolFilters { pub fn qty_is_valid(&self, qty: f64) -> bool { qty >= self.min_qty } + pub fn notional_is_valid(&self, qty: f64, price: f64) -> bool { + self.min_notional <= 0.0 || qty * price >= self.min_notional + } } /// Timeframe tanımları diff --git a/src/bot/strategy.rs b/src/bot/strategy.rs index a21a069..bf4b655 100644 --- a/src/bot/strategy.rs +++ b/src/bot/strategy.rs @@ -38,6 +38,12 @@ impl RedCandleStrategy { quantity, filters.min_qty )); } + if !filters.notional_is_valid(qty_f, kline.close) { + return Err(anyhow::anyhow!( + "İşlem tutarı ({:.2} USDT) min notional ({} USDT) altında — USDT miktarını artır", + qty_f * kline.close, filters.min_notional + )); + } info!("[{}] Market alım | Miktar: {} | Fiyat tahmini: {:.6}", symbol, quantity, kline.close);