Repository navigation
Description
Describe the bug
The exchange protection engine in backend_api_python/app/services/live_trading/native_protection.py fully implements exchange-native trailing stops (e.g. Binance TRAILING_STOP_MARKET, Bitget trailing_stop, Bybit v5/position/trading-stop, OKX move_order_stop).
However, in the Quick Trade workflow, trailing stop parameters are completely dropped:
-
Parameter parsing omission in
place_order:
Inbackend_api_python/app/routes/quick_trade.py(lines 256–258), the route extractstp_priceandsl_price, but never parsestrailing_stop_pctortrailing_activation_pctfrom the request payload:tp_price = float(body.get("tp_price") or 0) sl_price = float(body.get("sl_price") or 0) # trailing_stop_pct and trailing_activation_pct are omitted
-
Premature guard and missing fields in
attach_quick_trade_protection:
Inbackend_api_python/app/services/quick_trade/orders.py(lines 240–263):def attach_quick_trade_protection( client: Any, *, symbol: str, side: str, filled_qty: float, avg_price: float, tp_price: float = 0.0, sl_price: float = 0.0, ... ): if float(filled_qty or 0.0) <= 0 or float(avg_price or 0.0) <= 0: return [] if float(tp_price or 0.0) <= 0 and float(sl_price or 0.0) <= 0: return [] # Discards request even if a trailing stop was specified! request = NativeProtectionRequest( symbol=str(symbol), pos_side="long" if str(side or "").lower() == "buy" else "short", quantity=float(filled_qty), entry_price=float(avg_price), stop_loss_price=float(sl_price or 0.0), take_profit_price=float(tp_price or 0.0), # trailing_stop_pct and trailing_activation_pct are omitted, defaulting to 0.0 )
When a user submits a Quick Trade swap order specifying a trailing stop (or trailing stop without fixed TP/SL), the protection request is silently ignored, and no trailing stop order is placed with the exchange.
Steps to reproduce
- Submit a Quick Trade swap order POST to
/api/quick_trade/place_orderwith trailing protection parameters:{ "credential_id": 1, "symbol": "BTC/USDT", "side": "buy", "order_type": "market", "amount": 100, "leverage": 5, "market_type": "swap", "trailing_stop_pct": 0.02, "trailing_activation_pct": 0.05 } - Inspect the placed order response and backend execution trace.
- Observe that
attach_quick_trade_protectionreturns[]immediately due totp_price <= 0 and sl_price <= 0. - Observe that no native trailing stop order (
TRAILING_STOP_MARKET) is dispatched to the exchange.
Expected behavior
quick_trade.place_ordershould extracttrailing_stop_pctandtrailing_activation_pctfrom the request JSON and forward them through the protection attachment flow.attach_quick_trade_protectionshould allow requests wheretrailing_stop_pct > 0, constructNativeProtectionRequestwithtrailing_stop_pctandtrailing_activation_pct, and dispatch the native trailing stop to the exchange.- Protection status calculation in
quick_trade_protection_statusshould recognize trailing stops as requested protection.
Deployment method
Docker Compose
Relevant logs
INFO app.routes.quick_trade: Quick trade order executed: symbol=BTC/USDT, filled=0.01
DEBUG app.services.quick_trade.orders: attach_quick_trade_protection skipped: tp_price=0.0, sl_price=0.0 (trailing_stop_pct ignored)
INFO app.routes.quick_trade: protection_status: not_requested
Activity
PranavHariharan19 commentedon Nov 28, 2026
I found this bug while going through the codebase.
I will work on a fix and submit it for review.
PranavHariharan19 commentedon Nov 28, 2026
I have submitted a pull request that fixes this issue.
Please go through it and tell me what you think.