Repository navigation
Engine: amend a position's stop, target and trail (#695) - #696
Conversation
A new order action amend changes the protective stop and take profit a broker holds for an open position. It never loosens the stop or the trail (the account sized the position from them), turns a fixed stop into a trailing one, and may move or add a target on the winning side of the latest price. Static problems fail the run through validate(); stateful ones (no position, loosening, wrong side) are expected rejections. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01DzeiWMoBKxFP8WVjepv2fP
rustyeddy
left a comment
There was a problem hiding this comment.
This has valuable coverage for move-to-breakeven/trailing stops, but it gets ahead of the agreed implementation sequence: Rusty explicitly kept #695 open for a focused later increment, with engine and external protocol changes together, after the initial working TCP/JSON vertical slice. Please do not merge as part of the first protocol slice without a fresh owner decision.
Two behavioral points to resolve/test when we pick this up:
- The amend request is recorded as
stateFilledwhile explicitly not being an execution/fill (broker.completedexcludes it). Please clarify the domain semantics: isstateFilledintended to mean 'amend accepted/applied', or should we represent amendment completion distinctly without confusing trade-fill accounting/results? ADR-093's single order lifecycle should remain authoritative. - A changed protective stop and target are mutated in place and stored in exit history. Verify that the future durable journal can reconstruct pre-amend and post-amend state and the reason for expected stateful rejections—not just read
br.amendedin memory. This is particularly important for Investor's postmortem.
I have not independently run make check here; the PR reports it passed. Recommendation: keep the PR available for later focused review, but first finish and test the base transport slice.
|
Correction to my review: I misunderstood Rusty's use of v1. He means a complete milestone that can perform realistic external strategy backtests, achieved through incremental features; not the very first vertical slice. Thus it is entirely reasonable to develop |
…ateFilled means for an amend (#695) Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01DzeiWMoBKxFP8WVjepv2fP
rustyeddy
left a comment
There was a problem hiding this comment.
Re-review at 3b4b2d5: the earlier conceptual comments are addressed in this revision. The code now explicitly defines stateFilled for amend as applied, not an execution, keeps it out of broker.completed, and records the amendment ID plus before/after values on modified exits. The tests cover tightening, stateful rejection, target changes, trailing ratchet, timing, and account isolation. I see no remaining blocker in the diff for this focused engine increment. Merge recommendation: yes, subject to the normal required checks/owner approval. I could not independently execute make check, and GitHub reported no commit statuses for this SHA; the PR itself reports a clean run. Durable on-disk journal implementation remains tracked separately under #702.
Closes #695
Adds the order action
amend, which changes the protective stop and take profit the broker holds for an open position. Needed by the external strategy protocol (#690, ADR-094) and usable in process.Rules (owner decisions on #690):
validate(); stateful problems (no position, loosening, wrong side) are expected rejections kept intrader.rejected, and the run continues.broker.completedand is not counted as a fill. It is kept inbroker.amended, and each exit it changed records the change in its history.Verification:
make checkclean; EMAX md5 unchanged (195e457a21def1223e7181c86cb824a4); 25 new tests in broker_test.go, order_test.go and trader_test.go; six rule mutations (each loosening or side check, applying the change, the position check) each fail a test.🤖 Generated with Claude Code
https://claude.ai/code/session_01DzeiWMoBKxFP8WVjepv2fP