Repository navigation
Conversation
…n side and role Signed-off-by: huuan26 <phanbuihuuan261103@gmail.com>
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
Derive Gate
/api/v4/futures/usdt/price_orderstriggerrulefrom(role, pos_side)rather thanprice > request.entry_pricein_place_gate().Previously,
_place_gate()setrule = 1 if price > request.entry_price else 2, which inverted the trigger condition in two realistic cases:request.entry_price <= 0(e.g., queued protection orders placed beforeentry_priceis resolved), both SL and TP receivedrule = 1(>= trigger.price), causing a long stop-loss or short take-profit to trigger immediately at market.entry_price(long SL above entry or short SL below entry),ruleflipped to the opposite inequality and triggered an immediate close, whilegate_protection_orders()inquick_trade/position_activity.pymisclassified long SL orders (rule == 1) as"tp".This aligns
_place_gate()with_place_bybit()(native_protection.py) andgate_protection_orders()(quick_trade/position_activity.py).Changes
backend_api_python/app/services/live_trading/native_protection.py: computerises = (role == "take_profit" and request.pos_side == "long") or (role == "stop_loss" and request.pos_side == "short")and setrule = 1 if rises else 2.backend_api_python/tests/test_native_protection.py: add parametrized regression tests covering long/short SL and TP withentry_price=0.0and profit-locked stop-loss prices past entry, including round-trip classification viagate_protection_orders().Test plan
pytest tests/test_native_protection.py -k "not test_partial_fill_protection_client_ids_are_stable_and_distinct" --cov=app.services.live_trading.native_protection --cov-branch -v-> 29 passed, 1 deselected (0 missed lines/branches on modified lines; deselected test importspending_order_workerwhich requirescryptographyin local env).ruff check app scripts tests,compileall -q app scripts tests,backend_quality_check.py,check_requirements_lock.py,check_docs.py,check_version.py,check_mojibake.pyall pass.API documentation