Fox/project takeover baseline#1467
Open
huynhthiphuonghang321-oss wants to merge 128 commits intoNoFxAiOS:devfrom
Open
Fox/project takeover baseline#1467huynhthiphuonghang321-oss wants to merge 128 commits intoNoFxAiOS:devfrom
huynhthiphuonghang321-oss wants to merge 128 commits intoNoFxAiOS:devfrom
Conversation
Do not trust native trailing armed state in memory alone. Verify the exchange still has a live trailing order; if not, allow the runtime to re-arm native trailing instead of silently assuming protection is still active.
Log trailing placement response and move_order_stop query counts so we can pin down why OKX native trailing orders disappear after being armed.
…tive Prevent break-even native stop from competing with native full/partial trailing. This avoids the protection stack collapsing down to a single stop order while native trailing drawdown is supposed to own the exit logic.
…ack semantics - parse OKX advance algo response and fail when sCode != 0 - stop logging rejected trailing orders as successful placements - keep OKX callbackRatio in 0.001-1 ratio space and align tests with actual semantics
…ice move Drawdown trailing is a profit-protection system, so callback magnitude must be calculated as allowed giveback of earned profit, then converted into each exchange's native trailing callback format. This fixes the OKX trailing order rejection and aligns native trailing semantics across exchanges.
Convert drawdown rules into profit-based native trailing callback values: - activation price is based on min profit threshold - callback is based on allowed giveback of earned profit, not raw price percent - map callback into each exchange's native format (ratio for OKX, percent for Binance/Bitget) - treat OKX trailing response sCode != 0 as failure instead of false success This aligns exchange-native trailing behavior with the intended profit-protection model.
…e-profit plans When drawdown profit-control is enabled, suppress generic full/ladder take-profit legs while preserving generic stop-loss legs. This keeps profit-taking owned by drawdown/native trailing and avoids conflicts with static TP re-apply logic.
…ble exchanges For exchanges where we intend to use native partial trailing (OKX/Binance/Bitget), do not silently fall back to managed partial TP during runtime. Log the native failure explicitly and keep the system from re-entering the old managed path that pollutes protection state and open orders.
OKX callbackRatio for move_order_stop requires small decimal values such as 0.001415, but formatting with %.2f collapsed valid ratios to 0.00 and caused 51000 callBackRatio errors. Use full decimal formatting instead.
…wn profit-control owns TP side When drawdown/native trailing is enabled, old generic TP orders can continue to interfere with runtime profit-control. Reconciler now removes legacy generic TP orders for the active position while preserving generic SL legs, so drawdown owns the take-profit side cleanly.
Break-even no longer cancels existing stop-loss orders before placing its own native stop. This preserves ladder/full SL protection as long-term standing orders while allowing break-even to be managed independently, matching the intended separation of protection responsibilities.
…owns take-profit side Native trailing should suppress generic TP re-application, but generic SL must still be reconciled and restored. This fixes the case where ladder stop-loss orders disappear after drawdown/native trailing takes over the profit side.
For native trailing drawdown, do not cancel existing trailing orders before submitting a new one. This removes the protection gap created by cancel-first behavior and aligns with the required safety rule: place new, then clean old.
… confirmed After OKX accepts a new move_order_stop order, query current trailing orders and cancel older ones while keeping the freshly acknowledged algoId. This implements place-new-then-clean-old semantics for native trailing protection.
…ction Break-even stop should be managed independently and must not be suppressed just because drawdown/native trailing is active. Restore break-even arming while preserving the newer separation of stop-loss vs profit-control responsibilities.
…licate cleanup Duplicate cleanup previously only counted generic plan orders, so once ladder SL, break-even, and native trailing coexisted it treated valid protections as excess duplicates and wiped them. Include independent break-even and native trailing orders in expected count to preserve the full protection stack.
… state Break-even arming was overwriting the shared protectionState and causing reconciler cleanup/counting logic to lose track of native trailing ownership. Store break-even only in breakEvenState so trailing and break-even can coexist without corrupting protection-mode decisions.
Drawdown and break-even runtime logic should use pure price-move percentage, not leveraged return on margin. This ensures changing contract leverage does not change when protection rules trigger.
|
|
1 similar comment
|
|
Author
|
TP+SL |
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
Change Type
Scope
Linked Issues
Testing
What you verified and how:
go build ./...passesgo test ./...passesSecurity Impact
Yes/No)Yes/No)Yes/No)Compatibility
Yes/No)Yes/No)Yes/No)