Repository navigation
Intraday bars are cut from TradingView's session start
TradingView cuts every intraday bar grid from its own session start, not from the hours the data provider trades. CAPITALCOM:US30 reopens at 17:05 New York after a five-minute pause, but its TradingView session starts at 17:00, so its 2-minute bars sit on even minutes; anchored to 17:05, PyneCore put them on odd minutes.
- New optional SymInfo / TOML field
session_anchors: TradingView's session start per trading day, with an optionalalignfor grids that start before the open (HKEX: open 09:30, grid 09:00). It replacessession_startsas the grid origin. - Without it the anchor is derived: the latest quarter hour at or before the session start with no trading in between (17:05 -> 17:00), otherwise the start itself. Measured on 29 symbols, it fixes Capital.com and changes no symbol that was already right.
- The aggregator,
Resampler,request.security(file-backed and live),time(tf),time_closeand the daily-bar stamps use the resolved anchor. A bar's close follows the sessions actually trading in its bucket: lunch reopenings, reopenings after midnight, clipped opening slots and grid origins inside a session. timeframe.changeis derived from thetime(tf)change. The separate hour-rounding rule it used was wrong wherever the open is not on the hour (NASDAQ 09:30, NSE 09:15).- Checked against TradingView data:
CAPITALCOM:US301m -> 2m matches all 19,916 TradingView bars;request.securityandtimeframe.changematch on AAPL, HKEX and US30.
Live trading runs unattended
A quarantine over the bot's own trouble now ends by itself; only an external intervention (someone else changed a bot-owned order or position) waits for pyne broker resume. The engine never halts the process.
- Every entry block names its cause and ends when that cause ends. The resume command is logged only for an external intervention; an entry block logs its open causes and that it ends by itself.
- A plugin's manual-intervention report quarantines by kind and the run goes on.
- An unclassified write exception is treated as an unknown outcome: the dispatch parks, entries are blocked and nothing is sent blindly again.
- Storage failures no longer end the process: the journal is committed before a venue write, a failed follow-up write is owed and flushed later, and repeated failures quarantine entries.
- Defensive close retries are stored and survive a restart; spot inventory troubles are re-measured in-process instead of waiting for a restart.
- A process that lost the spot lease is fenced from every venue write without a persisted latch that would also stop its replacement.
Strategy statistics survive restarts
A live run used to start every restart from a fresh position, so strategy.netprofit, strategy.closedtrades and the other closed-trade statistics began at zero again. They are now stored in the broker store and restored before the script sees its first live bar, so a restarted run, or one whose store moved to another host, gives the same strategy.* values on every bar as one that never stopped.
- Stored in the same transaction as the binding book and the fill receipts, so a crash can neither lose nor double-count a trade.
- The closed-trade window keeps at most the last 9000 trades within the retention; the aggregates never shrink, and a late fee on a trade that left the window still lands exactly.
- Restored open trades keep their own entry price, time and commission; their bar indexes are remapped onto the new run's numbering.
- New
brokers.tomlsettingretention_days(default 180) sets the store retention. - The closed-trade count no longer stops at 9000 once the trade list is full.
Stop+limit entries are stop-limit orders
A Pine entry with both stop and limit is one stop-limit order: nothing can fill before the stop triggers, then it works as a LIMIT at the limit price. Live trading used to run it as an OCO (a resting LIMIT plus a stop that fired a MARKET), which could fill on a pullback before the trigger and above the limit after it.
- New
ExchangeCapabilities.stop_limit_order. On a venue without a native stop-limit, a software engine arms a persisted watch and sends nothing until the chart price crosses the stop, then sends the LIMIT. - On restart the warmup bars are shown to the armed watches, so a stop crossed while the bot was down still triggers. Watches left by the old OCO model are retired at startup and their LIMIT is cancelled.
- Modify and cancel follow the watch state: an armed watch changes or ends without a venue call.
- A venue reject that says the level was already crossed no longer drops the entry: a STOP goes out at market, a native stop-limit as a plain LIMIT, and a LIMIT at market only while a fresh quote is still on the limit's side, otherwise as a resting LIMIT.
Exits are bound per fill
The live engine keeps a per-fill entry binding book, the same way the backtest does: every exit is bound to the fills of its entry, and the book is stored and restored on restart.
- On one-way accounts a
from_entryexit targets the legs of its own entry (plus unattributed ones) and never falls back to a sibling leg; an entry-bound or defensive close targets its own leg instead of the oldest one. - Each one-way leg close has its own client order id, so the completion of one close no longer completes another on the same leg.
- A refused or rate-limited leg retirement is retried instead of ending the run, and an amend equal to the last confirmed one is not re-sent.
Execution evidence and fills
- Entries are held until their execution is proven: when a terminal order event carries no known executed quantity (
ExchangeOrder.filled_qty_known), no venue write goes out for that entry until a fill or a known-quantity event arrives, and the hold survives a restart. The engine recovers held executions from the newBrokerPlugin.fetch_order_executionwith backoff and books nothing from a contradicting record. - When the evidence never arrives but the strategy asked to close, the engine closes the venue-sized position with a close that cannot over-close or flip (
BrokerPlugin.supports_held_execution_close). - A reversal under another id waits while the opposite entry's execution is unresolved, then resizes from what was booked.
- Fill delivery receipts make fill booking idempotent across redelivery and restarts.
- Commissions arrive on their own fee channel and are booked idempotently, also when late, on a split trade or on the new side of a reversal; adopted trades keep their entry commission across a restart.
- On hedging accounts a resting reversal fill is netted against the opposite leg at fill time; an unidentifiable contended fill quarantines the run instead of being absorbed.
- A cancelled or rejected entry with executed quantity keeps its protection, and a landed cancel no longer tears an entry down while a fill for it is still queued.
- An unsettled restart retries the settle before the script runs and sends nothing from an unreconstructed book; an exit or entry placed again with other parameters is amended.
- New cancel outcome
FILLED_AND_CLOSEDfor an order that filled and whose position has since closed. - The software guard's trailing extreme survives a restart.
Broker plugin API
- New:
BrokerPlugin.fetch_order_execution(abstract),request_execution_hold,get_quote,bracket_matches,close_leg_executed,request_durable_intervention_quarantine,supports_held_execution_close;ExchangeCapabilities.stop_limit_orderandsized_leg_bracket;ExchangeOrder.filled_qty_known;PositionLeg.entry_idandvenue_qty;OrderDispositionUnknownError,JournalWriteError. - See
docs/development/broker-plugin-authoring.mdanddocs/cli/broker.md.
Data
- Float32 storage artifacts are cleaned in
OHLCVReader, per field and only within the stored value's noise, instead of in the run loop. In-memory and live provider bars, which never went through float32 storage, are no longer rounded, so their full-precision volume is kept. - The price clean-up takes its mintick from the data file's sibling
.toml; without a mintick prices are left as stored. restore_f32_priceis public inpynecore.core.ohlcv.- A flipped entry's mirrored stop and a loss-tick stop are snapped to the tick grid.
Breaking changes
brokers.toml: thehaltvalue ofon_unexpected_cancelandon_inventory_conflictis removed; a config that still sets it fails at startup with aValueError.- Broker plugins must implement
BrokerPlugin.fetch_order_execution. raise_if_halted,finalize_haltandDEGRADED_HALTare removed from the sync engine.stop_fired_marketon the entry intent is renamed totriggered_entry, andKIND_ENTRY_STOPtoKIND_ENTRY_TRIGGERED(same client-order-id character).ScriptRunnerno longer takeslossless_volume/lossless_prices, andderived_pricesis removed.- The broker store gets schema migrations 10–14 on first start.
- Intraday aggregation,
request.security,time(tf)andtimeframe.changecan place bars differently on symbols whose provider session start is not TradingView's (see the first section).