Repository navigation
Deliver execution feedback with the next OnBars (#698) - #713
Merged
Merged
Conversation
A worker that asks for it (strategy.Event) is told what the trader did with its orders: accepted, filled, rejected (with the reason) or cancelled, and the broker's own exits (protective stop, take profit, closeout) when they fill. The events are collected after the broker has processed the frame and before onBars, so a request carries the broker's work on its own bars and the outcome of the previous call's orders, never the outcome of the orders it is about to return. Each is delivered once, in time order. Order gains an optional ref echoed on its events. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Owner
Author
|
Reviewed PR #713 ( What looks right:
One non-blocking limitation to document explicitly: Events created by the final No blocking findings from this code review. Merge recommendation: yes, provided CI / |
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.
Closes #698. Part of #690. Implements the plan posted on #698 (defaults unchanged: optional
feedbackerinterface,Order.Refechoed on events, kinds accepted / filled / rejected / cancelled).What
A worker is told what Trader did with its orders, in the same request as the next group of bars. There is no second channel and no new state machine; Trader still owns risk, sizing, execution and OrderState.
Timing (no look-ahead, no leak)
trader.onFramenow collects events afterbroker.onFrame(f)and beforeonBars. A request therefore carries:It never carries the outcome of the orders returned by this same call, which are handled after
onBarsreturns and reported with the next group. Each history entry is delivered once (a per-order cursor), in time order; on a tie the strategy's own orders come before the broker's exits.Event mapping
Events come from the existing
order.history,trader.rejectedandbroker.completed; nothing new records them.feedback.go(root):Delivery uses a small optional interface next to
warmer,feedbacker { feedback([]feedbackEvent) }, called just beforeonBarsonly when the strategy implements it. In-process strategies and EMAX are untouched (md5195e457a…unchanged); the remote adapter keeps the events and sends them with the next group.Public type (
strategy.Event, read-only, no domain types)timekindaccepted,filled,rejected,cancelledidrefOrder.Ref, echoed; empty for the broker's own ordersinstrument,action,directionunitspricefilledcausestrategy,stop loss,take profit,margin closeout: afilledwith causestop lossis a protective-stop exitreasonrejected/cancelledRejected orders have no id (ids are issued at submit; giving refusals ids would shift later ids), so the worker labels an order with the new optional
Order.Refand gets it back on that order's events. The adapter keeps the label in amap[*order]string; the domainordergets no new field.Wire and API
The request is
{"bars":[...],"events":[...]}, with the same framing, deadline, size cap and strict decoding.eventsis required and may be[](missing ornullis an error, as with the orders list).Client.OnBars(ctx, bars, events); theServe/ListenAndServecallback isfunc(bars, events) ([]Order, error).examples/remote-strategy: same rule as before, but it closes on the 6th group only if it saw its entry fill and the stop has not already taken it out, and it prints each event to stderr.Tests
feedback_test.go): nothing before the first order; accepted and filled told with the next group, not the asking one; delivered once; time order regardless of watch order; protective-stop and take-profit exits with their causes and none of their housekeeping; refusal at sizing carries the reason and no id; a waiting order that expires is reported cancelled; a strategy that does not ask is not watched; the wire mapping per state.strategy:Eventwire form; the client sends[]rather thannull; the server hands events to the callback and refuses a request without the list;refround trip.a-reversal-exit: the same feedback-driven rule in-process and remote for (1) fill then a close it asked for, (2) a protective-stop exit after which the worker skips its close, (3) a sizing refusal. The worker is told exactly what the in-process strategy is told, and the runs end with identical orders, fills, rejections, balance and trades. The real example binary run as a separate process matches the in-process rule and prints the events.make checkpasses; EMAX md5 unchanged.Known limitation (by design)
Feedback rides on the next group, so events caused by the last callback's orders, or by the broker after the last delivered group, have no following callback to arrive in. A worker must not assume it receives a complete event set before the connection closes. The durable run journal (#702) has to preserve those events; run finalization is out of this increment.
Deferred
Position and account snapshots, push or async events, amend/trail events, richer per-fill fields (margin, P/L), registration/RunID, a Trader-side listener, journal (#702), REST (#700), auth/TLS, binary transport.
unitson anacceptedclose is the position size once known (a close is not sized at accept time).🤖 Generated with Claude Code