![]() |
algotradelib 0.0.0.9000
C++ header-only library for algorithmic trading
|
Runs one strategy: feeds it events, reconciles what it asks for, checks the risk limits, and sends through an executor. More...
#include <algotradelib/src/runner/runner.hpp>
Public Types | |
| using | Tag = BrokerTag |
| The broker tag (DryTag for a dry run). | |
| using | Context = runner::Context<BrokerTag, CapsType> |
| The context type handed to the strategy's handlers. | |
| using | Report = DryRunReport<BrokerTag> |
| What one feed returns. | |
Public Member Functions | |
| Runner (Strategy strategy={}, strategy::RiskLimits limits={}, std::size_t series_capacity=512, Executor executor={}) | |
| Constructs a runner. | |
| const Executor & | executor () const noexcept |
| Returns the executor. | |
| Executor & | executor () noexcept |
| Returns the executor. | |
| const IndeterminacyLedger & | ledger () const noexcept |
| Returns the ledger of instruments withheld pending reconciliation or an operator: an order of unknown outcome, which a sweep of the broker's lists can resolve, or one that timed out unconfirmed or is held for an operator, which no listing clears (account for it with release_obligations, and clear the ledger entry yourself once the broker's state is read). | |
| IndeterminacyLedger & | ledger () noexcept |
| Returns the ledger, so an operator who has read the broker's order list can clear an entry. | |
| std::optional< std::string > | local_failure () const |
| Returns why local machinery stopped sending, if it did. | |
| void | resume_after_local_failure () |
| Clears the local-failure hold, after an operator has fixed the cause. | |
| void | set_maximum_portfolio_age (std::optional< std::chrono::nanoseconds > age) |
| Sets how old the holdings may be before a reconciliation plan computed from them is held back (WithheldPlanReason::PORTFOLIO_STALE). | |
| void | set_observed_at (std::chrono::system_clock::time_point at) |
| Sets the current wall-clock instant, used to measure the age of holdings and price bands. | |
| std::chrono::system_clock::time_point | observed_at () const noexcept |
| Returns the instant last set by set_observed_at. | |
| void | allow_absent_portfolio () |
| Lets this runner place orders before holdings have ever been read. | |
| void | require_known_portfolio (bool required) |
| Sets whether placing requires holdings to have been read and fresh. | |
| void | halt_locally (std::string detail) |
| Stops this runner sending, with the LOCAL_FAILURE hold, until resume_after_local_failure. | |
| std::size_t | placements_at_broker () const noexcept |
| Returns how many placements may have left an order at the broker (accepted or of unknown outcome). | |
| std::size_t | sends_outside_permitted_phase () const noexcept |
| Returns how many orders were sent in a market phase RiskLimits::permitted_phases_ does not permit, because they close toward flat. | |
| void | probe_sellable_convention (bool enabled=true) |
| Turns on the strategy::SellableConventionProbe, which infers whether the broker's sellable figure already excludes resting sells. | |
| void | observe_sellable_convention () |
| Shows the current portfolio to the sellable-convention probe, if it is on. | |
| const strategy::SellableConventionProbe< Tag > & | sellable_convention () const noexcept |
| Returns the sellable-convention probe. | |
| const Strategy & | strategy () const noexcept |
| Returns the strategy, to read the state it kept. | |
| Strategy & | strategy () noexcept |
| Returns the strategy. | |
| const Context & | context () const noexcept |
| Returns the context. | |
| Context & | context () noexcept |
| Returns the context, to arrange its state (instruments, portfolio) before feeding events. | |
| const strategy::RiskGuard & | guard () const noexcept |
| Returns the risk guard. | |
| strategy::RiskGuard & | guard () noexcept |
| Returns the risk guard, to halt or resume trading. | |
| void | set_price_limits (const InstrumentId &id, PriceLimits limits) |
| Records an instrument's price band for today, used to clamp order prices. | |
| void | set_maximum_price_limits_age (std::optional< std::chrono::nanoseconds > age) |
| Sets how old a price band may be and still be applied to an order's price. | |
| void | allow_unbounded_price_limits_age () |
| Applies price bands of any age (replacing a stated maximum). | |
| std::size_t | price_bands_withheld () const noexcept |
| Returns how many plans were built while a band was known for the instrument but not applied (counted per plan, not per order). | |
| bool | price_limits_age_policy_stated () const noexcept |
| Tests whether a price-band age policy has been stated (a maximum, or any age). | |
| std::size_t | unclamped_orders_rejected () const noexcept |
| Returns how many sent orders the broker refused while carrying a price a withheld band would have clamped. | |
| std::size_t | unclamped_orders_refused () const noexcept |
| Returns how many orders carrying a price a withheld band would have clamped were refused before sending (by the risk guard or the binding; not counting UNAVAILABLE). | |
| std::size_t | orders_unbuildable () const noexcept |
| Returns how many orders reconciliation could not build (any strategy::RejectReason before sending, including a quantity that rounded to zero). | |
| std::size_t | orders_reconcile_withheld () const noexcept |
| Returns how many orders were held back because the instrument was in the ledger (an order of unknown outcome, timed out unconfirmed, or held for an operator); see orders_unbuildable. | |
| std::size_t | orders_guard_refused () const noexcept |
| Returns how many orders the risk guard refused, for a limit or a hold; see orders_unbuildable. | |
| std::size_t | orders_binding_refused () const noexcept |
| Returns how many orders the binding refused to send (no request made); see orders_unbuildable. | |
| std::size_t | orders_broker_refused () const noexcept |
| Returns how many orders the broker refused (SendOutcome::REJECTED; a request was spent); see last_broker_refusal. At KIS, Toss and Kiwoom most refusals count as unknown outcomes instead. | |
| std::size_t | orders_indeterminate () const noexcept |
| Returns how many orders had an unknown outcome (SendOutcome::INDETERMINATE, which at KIS, Toss and Kiwoom includes most of the broker's own refusals). | |
| std::size_t | plans_withheld () const noexcept |
| Returns how many whole reconciliation plans were held back (any WithheldPlanReason: holdings absent, stale or superseded, or a placement hold); the reasons are in each Report::withheld_plans_. | |
| std::vector< strategy::TargetPosition > | deferred_targets () const |
| Returns the targets waiting for a stop on their instrument to be cancelled (at most one per instrument). | |
| std::size_t | targets_deferred () const noexcept |
| Returns how many targets have waited for a stop's cancellation; see deferred_targets. | |
| std::size_t | deferred_dropped_after_fill () const noexcept |
| Returns how many waiting targets were dropped because a stop they waited on had filled. | |
| std::optional< std::chrono::system_clock::time_point > | deferred_awaiting_evidence () const |
| Returns from when the broker's order history must be read to decide waiting targets. | |
| Report | retry_deferred (const std::vector< OrderSnapshot > &evidence) |
| Decides each waiting target against the broker's order history, and settles what it released. | |
| std::size_t | unconfirmed_orders () const noexcept |
| Returns how many sent orders are still counted as reserved until the broker accounts for them. | |
| void | refresh_unconfirmed () |
| Rebuilds the reserved working rows against the portfolio as it is now. | |
| void | resolve_indeterminate_placement (const InstrumentId &instrument, OrderSide side, const std::optional< std::string > &order_id, const std::string &journal_id={}) |
| Tells the runner what a reconciliation sweep found for an order of unknown outcome. | |
| bool | serialized () const noexcept |
| Tests whether this runner is serialized: at most one order per instrument that holdings have not yet accounted for. | |
| void | allow_overlapping_orders () |
| Lets several orders on one instrument be outstanding at once, as an unjournaled runner does, with that runner's known limitations. | |
| ObligationState | obligation_state (const InstrumentId &instrument) const |
| Returns what a serialized runner still owes on an instrument. | |
| std::vector< Obligation > | obligations (const InstrumentId &instrument) const |
| Lists the orders a serialized runner still owes on an instrument, for an operator. | |
| std::vector< Obligation > | obligations () const |
| Lists every order a serialized runner still owes, on any instrument. | |
| bool | release_obligations (const InstrumentId &instrument, const std::string &reason) |
| Accounts for every order a serialized runner still owes on an instrument, on an operator's word. | |
| void | restore_obligations (const JournalReplay &replay) |
| Restores the orders a previous process left unaccounted for; runner::recover_runner calls it, and a serialized runner places nothing until it has run. | |
| std::size_t | orders_awaiting_confirmation () const noexcept |
| Returns how many orders a serialized runner withheld because another order on the instrument was not yet accounted for, or the runner could not yet measure one; see serialized. Whole plans withheld for it are in plans_withheld. | |
| std::size_t | obligations_unexplained () const noexcept |
| Returns how many orders a serialized runner owes that nothing yet explains: no listing shows them resting and holdings do not show them, or only an operator may account for them. | |
| void | set_confirmation_timeout (std::chrono::nanoseconds timeout) |
| Sets how long a sent order's quantity may stay unexplained before it is counted as timed out (ten minutes by default). | |
| std::size_t | orders_unconfirmed_timed_out () const noexcept |
| Returns how many sent orders timed out unconfirmed; see set_confirmation_timeout. | |
| std::optional< std::chrono::system_clock::time_point > | unconfirmed_awaiting_evidence () |
| Returns from when the broker's order history must be read to settle sent orders. | |
| void | confirm_from_history (const std::vector< OrderSnapshot > &evidence) |
| Settles reserved orders against the broker's order history; sends nothing. | |
| Report | retry_retained_targets () |
| Re-submits retained targets and kept intents once they can be acted on, and settles them. | |
| std::size_t | intents_kept_for_phase () const noexcept |
| Returns how many order intents are kept for the market phase, an unreachable broker or a rate limit; see retry_retained_targets. | |
| std::size_t | kept_intents_dropped () const noexcept |
| Returns how many kept intents were dropped at release, because the holding they were decided against had changed or a stop now rests. | |
| std::size_t | targets_retained () const noexcept |
| Returns how many targets are retained, for any reason; see retry_retained_targets. | |
| std::size_t | targets_retained_for_phase () const noexcept |
| Returns how many retained targets wait for the market phase, an unreachable broker or a rate limit. | |
| void | clear_retained_targets () noexcept |
| Discards every retained target and kept intent (PollingLoop does this when stopping). | |
| void | clear_deferred_targets () noexcept |
| Discards every target waiting on a resting stop (deferred_targets). The orders this runner owes are not touched. PollingLoop does this when stopping: nothing a strategy stated before a stop is to be released after it. | |
| std::size_t | obligations_awaiting_account () const noexcept |
| Returns how many orders a serialized runner owes that a later read could account for without anything more being sent: not held for an operator, and either no longer listed (filled or gone, awaiting holdings or history) or withdrawn with the withdrawal accepted. | |
| bool | withdrawal_accepted_for (const WorkingOrder< Tag > &working) const |
| Tests whether working is a row of an order this runner sent whose withdrawal the broker has already accepted. Such an order is not withdrawn again: a second withdrawal is refused. | |
| Report | retry_deferred_on_one_snapshot () |
| Releases and settles every waiting target whose stops are no longer listed, without reading history. | |
| std::size_t | instructions_unavailable () const noexcept |
| Returns how many instructions (placements and cancellations) were not sent because local machinery was unavailable; each leaves the LOCAL_FAILURE hold. | |
| std::size_t | cancels_rejected () const noexcept |
| Returns how many cancellations were refused, by the broker or the binding (RejectedCancel::by_broker_ tells which). | |
| std::size_t | cancels_refused () const noexcept |
| Returns how many cancellations a hold refused before sending. | |
| std::size_t | cancels_unresolved () const noexcept |
| Returns how many cancellations named an order the portfolio does not list. | |
| std::size_t | cancels_indeterminate () const noexcept |
| Returns how many cancellations had an unknown outcome (the order may or may not have been cancelled). | |
| const std::optional< BrokerRefusal > & | last_broker_refusal () const noexcept |
| Returns the broker's code and message for the most recent order it refused (SendOutcome::REJECTED; at KIS, Toss and Kiwoom most refusals are INDETERMINATE and not recorded here). | |
| const std::optional< strategy::Rejection > & | last_unbuildable () const noexcept |
| Returns why reconciliation could not build the most recent instruction it refused. | |
| void | set_trade_tolerance (strategy::TradeTolerance tolerance) |
| Sets how small a drift from a target is not worth an order; see strategy::TradeTolerance. | |
| void | set_minimum_trade (Decimal64 quantity) |
| Sets only the share-count floor of the trade tolerance. | |
| void | set_portfolio_value (Decimal64 value) |
| Sets the portfolio's total value, which a weight-sized intent needs live. | |
| void | set_portfolio_value (Money value) |
| Sets the portfolio's total value and its currency. | |
| void | clear_portfolio_value () noexcept |
| Forgets the portfolio value, so weighted intents are refused again. | |
| Report | start () |
| Calls on_start and settles what it asked for. | |
| Report | stop () |
| Calls on_stop and settles what it asked for. | |
| Report | notify_stop () |
| Calls on_stop and settles what it asked for while PollingLoop's STOPPING hold stands, so the strategy's parting orders are refused rather than sent beside the operator's closing orders. | |
| Report | settle_closing () |
| Settles instructions already queued on the context, without calling a handler. | |
| Report | feed (const strategy::BarEvent &event) |
| Feeds one bar: caches it, sets the last price and the clock to the bar's period end, calls on_bar, and settles what the strategy asked for. | |
| void | feed_warmup (const strategy::BarEvent &event) |
| Feeds one bar as history: like feed, but whatever the strategy asks for is discarded (counted in warmup_instructions_discarded). | |
| void | record (const strategy::BarEvent &event) |
| Prepares one bar for a slice: caches it (with a linear algebra backend) and sets the last price and the clock to the bar's period end, without calling a handler or settling. | |
| void | record_history_only (const strategy::BarEvent &event) |
| Caches one bar without moving the last price or the clock, and without calling a handler. | |
| Report | feed (const strategy::BarSlice &slice) |
| Delivers one period's bars to on_bars and settles what the strategy asked for. | |
| void | feed_warmup (const strategy::BarSlice &slice) |
| Delivers one period's bars as history: like feed(const strategy::BarSlice&), but whatever the strategy asks for is discarded (counted in warmup_instructions_discarded). | |
| std::size_t | warmup_instructions_discarded () const noexcept |
| Returns how many instructions feed_warmup discarded. | |
| Report | feed (const strategy::QuoteEvent &event) |
| Feeds one quote: sets the last price and the clock, calls on_quote, and settles. | |
| Report | feed (const strategy::Fill &event) |
| Feeds one execution: calls on_fill and settles. | |
| Report | feed (const OrderSnapshot &event) |
| Feeds one order update: calls on_order_update and settles. | |
| Report | feed (strategy::MarketPhase phase) |
| Feeds a market phase change: sets it on the context, calls on_phase, and settles. | |
Static Public Attributes | |
| static constexpr bool | on_fill_never_fires |
| true when this runner sends to a broker and the strategy defines on_fill, which then never fires (no shipped live source produces fills). | |
| static constexpr bool | takes_bar_slices = strategy::strategy_detail::declares_on_bars<Strategy> |
| true when the strategy declares on_bars: bars are then fed with record and delivered with feed(const strategy::BarSlice&) (or feed_warmup of one), and the single-bar feed and feed_warmup do not compile. | |
| static constexpr bool | keeps_sent_orders_until_listed |
| true when this runner keeps each order it sends in Portfolio::working_ until a broker listing accounts for it: a live runner whose broker lists working orders (every shipped binding). | |
| static constexpr bool | journals_to_a_broker |
| true when this runner journals what it sends to a broker (a JournalingExecutor), which makes it serialized unless allow_overlapping_orders is called; see serialized. | |
Runs one strategy: feeds it events, reconciles what it asks for, checks the risk limits, and sends through an executor.
The same class serves a dry run (the default RecordingExecutor, which sends nothing), a live session (live::SessionExecutor) and a backtest (backtest::QueueingExecutor). Feed events with feed; each call runs the matching handler and returns a DryRunReport of what it decided. A live program usually drives it through runner::PollingLoop.
A dry-run program contains no broker or network code: this header includes none.
| Strategy | The strategy type, held by value (read its state with strategy()). |
| CapsType | The broker capabilities the strategy sees. |
| BrokerTag | The broker tag of order references. |
| Executor | Where instructions are sent. |
Definition at line 297 of file runner.hpp.
| using algotradelib::runner::Runner< Strategy, CapsType, BrokerTag, Executor >::Context = runner::Context<BrokerTag, CapsType> |
The context type handed to the strategy's handlers.
Definition at line 302 of file runner.hpp.
| using algotradelib::runner::Runner< Strategy, CapsType, BrokerTag, Executor >::Report = DryRunReport<BrokerTag> |
What one feed returns.
Definition at line 304 of file runner.hpp.
| using algotradelib::runner::Runner< Strategy, CapsType, BrokerTag, Executor >::Tag = BrokerTag |
The broker tag (DryTag for a dry run).
Definition at line 300 of file runner.hpp.
|
inlineexplicit |
Constructs a runner.
| strategy | The strategy. |
| limits | The risk limits. |
| series_capacity | How many trailing bars each cached series keeps; must be positive with a linear algebra backend, or the first bar fed throws std::invalid_argument. |
| executor | Where instructions are sent. |
Definition at line 351 of file runner.hpp.
|
inline |
Lets this runner place orders before holdings have ever been read.
PollingLoop::allow_absent_portfolio calls it. A plan that would cancel something is still held back until holdings are read.
Definition at line 450 of file runner.hpp.
|
inline |
Lets several orders on one instrument be outstanding at once, as an unjournaled runner does, with that runner's known limitations.
After a restart, orders a previous process sent and holdings had not yet shown are forgotten, and a target can place them again. A buy and a sell on one instrument whose fills have not reached holdings can both be taken as accounted for, and a later order confirmed by another's fill. Choose it only for a strategy that needs overlapping orders (an entry beside its protective stop) and accepts those.
| std::logic_error | once anything was placed, or after runner::recover_runner. |
Definition at line 898 of file runner.hpp.
|
inline |
Applies price bands of any age (replacing a stated maximum).
Definition at line 604 of file runner.hpp.
|
inlinenoexcept |
Returns how many cancellations had an unknown outcome (the order may or may not have been cancelled).
Definition at line 1394 of file runner.hpp.
|
inlinenoexcept |
Returns how many cancellations a hold refused before sending.
Definition at line 1384 of file runner.hpp.
|
inlinenoexcept |
Returns how many cancellations were refused, by the broker or the binding (RejectedCancel::by_broker_ tells which).
Definition at line 1379 of file runner.hpp.
|
inlinenoexcept |
Returns how many cancellations named an order the portfolio does not list.
Definition at line 1389 of file runner.hpp.
|
inlinenoexcept |
Discards every target waiting on a resting stop (deferred_targets). The orders this runner owes are not touched. PollingLoop does this when stopping: nothing a strategy stated before a stop is to be released after it.
Definition at line 1314 of file runner.hpp.
|
inlinenoexcept |
Forgets the portfolio value, so weighted intents are refused again.
Definition at line 1466 of file runner.hpp.
|
inlinenoexcept |
Discards every retained target and kept intent (PollingLoop does this when stopping).
Definition at line 1304 of file runner.hpp.
|
inline |
Settles reserved orders against the broker's order history; sends nothing.
A terminal row for an order caps the quantity holdings must still show at its filled quantity; an order that ended with nothing filled is forgotten at once. After the runner has seen the phase CLOSED or POST_CLOSE since the order was sent, an open row of a DAY order counts as terminal (its filled quantity is final); not for a serialized runner, whose rules are under serialized. An order the history settled, or had no answer for after the timeout, withholds its instrument (orders_unconfirmed_timed_out) if a holdings read a timeout later still does not show it; see set_confirmation_timeout.
| evidence | History rows covering the instants unconfirmed_awaiting_evidence asked for. |
Definition at line 1118 of file runner.hpp.
|
inlinenoexcept |
Returns the context.
Definition at line 543 of file runner.hpp.
Referenced by algotradelib::runner::ManualSource< Runner >::poll().
|
inlinenoexcept |
Returns the context, to arrange its state (instruments, portfolio) before feeding events.
Definition at line 548 of file runner.hpp.
|
inline |
Returns from when the broker's order history must be read to decide waiting targets.
Definition at line 737 of file runner.hpp.
|
inlinenoexcept |
Returns how many waiting targets were dropped because a stop they waited on had filled.
Definition at line 730 of file runner.hpp.
|
inline |
Returns the targets waiting for a stop on their instrument to be cancelled (at most one per instrument).
A target that needs a trade while a stop rests cancels the stop and waits (strategy::RejectReason::STOP_ORDER_RESTING); the runner keeps it so it is not lost when no strategy callback follows. It is:
Not journalled: a restart loses it.
Definition at line 711 of file runner.hpp.
|
inlinenoexcept |
|
inlinenoexcept |
|
inline |
Feeds one order update: calls on_order_update and settles.
| event | The order's new state. |
Definition at line 1666 of file runner.hpp.
|
inline |
Feeds one bar: caches it, sets the last price and the clock to the bar's period end, calls on_bar, and settles what the strategy asked for.
Does not compile for a strategy declaring on_bars (takes_bar_slices): use record and feed(const strategy::BarSlice&).
| event | The bar. |
| std::invalid_argument | (with a linear algebra backend) if the bar is not later than the cached series' newest bar. |
Definition at line 1524 of file runner.hpp.
|
inline |
Delivers one period's bars to on_bars and settles what the strategy asked for.
Every bar in the slice must have been passed to record first; nothing here caches, prices or clocks. on_bars then sees ctx.bars(id, slice.interval_) end at the slice's period for every instrument in it.
| slice | The period's bars. |
Definition at line 1611 of file runner.hpp.
|
inline |
Feeds one execution: calls on_fill and settles.
| event | The fill. |
Definition at line 1655 of file runner.hpp.
|
inline |
Feeds one quote: sets the last price and the clock, calls on_quote, and settles.
| event | The quote. |
Definition at line 1642 of file runner.hpp.
|
inline |
Feeds a market phase change: sets it on the context, calls on_phase, and settles.
| phase | The new phase. |
Definition at line 1677 of file runner.hpp.
|
inline |
Feeds one bar as history: like feed, but whatever the strategy asks for is discarded (counted in warmup_instructions_discarded).
Use it for every bar older than the newest one, so a restart or a backlog does not act on an old signal at today's price. A source of your own should feed a read's new bars in period-end order across instruments, and feed live (with feed) only each instrument's newest closed bar, and only if its period ended strictly after every bar fed as history from the same read, across instruments. A newest bar that ties or trails one (a suspended name, or one a bar behind) is history too, or an order could be decided on a stale cross-section at today's price.
Does not compile for a strategy declaring on_bars: use record and feed_warmup(const strategy::BarSlice&).
| event | The bar. |
| std::invalid_argument | (with a linear algebra backend) if the bar is not later than the cached series' newest bar. |
Definition at line 1553 of file runner.hpp.
|
inline |
Delivers one period's bars as history: like feed(const strategy::BarSlice&), but whatever the strategy asks for is discarded (counted in warmup_instructions_discarded).
Every bar in the slice must have been passed to record first. See feed_warmup(const strategy::BarEvent&) for which bars are history.
| slice | The period's bars. |
Definition at line 1626 of file runner.hpp.
|
inlinenoexcept |
|
inlinenoexcept |
Returns the risk guard, to halt or resume trading.
Definition at line 559 of file runner.hpp.
|
inline |
Stops this runner sending, with the LOCAL_FAILURE hold, until resume_after_local_failure.
Used, for example, by recovery when a damaged journal shows something was in flight but not what.
| detail | Why, for the operator. |
Definition at line 472 of file runner.hpp.
Referenced by algotradelib::runner::recover_runner().
|
inlinenoexcept |
Returns how many instructions (placements and cancellations) were not sent because local machinery was unavailable; each leaves the LOCAL_FAILURE hold.
Definition at line 1373 of file runner.hpp.
|
inlinenoexcept |
Returns how many order intents are kept for the market phase, an unreachable broker or a rate limit; see retry_retained_targets.
Definition at line 1276 of file runner.hpp.
|
inlinenoexcept |
Returns how many kept intents were dropped at release, because the holding they were decided against had changed or a stop now rests.
Definition at line 1283 of file runner.hpp.
|
inlinenoexcept |
Returns the broker's code and message for the most recent order it refused (SendOutcome::REJECTED; at KIS, Toss and Kiwoom most refusals are INDETERMINATE and not recorded here).
Definition at line 1404 of file runner.hpp.
|
inlinenoexcept |
Returns why reconciliation could not build the most recent instruction it refused.
For example, a live weight-sized intent is refused NO_PORTFOLIO_VALUE on every pass unless set_portfolio_value was called.
Definition at line 1416 of file runner.hpp.
|
inlinenoexcept |
Returns the ledger of instruments withheld pending reconciliation or an operator: an order of unknown outcome, which a sweep of the broker's lists can resolve, or one that timed out unconfirmed or is held for an operator, which no listing clears (account for it with release_obligations, and clear the ledger entry yourself once the broker's state is read).
Definition at line 380 of file runner.hpp.
Referenced by algotradelib::runner::recover_runner().
|
inlinenoexcept |
Returns the ledger, so an operator who has read the broker's order list can clear an entry.
Definition at line 385 of file runner.hpp.
|
inline |
Returns why local machinery stopped sending, if it did.
The hold (strategy::HaltReason::LOCAL_FAILURE) stays until resume_after_local_failure (or a direct guard().resume), even if the failure was transient. The detail is the first failure recorded through this runner.
Definition at line 395 of file runner.hpp.
|
inline |
Calls on_stop and settles what it asked for while PollingLoop's STOPPING hold stands, so the strategy's parting orders are refused rather than sent beside the operator's closing orders.
Definition at line 1498 of file runner.hpp.
|
inline |
Returns what a serialized runner still owes on an instrument.
| instrument | The instrument. |
Definition at line 911 of file runner.hpp.
|
inline |
Lists every order a serialized runner still owes, on any instrument.
Definition at line 946 of file runner.hpp.
|
inline |
Lists the orders a serialized runner still owes on an instrument, for an operator.
| instrument | The instrument. |
Definition at line 933 of file runner.hpp.
|
inlinenoexcept |
Returns how many orders a serialized runner owes that a later read could account for without anything more being sent: not held for an operator, and either no longer listed (filled or gone, awaiting holdings or history) or withdrawn with the withdrawal accepted.
An order that is simply resting is not counted: only a withdrawal changes that. PollingLoop reads this to decide whether a stop that closes should read again before its pass.
Definition at line 1326 of file runner.hpp.
|
inlinenoexcept |
Returns how many orders a serialized runner owes that nothing yet explains: no listing shows them resting and holdings do not show them, or only an operator may account for them.
PollingLoop counts these as a closing pass begins and reports them, since the pass cannot see them.
Definition at line 1043 of file runner.hpp.
|
inline |
Shows the current portfolio to the sellable-convention probe, if it is on.
Called on every pass and by PollingLoop after it polls. Skipped while the working-order listing is newer than the holdings.
Definition at line 511 of file runner.hpp.
|
inlinenoexcept |
Returns the instant last set by set_observed_at.
Definition at line 442 of file runner.hpp.
|
inlinenoexcept |
Returns how many orders a serialized runner withheld because another order on the instrument was not yet accounted for, or the runner could not yet measure one; see serialized. Whole plans withheld for it are in plans_withheld.
Definition at line 1033 of file runner.hpp.
|
inlinenoexcept |
Returns how many orders the binding refused to send (no request made); see orders_unbuildable.
Definition at line 670 of file runner.hpp.
|
inlinenoexcept |
Returns how many orders the broker refused (SendOutcome::REJECTED; a request was spent); see last_broker_refusal. At KIS, Toss and Kiwoom most refusals count as unknown outcomes instead.
Definition at line 677 of file runner.hpp.
|
inlinenoexcept |
Returns how many orders the risk guard refused, for a limit or a hold; see orders_unbuildable.
Definition at line 665 of file runner.hpp.
|
inlinenoexcept |
Returns how many orders had an unknown outcome (SendOutcome::INDETERMINATE, which at KIS, Toss and Kiwoom includes most of the broker's own refusals).
Definition at line 683 of file runner.hpp.
|
inlinenoexcept |
Returns how many orders were held back because the instrument was in the ledger (an order of unknown outcome, timed out unconfirmed, or held for an operator); see orders_unbuildable.
Definition at line 660 of file runner.hpp.
|
inlinenoexcept |
Returns how many orders reconciliation could not build (any strategy::RejectReason before sending, including a quantity that rounded to zero).
One of eight counters of what became of placements: orders_unbuildable, orders_reconcile_withheld, orders_awaiting_confirmation, orders_guard_refused, orders_binding_refused, orders_broker_refused, orders_indeterminate and instructions_unavailable (which counts cancellations too). All count over the runner's life, so a loop differences them; the per-instruction reasons are in each pass's Report. See also last_unbuildable.
Definition at line 654 of file runner.hpp.
|
inlinenoexcept |
Returns how many sent orders timed out unconfirmed; see set_confirmation_timeout.
Definition at line 1073 of file runner.hpp.
|
inlinenoexcept |
Returns how many placements may have left an order at the broker (accepted or of unknown outcome).
Definition at line 478 of file runner.hpp.
|
inlinenoexcept |
Returns how many whole reconciliation plans were held back (any WithheldPlanReason: holdings absent, stale or superseded, or a placement hold); the reasons are in each Report::withheld_plans_.
Definition at line 691 of file runner.hpp.
|
inlinenoexcept |
Returns how many plans were built while a band was known for the instrument but not applied (counted per plan, not per order).
Definition at line 613 of file runner.hpp.
|
inlinenoexcept |
Tests whether a price-band age policy has been stated (a maximum, or any age).
Definition at line 619 of file runner.hpp.
|
inline |
Turns on the strategy::SellableConventionProbe, which infers whether the broker's sellable figure already excludes resting sells.
Off by default. It only observes; it sends and requests nothing extra. Read the answer from sellable_convention().
| enabled | Whether to probe. |
Definition at line 503 of file runner.hpp.
|
inline |
Prepares one bar for a slice: caches it (with a linear algebra backend) and sets the last price and the clock to the bar's period end, without calling a handler or settling.
For a strategy declaring on_bars, a source records every bar of a period, then delivers the period with feed(const strategy::BarSlice&).
| event | The bar. |
| std::invalid_argument | (with a linear algebra backend) if the bar is not later than the cached series' newest bar. |
Definition at line 1574 of file runner.hpp.
|
inline |
Caches one bar without moving the last price or the clock, and without calling a handler.
For a bar that arrives after its period was already delivered: its own series stays complete, while a newer price or a later clock is not overwritten by an older bar. Does nothing without a linear algebra backend.
| event | The bar. |
| std::invalid_argument | (with a linear algebra backend) if the bar is not later than the cached series' newest bar. |
Definition at line 1593 of file runner.hpp.
|
inline |
Rebuilds the reserved working rows against the portfolio as it is now.
Every pass does this first; call it before reading working_ outside a pass.
Definition at line 791 of file runner.hpp.
|
inline |
Accounts for every order a serialized runner still owes on an instrument, on an operator's word.
For an order held for an operator, one whose reply was lost and no sweep named, one from an older journal, or one whose holdings never arrived: read the broker's order list and holdings first. Each order gets a JournalOutcome::CONFIRMED line naming reason and is then forgotten; the next order on the instrument needs a holdings read received after this call. The indeterminacy ledger is left as it is. If a line cannot be written, that order is kept and the runner stops sending (HaltReason::LOCAL_FAILURE).
| instrument | The instrument. |
| reason | Why, for the journal. |
Definition at line 980 of file runner.hpp.
|
inline |
Sets whether placing requires holdings to have been read and fresh.
On by default for an executor that can reach a broker, off for a dry run or a replay. Off, a placement-only plan skips both the read and the age check. PollingLoop sets it each iteration. A plan that would cancel something is held back unless holdings have been read and are fresh, whatever this setting.
| required | Whether placing requires read holdings. |
Definition at line 462 of file runner.hpp.
|
inline |
Tells the runner what a reconciliation sweep found for an order of unknown outcome.
With an order id (found in the broker's listing), the order is tracked like an accepted one; without (it was never placed), it is forgotten with its reserved row. live::SessionSource calls this for each recorded MATCHED or NOT_PLACED placement; a source of your own, or an operator clearing the ledger by hand, should too, or the order's instrument is withheld again after the confirmation timeout.
A serialized runner names only the order whose journal line is journal_id, and forgets nothing (serialized).
| instrument | The instrument. |
| side | The order's side. |
| order_id | The broker's order id, or std::nullopt if the order was not placed. |
| journal_id | The id of the order's journal line; without it a serialized runner does nothing, and any other runner names its newest unnamed order on the instrument and side. |
Definition at line 811 of file runner.hpp.
|
inline |
Restores the orders a previous process left unaccounted for; runner::recover_runner calls it, and a serialized runner places nothing until it has run.
Every placement with no CONFIRMED or REJECTED line comes back, named by an ACCEPTED or RESOLVED line's order id or else unnamed, measured from the holding its lines recorded. One with no recorded holding (an overlapping or older journal), lines that disagree or were damaged, a HELD line, or another such order on its instrument, is held for an operator and marks the ledger. Each instrument's latest CONFIRMED line means only a holdings read received after it sizes the next order. Does nothing else for a runner that is not serialized.
| replay | The journal's contents. |
Definition at line 1017 of file runner.hpp.
Referenced by algotradelib::runner::recover_runner().
|
inline |
Clears the local-failure hold, after an operator has fixed the cause.
It also acknowledges the journal failures seen so far, so the same failure does not halt again. Other holds, such as an operator's halt, stay.
Definition at line 408 of file runner.hpp.
|
inline |
Decides each waiting target against the broker's order history, and settles what it released.
live::SessionSource calls it after a working-order poll. It calls no handler.
| evidence | History rows covering the instants deferred_awaiting_evidence asked for. |
Definition at line 759 of file runner.hpp.
|
inline |
Releases and settles every waiting target whose stops are no longer listed, without reading history.
Only for a replay, whose ledger is the broker: a stop it withdrew cannot have filled. A live caller uses retry_deferred.
Definition at line 1367 of file runner.hpp.
|
inline |
Re-submits retained targets and kept intents once they can be acted on, and settles them.
The runner keeps (rather than drops):
All but the first only in a runner that sends to a broker. A released target is planned under the limits then in force, and one the guard refuses for anything but the phase is not kept again. Not kept: anything decided under the STOPPING, OPERATOR or LOCAL_FAILURE hold; an intent with a client order id the broker answered; an intent whose instrument's net holding is unknown. So a protective stop with a client order id, refused out of hours, is not installed at the open by itself (one without an id is).
At release, a kept intent is dropped (kept_intents_dropped) if the instrument's holding changed since (except a TARGET_WEIGHT intent, which is planned again against the new holding), or if it carries a trigger and a stop now rests on the instrument.
Nothing is released while holdings were never read or predate the listing, or while any hold is in force. If this method runs while OPERATOR or LOCAL_FAILURE holds, it discards every kept intent and every target kept for the phase or the broker (targets kept for the account stay). Halting and resuming without calling it in between discards nothing, so the kept work can still go out after the resume; call clear_retained_targets to drop it. A later target or intent for the instrument replaces a retained one, one still queued on the context when this is called included. PollingLoop calls this once per iteration; a program driving a Runner itself must call it (or clear_retained_targets).
Definition at line 1197 of file runner.hpp.
|
inlinenoexcept |
Returns the sellable-convention probe.
Definition at line 524 of file runner.hpp.
|
inlinenoexcept |
Returns how many orders were sent in a market phase RiskLimits::permitted_phases_ does not permit, because they close toward flat.
Counts sends, including ones the broker then rejected (likely outside a session). Not by itself a fault: it shows a flatten after the close, or a strategy restating a close every pass (limit that with RiskLimits::max_orders_per_window_).
Definition at line 490 of file runner.hpp.
|
inlinenoexcept |
Tests whether this runner is serialized: at most one order per instrument that holdings have not yet accounted for.
On by default for a runner that journals what it sends to a broker (journals_to_a_broker: live::bind_journaled, or a JournalingExecutor of your own). In this mode:
It assumes this runner is the only one trading the account, that a holdings read received later shows no older content, and that the journal's clock and the holdings' as_of_ are one clock (as they are live; a simulated market must journal on its own clock). Orders placed any other way are outside it, as is an executor that drives this runner from inside its own place. A runner that journals to a broker but lacks what this needs (a broker that lists working orders, and an executor with last_entry, record and place(order, baseline), as JournalingExecutor has) places nothing until allow_overlapping_orders is called.
Definition at line 885 of file runner.hpp.
|
inline |
Sets how long a sent order's quantity may stay unexplained before it is counted as timed out (ten minutes by default).
When it passes, the broker's history is read once more; if that does not settle it, or holdings still do not show the filled quantity one more timeout later, the order is counted (orders_unconfirmed_timed_out). A runner that is not serialized then forgets it and marks the instrument in the indeterminacy ledger for an operator to clear, so too short a timeout costs trading on that instrument, never a duplicate order. A serialized runner keeps it owed, so the instrument trades again once evidence accounts for it; only an order never named marks the ledger, so an unattended run watches its obligations (obligations), not only the ledger. It needs a source that advances Portfolio::as_of_ on each holdings read.
| timeout | The timeout. |
Definition at line 1067 of file runner.hpp.
|
inline |
Sets how old the holdings may be before a reconciliation plan computed from them is held back (WithheldPlanReason::PORTFOLIO_STALE).
It applies to every plan that would cancel something, and to placement-only plans while require_known_portfolio is on. It takes no hold on the guard. Age is measured against the later of observed_at() and Context::now(). PollingLoop sets it from its own configuration.
| age | The maximum age, or std::nullopt for no limit. |
Definition at line 423 of file runner.hpp.
|
inline |
Sets how old a price band may be and still be applied to an order's price.
With no policy stated (the default), no band is applied; call allow_unbounded_price_limits_age to apply bands of any age.
A band not applied leaves the strategy's own price on the order, as if no band were known. That has costs: the exchange may reject a price outside today's real band that the clamp would have fixed (an exit below today's floor, say), or a local check (notional, buying power, exposure) may refuse a buy priced above the ceiling. unclamped_orders_rejected and unclamped_orders_refused count those; an order accepted at the raw price that never filled is not counted.
| age | The maximum age. std::nullopt withdraws the policy (so no band is applied); it does not mean "any age". |
Definition at line 597 of file runner.hpp.
|
inline |
Sets only the share-count floor of the trade tolerance.
Across instruments at different price levels, prefer a notional or fractional floor.
| quantity | The smallest drift worth trading, in shares. |
Definition at line 1435 of file runner.hpp.
|
inline |
Sets the current wall-clock instant, used to measure the age of holdings and price bands.
PollingLoop sets it each iteration. Without it, age is measured against Context::now(), which for a daily bar is its period end and understates age. The epoch (time_point{}) is reserved for "no reading": a clock of your own should not start there (ManualClock{} does; give it a start).
| at | The instant. |
Definition at line 436 of file runner.hpp.
|
inline |
Sets the portfolio's total value, which a weight-sized intent needs live.
Without it a weighted intent is refused (NO_PORTFOLIO_VALUE). The value is taken to be in each instrument's own currency; use the Money overload to state it.
| value | The total value. |
Definition at line 1447 of file runner.hpp.
|
inline |
Sets the portfolio's total value and its currency.
A weight on an instrument in another currency is then refused. The value is kept until replaced or cleared with clear_portfolio_value.
| value | The total value and currency. |
Definition at line 1460 of file runner.hpp.
|
inline |
Records an instrument's price band for today, used to clamp order prices.
The band is dated by the earlier of the exchange's timestamp, where the broker gave one (Toss, Kiwoom), and the instant last set with set_observed_at (the only date of a KIS band); a future exchange timestamp cannot make it fresher. A band recorded before any instant was set is dated at the epoch, so any realistic age limit rejects it. Its age is measured against the later of observed_at() and Context::now(); a band dated after that instant is never applied, whatever the policy. Whether a band is applied depends on set_maximum_price_limits_age.
| id | The instrument (bands are kept per full identity, venue included). |
| limits | The band. |
Definition at line 574 of file runner.hpp.
Referenced by algotradelib::runner::ManualSource< Runner >::poll().
|
inline |
Sets how small a drift from a target is not worth an order; see strategy::TradeTolerance.
| tolerance | The floors; all unset (the default) trades every share. |
Definition at line 1424 of file runner.hpp.
|
inline |
Settles instructions already queued on the context, without calling a handler.
PollingLoop queues its closing orders and settles them with this.
Definition at line 1510 of file runner.hpp.
|
inline |
Calls on_start and settles what it asked for.
Definition at line 1475 of file runner.hpp.
|
inline |
Calls on_stop and settles what it asked for.
For a caller driving a runner directly; PollingLoop uses notify_stop during a stop instead.
Definition at line 1487 of file runner.hpp.
|
inlinenoexcept |
Returns the strategy, to read the state it kept.
Definition at line 532 of file runner.hpp.
|
inlinenoexcept |
|
inlinenoexcept |
Returns how many targets have waited for a stop's cancellation; see deferred_targets.
Definition at line 724 of file runner.hpp.
|
inlinenoexcept |
Returns how many targets are retained, for any reason; see retry_retained_targets.
Definition at line 1289 of file runner.hpp.
|
inlinenoexcept |
Returns how many retained targets wait for the market phase, an unreachable broker or a rate limit.
Definition at line 1296 of file runner.hpp.
|
inlinenoexcept |
Returns how many orders carrying a price a withheld band would have clamped were refused before sending (by the risk guard or the binding; not counting UNAVAILABLE).
Definition at line 639 of file runner.hpp.
|
inlinenoexcept |
Returns how many sent orders the broker refused while carrying a price a withheld band would have clamped.
Co-occurrence, not proof that the band caused the refusal. Orders refused before sending are in unclamped_orders_refused.
Definition at line 632 of file runner.hpp.
|
inline |
Returns from when the broker's order history must be read to settle sent orders.
An order needs it when part of it is unexplained and either it passed the confirmation timeout (listed or not), or no listing carries it and it was listed before, its cancellation was accepted, or it was restored at startup. In a serialized runner, an order a sweep named and no dated row has confirmed always needs it. Excluded: an order the history already settled; one whose history had no answer after the timeout (until a later listing or holdings explain it again); an order held for an operator; in a serialized runner, an order with no name; and, overlapping, an order of unknown outcome with no reference while its instrument is in the ledger.
Definition at line 1088 of file runner.hpp.
|
inlinenoexcept |
Returns how many sent orders are still counted as reserved until the broker accounts for them.
A runner that keeps sent orders (keeps_sent_orders_until_listed) remembers each order the broker accepted with a reference, and each order of unknown outcome if its executor reports references (has last_ref(), as live::SessionExecutor does), provided holdings had been read and the instrument's net holding was known when it was sent. Before each pass it rebuilds a reserved working row from what neither holdings (moved in the order's direction since it was sent) nor a listing yet explains. An entry ends when holdings show the whole quantity, or the broker's history shows the order ended with less (confirm_from_history). This stops a target from ordering again while a fill has not reached the holdings yet.
An accepted order not tracked (no reference, or sent before holdings were read, as allow_absent_portfolio permits) has no such protection: its reservation lasts only until the next listing. An order of unknown outcome not tracked (an executor without last_ref()) gets no reservation at all once the ledger entry is resolved. Only orders sent in this process are tracked, and a restart starts with none, unless the runner is serialized (serialized).
Definition at line 784 of file runner.hpp.
|
inlinenoexcept |
Returns how many instructions feed_warmup discarded.
Definition at line 1635 of file runner.hpp.
|
inline |
Tests whether working is a row of an order this runner sent whose withdrawal the broker has already accepted. Such an order is not withdrawn again: a second withdrawal is refused.
Acceptance is of the request, not of its result: the order may still fill. The row has to be dated within an hour of the order's send: brokers reuse order numbers from day to day, and an undated row, or one of another day, is not known to be that order.
| working | A row of the portfolio's working orders. |
Definition at line 1346 of file runner.hpp.
|
staticconstexpr |
true when this runner journals what it sends to a broker (a JournalingExecutor), which makes it serialized unless allow_overlapping_orders is called; see serialized.
Definition at line 340 of file runner.hpp.
|
staticconstexpr |
true when this runner keeps each order it sends in Portfolio::working_ until a broker listing accounts for it: a live runner whose broker lists working orders (every shipped binding).
PollingLoop then requires the working-order poll (see PollSchedule::working_orders_).
Definition at line 333 of file runner.hpp.
|
staticconstexpr |
true when this runner sends to a broker and the strategy defines on_fill, which then never fires (no shipped live source produces fills).
Nothing is refused; PollingLoop puts a note in its report. A program that feeds Fill events itself does reach on_fill.
Definition at line 315 of file runner.hpp.
|
staticconstexpr |
true when the strategy declares on_bars: bars are then fed with record and delivered with feed(const strategy::BarSlice&) (or feed_warmup of one), and the single-bar feed and feed_warmup do not compile.
Definition at line 324 of file runner.hpp.