fix(trade): switch the core's manual strategy off ahead of a bare order - #541
Merged
Conversation
A manual order placed with the terminal's manual-strategy mode OFF goes out under StratID=0, which the core reads as "attach whatever my own use_manual_strategy names" - there is no "deliberately none" value on the wire. With Moonbot's own checkbox on, three bare orders on BB1 (2026-09-13) were attached to a strategy nobody chose here and followed its hook. The exit barrier a bare order already waits behind now carries use_manual_strategy=false in the same ClientSettings packet as the group exits (SettingsMutation::NoManualStrategy), confirmed by the core's echo like any other mutation and abandoned after the same retry budget - with a log line naming the order and the consequence when the core will not hold it. Orders that name a strategy are unchanged: an explicit id is honoured regardless of the switch, so Moonbot's screen is left alone there. The stale pre-order warning is gone and the docs that promised the switch is never written now say when it is.
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.
What & why
A manual order placed with the terminal's manual-strategy mode OFF goes to the core with
StratID = 0. On the wire zero is not "no strategy" — it is "attach whatever the core's ownuse_manual_strategy/manual_strategy_idnames", and moonproto has no value for "deliberately none". With Moonbot's own checkbox left on, three bare orders on BB1 (2026-09-13 03:37) were attached to a Manual strategy nobody selected in the terminal and followed its hook: sell and trailing came from the strategy, not from the TP/SL the terminal had just confirmed.The exit barrier a bare order already waits behind (
ClientSettingsSequence::enqueue_order,sync_exit == true) now queues a privateSettingsMutation::NoManualStrategythat writesuse_manual_strategy = falseinto the SAME full-snapshot ClientSettings packet as the group exits. It is confirmed by the core's echo like every other mutation and abandoned after the sameMAX_EXIT_ATTEMPTS, so it costs no extra round trip on a core whose switch is already off, and one echo on a core whose switch is on.Orders that name a strategy (mode ON) are unchanged: an explicit id is honoured regardless of the core's switch (checked live), so Moonbot's own screen is left alone there and two terminals on one core can still sit on different strategies.
Notable decisions
manual_strategy_idis not touched, so the seed that adopts a never-seen core (tick_manual_strat_seed) still finds the selection and keeps it (mode off, strategy kept).log::warnthat only guessed at this is gone.sync_exit; a shared counter would drop mutations queued later (TempBL during the wait) before their budget.Known limitations
serialized client settings sentBEFOREplace order … strat=None, Moonbot's checkbox going off, the order living under the terminal's TP/SL rather than the strategy's hook.Startneeds a "no strategy" reading, asStartPendingalready has. Write-up for the core/moonproto team is indocs-internal/proto_bare_order_manual_strategy.md(not tracked).Issues
None of the 16 open issues is touched by this change.
How to verify
fmt
--checkexit 0 · build all targets green · clippy: 107 pre-existing locations on the branch, 107 onorigin/main, per-file counts identical — zero new findings · tests: moon-core 1947 passed, moon-ui-gpui 1799 passed + theme_contract 330 passed, 0 failed · FireTest not run (no chart/render/window/input surface). Three new unit tests infeed/live/client_settings/tests.rs: the switch travels off in the exit packet and the order waits for its echo; an order with a strategy leaves the switch alone; a core that keeps its switch on does not strand the order.🤖 Generated with Claude Code