Skip to content

Quick Trade drops trailing_stop_pct and trailing_activation_pct parameters and fails to attach native trailing protection #428

Done

Description

@PranavHariharan19

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:

  1. Parameter parsing omission in place_order:
    In backend_api_python/app/routes/quick_trade.py (lines 256–258), the route extracts tp_price and sl_price, but never parses trailing_stop_pct or trailing_activation_pct from 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
  2. Premature guard and missing fields in attach_quick_trade_protection:
    In backend_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

  1. Submit a Quick Trade swap order POST to /api/quick_trade/place_order with 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
    }
  2. Inspect the placed order response and backend execution trace.
  3. Observe that attach_quick_trade_protection returns [] immediately due to tp_price <= 0 and sl_price <= 0.
  4. Observe that no native trailing stop order (TRAILING_STOP_MARKET) is dispatched to the exchange.

Expected behavior

  1. quick_trade.place_order should extract trailing_stop_pct and trailing_activation_pct from the request JSON and forward them through the protection attachment flow.
  2. attach_quick_trade_protection should allow requests where trailing_stop_pct > 0, construct NativeProtectionRequest with trailing_stop_pct and trailing_activation_pct, and dispatch the native trailing stop to the exchange.
  3. Protection status calculation in quick_trade_protection_status should 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

  1. added
    bug
    on Nov 28, 2026
  2. PranavHariharan19 commented on Nov 28, 2026

    @PranavHariharan19
    ContributorAuthor

    I found this bug while going through the codebase.
    I will work on a fix and submit it for review.

  3. PranavHariharan19 commented on Nov 28, 2026

    @PranavHariharan19
    ContributorAuthor

    I have submitted a pull request that fixes this issue.
    Please go through it and tell me what you think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions