Skip to content

Fox/project takeover baseline#1467

Open
huynhthiphuonghang321-oss wants to merge 128 commits intoNoFxAiOS:devfrom
MAX-LIUS:fox/project-takeover-baseline
Open

Fox/project takeover baseline#1467
huynhthiphuonghang321-oss wants to merge 128 commits intoNoFxAiOS:devfrom
MAX-LIUS:fox/project-takeover-baseline

Conversation

@huynhthiphuonghang321-oss
Copy link
Copy Markdown

Summary

  • Problem:
  • What changed:
  • What did NOT change (scope boundary):

Change Type

  • Bug fix
  • Feature
  • Refactoring
  • Docs
  • Security fix
  • Chore / infra

Scope

  • Trading engine / strategies
  • MCP / AI clients
  • API / server
  • Telegram bot / agent
  • Web UI / frontend
  • Config / deployment
  • CI/CD / infra

Linked Issues

  • Closes #
  • Related #

Testing

What you verified and how:

  • go build ./... passes
  • go test ./... passes
  • Manual testing done (describe below)

Security Impact

  • Secrets/keys handling changed? (Yes/No)
  • New/changed API endpoints? (Yes/No)
  • User input validation affected? (Yes/No)

Compatibility

  • Backward compatible? (Yes/No)
  • Config/env changes? (Yes/No)
  • Migration needed? (Yes/No)
  • If yes, upgrade steps:

MAX-LIUS added 30 commits March 21, 2026 23:53
MAX-LIUS added 25 commits April 12, 2026 15:16
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.
@cla-assistant
Copy link
Copy Markdown

cla-assistant Bot commented Apr 12, 2026

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

1 similar comment
@cla-assistant
Copy link
Copy Markdown

cla-assistant Bot commented Apr 12, 2026

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@huynhthiphuonghang321-oss
Copy link
Copy Markdown
Author

TP+SL

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.

2 participants