Repository navigation
2.1.0 — Hardening the trade clock
Hardening the trade clock — the smallest and least-tested part of this project,
which is backwards, since it is the only part that can lose money.
Most of what follows was found by running the live path rather than reading it.
Two were live bugs that looked correct in the source and passed every test.
Fixed
The live path could open a position but never close one. A strategy decides
whether an exit is legitimate by looking itself up in its own position book, and
nothing in live mode ever wrote that book — so every CLOSE_BUY/CLOSE_SELL was
rewritten to HOLD before execution saw it. A live position could only be closed by
its broker-side bracket legs, if it had any. The unit tests passed throughout,
because they feed handle_signal directly and so exercise the layer below the break.
A strategy could go permanently silent with nothing logged. Warm-up history is
timezone-aware and a feed may stream naive timestamps; mixing them made every later
comparison raise inside process_bar, whose blanket except turned that into a
strategy that emitted nothing at all, indefinitely.
Warm-up fetched a fraction of the history it asked for. The lookback converted
bars to wall-clock time directly, which counts the overnight gap, the weekend and
every holiday as tradeable: fifty one-minute bars became "100 minutes ago", so a
09:35 start warmed a fifty-bar indicator with five bars and ran anyway. The window is
now measured in sessions, and a short warm-up is reported rather than absorbed.
Missed signal edges were lost for good. Entries fire on the crossing bar and
never again, so a rejected bar, a dropped stream or a restart left the score saying
"should be long" while every bar emitted HOLD.
Added
A kill switch. tradeflow halt | resume | halts records a durable decision to
stop; tradeflow flatten --confirm halts, cancels every order and closes every
position, going straight to the broker so it works when the engine is wedged. Halt
state is a file, not a database — the order path holds no connection to anything that
can be down. Halts block entries and never exits, so the switch cannot trap the book
and flatten cannot deadlock against its own gate.
Deterministic client order ids. The guard against double-submitting was a
question asked of the broker immediately before placing an order — a check-then-act
race with no memory across a restart. Each order now carries an id derived from the
decision behind it, so a venue that has already accepted it rejects the duplicate.
Typed broker failures. Every broker call used to fail as None or False, so a
rate limit, an expired token, insufficient funds and a deliberate rejection all
produced the same non-answer. Two cases were actively wrong: a duplicate order read
as a failed submission, and list_positions returning [] — the claim that the
account is flat — when the broker could not be reached.
A decision record for every signal. "No order" had a dozen causes and one
representation. Execution now returns what it decided, why, and which guards it
consulted — the guards that ran, not just the one that fired.
Changed — read before upgrading
- A strategy started while the score already implies a position takes it on the
first live bar, rather than waiting for the next crossing, with stops from the
current price. Default on;--no-reaffirm-entriesopts out. - An unreadable market clock no longer uniformly means "assume open." That is
right for a transient blip but was also applied to revoked credentials, which are
never transient. Authentication failures now fail closed. - Position-book hydration is not governed by
--reconcile-every. A broker read
happens at start-up even with reconciliation disabled. - Internal trade-clock interfaces changed shape.
Broker.submit_*take a
client_order_id; the order-path methods raiseBrokerErrorrather than returning
None/False;LiveTrader.handle_signalreturns aDecision. No supported API
moved —tradeflow.services.*is the supported surface and is untouched — which is
why this is a minor. Anyone who reached past it into the broker or execution layer
will need these.
Verified
881 tests (up from 817), ruff clean, links clean across 98 files, the docs site
compiles, and the wheel installs into a clean venv and reports 2.1.0 with every new
verb resolving from that installed copy. The halt/resume/flatten CLI was driven end
to end. Both follow-up regressions were confirmed to fail with the fix backed out,
rather than assumed to cover it.
No live paper smoke test: every change here is on the order path, and the suite
drives the real LiveEngine and LiveTrader against faked edges only.
Full changelog: https://tradeflow.mk-dir.com/changelog