Skip to content

Support native trailing stop protection - #429

Closed
PranavHariharan19 wants to merge 1 commit into
OpenByteInc:mainfrom
PranavHariharan19:fix/quick-trade-trailing-protection
Closed

PranavHariharan19 wants to merge 1 commit into
OpenByteInc:mainfrom
PranavHariharan19:fix/quick-trade-trailing-protection

Conversation

@PranavHariharan19

Copy link
Copy Markdown
Contributor

Summary

Enables exchange-native trailing stop protection for Quick Trade orders. Previously, while native_protection.py supported trailing stops across venues (such as Binance TRAILING_STOP_MARKET, Bitget trailing_stop, Bybit v5/position/trading-stop, and OKX move_order_stop), the Quick Trade order routing layer (quick_trade.py) omitted parsing trailing_stop_pct and trailing_activation_pct from request payloads. Furthermore, attach_quick_trade_protection() aborted immediately whenever tp_price <= 0 and sl_price <= 0, silently dropping standalone trailing protection requests.

This PR wires trailing stop parameters through the Quick Trade workflow, deferred fill worker, and Agent V1 endpoints so users can submit and attach exchange-native trailing stops.

Related issue

Changes

  • Updated attach_quick_trade_protection() in backend_api_python/app/services/quick_trade/orders.py to accept trailing_stop_pct and trailing_activation_pct, adjust the early-exit guard to allow standalone trailing stops, and forward parameters into NativeProtectionRequest.
  • Updated place_order() in backend_api_python/app/routes/quick_trade.py to extract trailing_stop_pct / trailingStopPct and trailing_activation_pct / trailingActivationPct, forward them to attach_quick_trade_protection(), record them in order metadata, and recognize them in quick_trade_protection_status().
  • Updated _place_live_order() in backend_api_python/app/routes/agent_v1/quick_trade.py to parse and forward trailing stop parameters.
  • Updated PendingOrderWorker._sync_one_quick_trade_order() in backend_api_python/app/services/pending_order_worker.py to pass stored trailing protection parameters when attaching native protection to deferred fills.
  • Added comprehensive unit and route regression tests in backend_api_python/tests/test_quick_trade_trailing_protection.py.

Test plan

  • Tested locally with docker compose up -d --build
  • Backend logs show no errors
  • Relevant pytest tests pass (pytest tests/test_quick_trade_*.py tests/test_native_protection.py -q — 258 passed)

API documentation (if routes/schemas changed)

  • Regenerated docs/api/openapi.yaml (cd backend_api_python && python scripts/export_openapi.py)
  • Updated docs/agent/agent-openapi.json if /api/agent/v1 routes changed
  • Breaking API changes called out below (oasdiff will fail CI otherwise)

Note: Non-breaking addition of optional fields (trailing_stop_pct, trailing_activation_pct) to existing order submission endpoints.

Screenshots (if UI change)

N/A (Backend order protection handling and parameter routing)

Roadmap contribution (if applicable)

  • A maintainer confirmed the claimed scope before implementation
  • This PR implements one reviewable slice rather than an entire epic
  • User-facing behavior and compatibility notes are documented

@sonarqubecloud

Copy link
Copy Markdown

@brokermr810

Copy link
Copy Markdown
Collaborator

Thanks for the contribution! We incorporated your changes into [PR #430](#430), preserving your original authorship in commit 6eeec45.

We also added validation, delayed-fill handling, protection-status checks, and regression coverage across the affected trading paths.

I’m closing this PR as superseded by #430 to keep the related fixes together. Your contribution is included—thank you for identifying and fixing the original issue!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants