![]() |
algotradelib 0.0.0.9000
C++ header-only library for algorithmic trading
|
What a whole PollingLoop::run did, and why it ended. More...
#include <algotradelib/src/runner/loop.hpp>
Public Member Functions | |
| bool | closing_complete () const noexcept |
| Tests whether every closing instruction the loop asked for was accepted, and the loop knew what to ask for. | |
| std::size_t | attempted (PollKind kind) const noexcept |
| Returns how many polls of a kind were attempted. | |
| std::size_t | failed (PollKind kind) const noexcept |
| Returns how many polls of a kind failed. | |
Public Attributes | |
| std::size_t | iterations_ {0} |
| How many iterations ran. | |
| ChargedCosts | charged_costs_ |
| Commission and tax the broker stated on the orders this run saw; a subtotal (see ChargedCosts). | |
| std::size_t | attempted_ [poll_kind_count] = {} |
| How many polls of each kind were attempted, indexed by PollKind; see attempted(). | |
| std::size_t | failed_ [poll_kind_count] = {} |
| How many polls of each kind failed; see failed(). | |
| std::size_t | blocked_ {0} |
| How many iterations were blocked from placing (a named cancellation may still have gone). | |
| std::optional< StopIntent > | stopped_by_ |
| The stop intent that ended the run, if one did. | |
| std::optional< strategy::HaltReason > | final_gate_ |
| The most fundamental hold in force when the run ended, whoever took it. | |
| strategy::MarketPhase | final_phase_ {strategy::MarketPhase::UNKNOWN} |
| The phase the last iteration computed. | |
| std::size_t | sends_under_a_revised_phase_ {0} |
| How many calls into a source or strategy both sent something and left the market phase changed. | |
| std::size_t | price_bands_withheld_ {0} |
| Plans built while a known price band was not applied (no age policy, too old, or dated after the clock); see Runner::price_bands_withheld. | |
| std::size_t | unclamped_orders_rejected_ {0} |
| Sent orders the broker refused while carrying a price a withheld band would have clamped; see Runner::unclamped_orders_rejected. | |
| std::size_t | unclamped_orders_refused_ {0} |
| Orders refused before sending while carrying such a price; see Runner::unclamped_orders_refused. | |
| std::size_t | orders_unbuildable_ {0} |
| Orders reconciliation could not build during this run's polling; see Runner::orders_unbuildable. | |
| std::size_t | orders_reconcile_withheld_ {0} |
| Orders held back for an instrument of unknown order state; see Runner::orders_reconcile_withheld. | |
| std::size_t | orders_guard_refused_ {0} |
| Orders the risk guard refused; see Runner::orders_guard_refused. | |
| std::size_t | orders_binding_refused_ {0} |
| Orders the binding refused to send; see Runner::orders_binding_refused. | |
| std::size_t | orders_broker_refused_ {0} |
| Orders the broker refused (SendOutcome::REJECTED); see last_broker_refusal_. At KIS, Toss and Kiwoom most refusals arrive as unknown outcomes and are counted in orders_indeterminate_. | |
| std::size_t | orders_indeterminate_ {0} |
| Orders with an unknown outcome (SendOutcome::INDETERMINATE, including most KIS, Toss and Kiwoom refusals). | |
| std::size_t | orders_unconfirmed_timed_out_ {0} |
| Sent orders that timed out unconfirmed; see Runner::set_confirmation_timeout for what each mode then withholds. Counted in the run that noticed it, not while it stays owed (Runner::obligations); a named serialized order counted here marks no ledger. | |
| std::size_t | plans_withheld_ {0} |
| Whole plans held back (any WithheldPlanReason); see Runner::plans_withheld. | |
| std::size_t | instructions_unavailable_ {0} |
| Instructions not sent because local machinery was unavailable; see Runner::instructions_unavailable. | |
| std::size_t | cancels_rejected_ {0} |
| Cancellations refused by the broker or binding; see Runner::cancels_rejected. | |
| std::size_t | cancels_refused_ {0} |
| Cancellations a hold refused. | |
| std::size_t | cancels_unresolved_ {0} |
| Cancellations naming an order the portfolio does not list. | |
| std::size_t | cancels_indeterminate_ {0} |
| Cancellations with an unknown outcome. | |
| std::optional< BrokerRefusal > | last_broker_refusal_ |
| The broker's code and message for the last order it refused during this run, if any. | |
| std::optional< strategy::Rejection > | last_unbuildable_ |
| Why reconciliation could not build the last such instruction in this run, if any. | |
| std::size_t | phase_transitions_ {0} |
| How many phase changes were announced to the strategy. | |
| std::size_t | sends_outside_permitted_phase_ {0} |
| Orders sent in a phase RiskLimits::permitted_phases_ does not permit, because they close toward flat; see Runner::sends_outside_permitted_phase. | |
| bool | abandoned_ {false} |
| Whether the loop gave up because a poll kept failing. | |
| std::optional< PollKind > | abandoned_kind_ |
| The poll kind that exhausted its failure budget, if one did. | |
| bool | order_list_read_ {false} |
| Whether the broker's order list was read at least once. | |
| std::size_t | withdrawn_ {0} |
| Cancellations queued for a WITHDRAW or FLATTEN (asked for, not necessarily sent). | |
| std::size_t | flattened_ {0} |
| Closing orders queued for a FLATTEN (asked for, not necessarily sent). | |
| std::size_t | closing_placed_ {0} |
| Closing orders (placements, not cancellations) accepted by the executor (for a dry run, recorded). | |
| std::size_t | closing_rejected_ {0} |
| Closing instructions (placements and cancellations) rejected by reconciliation, the broker or the binding. | |
| std::size_t | closing_refused_ {0} |
| Closing instructions the risk guard refused. | |
| std::size_t | closing_withheld_ {0} |
| Closing instructions held back because the instrument has an order of unknown outcome, or (a serialized runner) an order not yet accounted for; whole withheld plans count once each. | |
| std::size_t | closing_indeterminate_ {0} |
| Closing instructions (cancellations included) with an unknown outcome. | |
| std::size_t | closing_unavailable_ {0} |
| Closing instructions not sent because local machinery was unavailable; fix it, resume_after_local_failure, and stop again. | |
| std::size_t | closing_unresolved_ {0} |
| Closing cancellations naming an order the portfolio does not list; read the broker's list rather than retry. | |
| std::size_t | closing_unconfirmed_ {0} |
| Orders a serialized runner still owed when the closing pass began that neither holdings nor a listing explained (Runner::obligations_unexplained), so the pass could neither withdraw nor size around them. Makes closing_complete() false. | |
| std::chrono::nanoseconds | closing_waited_ {0} |
| The time from the loop taking up a stop to its closing pass (or to the run's abandonment), on the clock's monotonic reading: the wait of PollingLoop::set_closing_wait, if there was one, and the stop handler before it. Small, and not zero, when nothing was waited for. | |
| bool | closing_wait_expired_ {false} |
| Whether that wait ended at its limit, with the closing pass built from what was in hand then. | |
| bool | closing_interrupted_ {false} |
| Whether a WITHDRAW or FLATTEN was pending when the run was abandoned for failing polls, so its closing pass never ran. Makes closing_complete() false; stopped_by_ names the stop. | |
| std::optional< Obligation > | owed_stop_ |
| The order for which the loop stopped placing by itself (PollingLoop::set_owed_order_limit): owed longer than the limit with no sweep having named it, or held for an operator. The loop requested QUIESCE for it, and notes_ says what to do. | |
| std::size_t | closing_contended_ {0} |
| Positions whose closing order was sized down, or not sent, because another order could close them too. | |
| std::size_t | closing_unsizable_ {0} |
| Positions whose closing order could not be sized: the holding rows do not add up, the closing quantity is not representable, or the same-side working quantity cannot be subtracted. Makes closing_complete() false. | |
| bool | closing_source_unverified_ {false} |
| Whether the closing pass could not trust its picture of the account. Makes closing_complete() false. | |
| std::size_t | stop_handler_refused_ {0} |
| Instructions the strategy's on_stop asked for during a stop, refused as intended (the operator's orders go instead). | |
| std::size_t | stop_handler_sent_ {0} |
| Instructions the strategy's on_stop got out during a stop; always zero. | |
| std::vector< std::string > | notes_ |
| Notes for the operator, such as an unrecognized control-file word or a missing policy. | |
What a whole PollingLoop::run did, and why it ended.
Read notes_ first; they explain anything the run could not do. Scope of the counters: the orders_*, cancels_*, plans_withheld_ and instructions_unavailable_ outcomes (and last_broker_refusal_, last_unbuildable_) cover the run's polling, before any closing pass, whose results are the closing_* fields; price_bands_withheld_, unclamped_orders_* and sends_outside_permitted_phase_ cover the whole run, closing pass included.
|
inlinenoexcept |
Returns how many polls of a kind were attempted.
| kind | The kind. |
Definition at line 780 of file loop.hpp.
Referenced by live_program::print_loop().
|
inlinenoexcept |
Tests whether every closing instruction the loop asked for was accepted, and the loop knew what to ask for.
Meaningful only after a WITHDRAW or FLATTEN stop (stopped_by_): a run that ended otherwise, or with QUIESCE, also returns true, having checked nothing. true does not mean flat or nothing resting: an accepted closing order may not have filled, and an accepted cancellation may not have completed. Read the broker's order list and holdings for the state.
Definition at line 761 of file loop.hpp.
Referenced by live_program::print_report().
|
inlinenoexcept |
Returns how many polls of a kind failed.
| kind | The kind. |
Definition at line 789 of file loop.hpp.
Referenced by live_program::print_loop().
| bool algotradelib::runner::LoopReport::abandoned_ {false} |
Whether the loop gave up because a poll kept failing.
Definition at line 662 of file loop.hpp.
Referenced by live_program::print_loop(), and algotradelib::runner::PollingLoop< Runner, Source, Clock >::run().
| std::optional<PollKind> algotradelib::runner::LoopReport::abandoned_kind_ |
The poll kind that exhausted its failure budget, if one did.
Definition at line 664 of file loop.hpp.
Referenced by live_program::print_loop().
| std::size_t algotradelib::runner::LoopReport::attempted_[poll_kind_count] = {} |
How many polls of each kind were attempted, indexed by PollKind; see attempted().
Definition at line 585 of file loop.hpp.
Referenced by attempted().
| std::size_t algotradelib::runner::LoopReport::blocked_ {0} |
How many iterations were blocked from placing (a named cancellation may still have gone).
Definition at line 589 of file loop.hpp.
Referenced by live_program::print_loop(), and algotradelib::runner::PollingLoop< Runner, Source, Clock >::run().
| std::size_t algotradelib::runner::LoopReport::cancels_indeterminate_ {0} |
Cancellations with an unknown outcome.
Definition at line 649 of file loop.hpp.
Referenced by live_program::print_loop().
| std::size_t algotradelib::runner::LoopReport::cancels_refused_ {0} |
Cancellations a hold refused.
Definition at line 645 of file loop.hpp.
Referenced by live_program::print_loop().
| std::size_t algotradelib::runner::LoopReport::cancels_rejected_ {0} |
Cancellations refused by the broker or binding; see Runner::cancels_rejected.
Definition at line 643 of file loop.hpp.
Referenced by live_program::print_loop().
| std::size_t algotradelib::runner::LoopReport::cancels_unresolved_ {0} |
Cancellations naming an order the portfolio does not list.
Definition at line 647 of file loop.hpp.
Referenced by live_program::print_loop().
| ChargedCosts algotradelib::runner::LoopReport::charged_costs_ |
Commission and tax the broker stated on the orders this run saw; a subtotal (see ChargedCosts).
Definition at line 583 of file loop.hpp.
Referenced by algotradelib::runner::PollingLoop< Runner, Source, Clock >::run().
| std::size_t algotradelib::runner::LoopReport::closing_contended_ {0} |
Positions whose closing order was sized down, or not sent, because another order could close them too.
A flatten cancels every listed order and then closes the position, but a same-side order can fill while its cancellation is pending. So the close is sized to the holding minus what is working on that side, or not sent at all when the listing cannot be trusted (closing_source_unverified_). Makes closing_complete() false.
Definition at line 723 of file loop.hpp.
Referenced by closing_complete().
| std::size_t algotradelib::runner::LoopReport::closing_indeterminate_ {0} |
Closing instructions (cancellations included) with an unknown outcome.
Definition at line 683 of file loop.hpp.
Referenced by closing_complete().
| bool algotradelib::runner::LoopReport::closing_interrupted_ {false} |
Whether a WITHDRAW or FLATTEN was pending when the run was abandoned for failing polls, so its closing pass never ran. Makes closing_complete() false; stopped_by_ names the stop.
Definition at line 706 of file loop.hpp.
Referenced by closing_complete().
| std::size_t algotradelib::runner::LoopReport::closing_placed_ {0} |
| std::size_t algotradelib::runner::LoopReport::closing_refused_ {0} |
Closing instructions the risk guard refused.
Definition at line 676 of file loop.hpp.
Referenced by closing_complete().
| std::size_t algotradelib::runner::LoopReport::closing_rejected_ {0} |
Closing instructions (placements and cancellations) rejected by reconciliation, the broker or the binding.
Definition at line 674 of file loop.hpp.
Referenced by closing_complete().
| bool algotradelib::runner::LoopReport::closing_source_unverified_ {false} |
Whether the closing pass could not trust its picture of the account. Makes closing_complete() false.
Set if the order list was never read, the source publishes no working orders, no working-order listing was read or it is older than the portfolio age limit, an order was placed (or sent with an unknown outcome) after that listing, holdings were never read or are too old, or the listing is newer than the holdings. Then a FLATTEN places no closing orders at all, while the withdrawals of the orders it knows of are still sent.
A verified source still lists only what the broker's listing shows: at Toss, an order of a type the API does not list (such as an after-hours closing-price order placed in the app) is in no listing, so a flatten can neither withdraw it nor size around it.
Definition at line 746 of file loop.hpp.
Referenced by closing_complete().
| std::size_t algotradelib::runner::LoopReport::closing_unavailable_ {0} |
Closing instructions not sent because local machinery was unavailable; fix it, resume_after_local_failure, and stop again.
Definition at line 685 of file loop.hpp.
Referenced by closing_complete().
| std::size_t algotradelib::runner::LoopReport::closing_unconfirmed_ {0} |
Orders a serialized runner still owed when the closing pass began that neither holdings nor a listing explained (Runner::obligations_unexplained), so the pass could neither withdraw nor size around them. Makes closing_complete() false.
Definition at line 693 of file loop.hpp.
Referenced by closing_complete().
| std::size_t algotradelib::runner::LoopReport::closing_unresolved_ {0} |
Closing cancellations naming an order the portfolio does not list; read the broker's list rather than retry.
Definition at line 687 of file loop.hpp.
Referenced by closing_complete().
| std::size_t algotradelib::runner::LoopReport::closing_unsizable_ {0} |
Positions whose closing order could not be sized: the holding rows do not add up, the closing quantity is not representable, or the same-side working quantity cannot be subtracted. Makes closing_complete() false.
Definition at line 730 of file loop.hpp.
Referenced by closing_complete().
| bool algotradelib::runner::LoopReport::closing_wait_expired_ {false} |
| std::chrono::nanoseconds algotradelib::runner::LoopReport::closing_waited_ {0} |
The time from the loop taking up a stop to its closing pass (or to the run's abandonment), on the clock's monotonic reading: the wait of PollingLoop::set_closing_wait, if there was one, and the stop handler before it. Small, and not zero, when nothing was waited for.
| std::size_t algotradelib::runner::LoopReport::closing_withheld_ {0} |
Closing instructions held back because the instrument has an order of unknown outcome, or (a serialized runner) an order not yet accounted for; whole withheld plans count once each.
Definition at line 681 of file loop.hpp.
Referenced by closing_complete().
| std::size_t algotradelib::runner::LoopReport::failed_[poll_kind_count] = {} |
| std::optional<strategy::HaltReason> algotradelib::runner::LoopReport::final_gate_ |
The most fundamental hold in force when the run ended, whoever took it.
Definition at line 593 of file loop.hpp.
Referenced by live_program::print_loop(), and algotradelib::runner::PollingLoop< Runner, Source, Clock >::run().
| strategy::MarketPhase algotradelib::runner::LoopReport::final_phase_ {strategy::MarketPhase::UNKNOWN} |
The phase the last iteration computed.
Definition at line 595 of file loop.hpp.
Referenced by live_program::print_loop(), and algotradelib::runner::PollingLoop< Runner, Source, Clock >::run().
| std::size_t algotradelib::runner::LoopReport::flattened_ {0} |
| std::size_t algotradelib::runner::LoopReport::instructions_unavailable_ {0} |
Instructions not sent because local machinery was unavailable; see Runner::instructions_unavailable.
| std::size_t algotradelib::runner::LoopReport::iterations_ {0} |
How many iterations ran.
Definition at line 581 of file loop.hpp.
Referenced by live_program::print_loop(), and algotradelib::runner::PollingLoop< Runner, Source, Clock >::run().
| std::optional<BrokerRefusal> algotradelib::runner::LoopReport::last_broker_refusal_ |
The broker's code and message for the last order it refused during this run, if any.
Definition at line 651 of file loop.hpp.
Referenced by live_program::print_loop(), and algotradelib::runner::PollingLoop< Runner, Source, Clock >::run().
| std::optional<strategy::Rejection> algotradelib::runner::LoopReport::last_unbuildable_ |
Why reconciliation could not build the last such instruction in this run, if any.
Definition at line 653 of file loop.hpp.
Referenced by live_program::print_loop(), and algotradelib::runner::PollingLoop< Runner, Source, Clock >::run().
| std::vector<std::string> algotradelib::runner::LoopReport::notes_ |
Notes for the operator, such as an unrecognized control-file word or a missing policy.
Definition at line 773 of file loop.hpp.
Referenced by live_program::print_loop(), and algotradelib::runner::PollingLoop< Runner, Source, Clock >::run().
| bool algotradelib::runner::LoopReport::order_list_read_ {false} |
Whether the broker's order list was read at least once.
Definition at line 666 of file loop.hpp.
Referenced by live_program::print_loop(), and algotradelib::runner::PollingLoop< Runner, Source, Clock >::run().
| std::size_t algotradelib::runner::LoopReport::orders_binding_refused_ {0} |
Orders the binding refused to send; see Runner::orders_binding_refused.
Definition at line 620 of file loop.hpp.
Referenced by live_program::print_loop().
| std::size_t algotradelib::runner::LoopReport::orders_broker_refused_ {0} |
Orders the broker refused (SendOutcome::REJECTED); see last_broker_refusal_. At KIS, Toss and Kiwoom most refusals arrive as unknown outcomes and are counted in orders_indeterminate_.
Definition at line 626 of file loop.hpp.
Referenced by live_program::print_loop(), and algotradelib::runner::PollingLoop< Runner, Source, Clock >::run().
| std::size_t algotradelib::runner::LoopReport::orders_guard_refused_ {0} |
Orders the risk guard refused; see Runner::orders_guard_refused.
Definition at line 618 of file loop.hpp.
Referenced by live_program::print_loop().
| std::size_t algotradelib::runner::LoopReport::orders_indeterminate_ {0} |
Orders with an unknown outcome (SendOutcome::INDETERMINATE, including most KIS, Toss and Kiwoom refusals).
Definition at line 631 of file loop.hpp.
Referenced by live_program::print_loop().
| std::size_t algotradelib::runner::LoopReport::orders_reconcile_withheld_ {0} |
Orders held back for an instrument of unknown order state; see Runner::orders_reconcile_withheld.
Definition at line 616 of file loop.hpp.
Referenced by live_program::print_loop().
| std::size_t algotradelib::runner::LoopReport::orders_unbuildable_ {0} |
Orders reconciliation could not build during this run's polling; see Runner::orders_unbuildable.
Definition at line 614 of file loop.hpp.
Referenced by live_program::print_loop(), and algotradelib::runner::PollingLoop< Runner, Source, Clock >::run().
| std::size_t algotradelib::runner::LoopReport::orders_unconfirmed_timed_out_ {0} |
Sent orders that timed out unconfirmed; see Runner::set_confirmation_timeout for what each mode then withholds. Counted in the run that noticed it, not while it stays owed (Runner::obligations); a named serialized order counted here marks no ledger.
Definition at line 637 of file loop.hpp.
Referenced by live_program::print_loop().
| std::optional<Obligation> algotradelib::runner::LoopReport::owed_stop_ |
The order for which the loop stopped placing by itself (PollingLoop::set_owed_order_limit): owed longer than the limit with no sweep having named it, or held for an operator. The loop requested QUIESCE for it, and notes_ says what to do.
| std::size_t algotradelib::runner::LoopReport::phase_transitions_ {0} |
How many phase changes were announced to the strategy.
Definition at line 655 of file loop.hpp.
Referenced by algotradelib::runner::PollingLoop< Runner, Source, Clock >::run().
| std::size_t algotradelib::runner::LoopReport::plans_withheld_ {0} |
Whole plans held back (any WithheldPlanReason); see Runner::plans_withheld.
Definition at line 639 of file loop.hpp.
Referenced by live_program::print_loop().
| std::size_t algotradelib::runner::LoopReport::price_bands_withheld_ {0} |
Plans built while a known price band was not applied (no age policy, too old, or dated after the clock); see Runner::price_bands_withheld.
Definition at line 608 of file loop.hpp.
Referenced by algotradelib::runner::PollingLoop< Runner, Source, Clock >::run().
| std::size_t algotradelib::runner::LoopReport::sends_outside_permitted_phase_ {0} |
Orders sent in a phase RiskLimits::permitted_phases_ does not permit, because they close toward flat; see Runner::sends_outside_permitted_phase.
Definition at line 660 of file loop.hpp.
Referenced by algotradelib::runner::PollingLoop< Runner, Source, Clock >::run().
| std::size_t algotradelib::runner::LoopReport::sends_under_a_revised_phase_ {0} |
How many calls into a source or strategy both sent something and left the market phase changed.
Always zero with live::SessionSource and a strategy that does not write the calendar; nonzero means some code breaks the rule in PollKind::CALENDAR (co-occurrence, not proof of a stale send).
| std::size_t algotradelib::runner::LoopReport::stop_handler_refused_ {0} |
| std::size_t algotradelib::runner::LoopReport::stop_handler_sent_ {0} |
| std::optional<StopIntent> algotradelib::runner::LoopReport::stopped_by_ |
The stop intent that ended the run, if one did.
Definition at line 591 of file loop.hpp.
Referenced by live_program::print_loop(), and algotradelib::runner::PollingLoop< Runner, Source, Clock >::run().
| std::size_t algotradelib::runner::LoopReport::unclamped_orders_refused_ {0} |
Orders refused before sending while carrying such a price; see Runner::unclamped_orders_refused.
Definition at line 612 of file loop.hpp.
Referenced by algotradelib::runner::PollingLoop< Runner, Source, Clock >::run().
| std::size_t algotradelib::runner::LoopReport::unclamped_orders_rejected_ {0} |
Sent orders the broker refused while carrying a price a withheld band would have clamped; see Runner::unclamped_orders_rejected.
Definition at line 610 of file loop.hpp.
Referenced by algotradelib::runner::PollingLoop< Runner, Source, Clock >::run().
| std::size_t algotradelib::runner::LoopReport::withdrawn_ {0} |