Fix: mirror funds only ever traded in a burst at startup - #13
Open
mpont91 wants to merge 1 commit into
Open
Conversation
FundTradeListener advanced its highwater mark to now() on every poll and selected trades whose ts fell in that window. Trades reach ClickHouse minutes after they happen, so by the time one lands the mark is already past its ts and no window can contain it. Only the startup lookback ever saw anything. The window is over ingested_at now, and pollForTrades is synchronized because the multi-fund scheduler overlaps invocations.
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.
On first poll
FundTradeListenerlooks back an hour; from then on the window is[lastPollTime, now]andlastPollTimeis set tonowat the end of every poll. The query selects onts:Trades do not reach ClickHouse the instant they happen. Measured on a live instance the lag between
tsandingested_atis a steady ~4.5 minutes (median 267s, p95 285s, max 296s). A trade therefore becomes visible several minutes after the highwater mark has passed itsts, and no window will ever contain it.The only trades a fund ever sees are the ones already in the table when the startup lookback runs.
Evidence
Fund executions on a running instance, grouped by hour:
Meanwhile the index constituents traded ~1,400 times in the same 24 hours. Between restarts the funds are inert.
Fix
Window on
ingested_at, which is when a row becomes visible, so nothing can arrive behind the mark. Signals still carry the real trade timestamp, so the delay a fund sees is the pipeline lag and nothing more.pollForTradesis alsosynchronized.MultiFundConfiguration.pollPsiMirrorFundsruns at a fixed 1s rate over every fund; when a round takes longer than that the next starts on another thread, both read the samelastPollTime, and the same trade is queued twice. It shows up in the logs as one signal emitted by two scheduling threads a millisecond apart — two mirrored orders for one trader action.After
Executions now arrive continuously rather than only after a restart, across all six mirror funds.