![]() |
algotradelib 0.0.0.9000
C++ header-only library for algorithmic trading
|
Runs a strategy: the runner, the polling loop, the order journal, and stopping. More...
Classes | |
| struct | BarEvent |
| One bar, delivered to on_bar. More... | |
| struct | BrokerRefusal |
| The broker's own code and message for a refusal, kept for diagnosis. More... | |
| struct | CancelIntent |
| A request to cancel one working order. More... | |
| struct | ChargedCosts |
| Commission and tax the broker stated on the orders a loop happened to poll (Toss states them; KIS does not). More... | |
| class | ClockReference |
| A clock that reads another one, so that two holders (a loop and its journal) read one time. More... | |
| class | Context |
| What a strategy's handlers receive as ctx: everything the strategy may read, and where it queues what it wants. More... | |
| struct | DryRunReport |
| What one runner pass decided and did, sorted by outcome (returned by Runner::feed). More... | |
| struct | DryTag |
| The broker tag of a dry run, whose order references reach no broker. More... | |
| struct | FailurePolicy |
| How a PollingLoop responds to polls that keep failing. More... | |
| class | FileJournal |
| The order journal on disk: one JSON object per line, appended and flushed to disk (fsync) before append returns. More... | |
| class | FileStopChannel |
| A control file an operator writes to stop a running loop with a given intent. More... | |
| struct | Fill |
| One execution of an order the strategy placed, delivered to on_fill. More... | |
| class | IndeterminacyLedger |
| The instruments with an order of unknown outcome, where nothing may be placed until the broker's order list is read and the instrument resolved. More... | |
| struct | IterationReport |
| What one loop iteration did. More... | |
| struct | JournalBytes |
| A journal file's bytes, and whether they could be read. More... | |
| struct | JournalEntry |
| One journal line: an instruction and what was known about it when the line was written. More... | |
| class | JournalingExecutor |
| An executor wrapper that records each instruction in a journal before sending it. More... | |
| struct | JournalReplay |
| The contents of a journal, including what could not be read. More... | |
| struct | LoopReport |
| What a whole PollingLoop::run did, and why it ended. More... | |
| class | ManualClock |
| A clock for tests: wait_for advances it instead of sleeping. More... | |
| class | ManualSource |
| A source for tests: each poll returns a queued or default outcome, without any network. More... | |
| struct | MatchWindow |
| The time allowances used when matching journalled instructions against a broker listing. More... | |
| class | MemoryJournal |
| A journal held in memory, lost when the process exits; for tests and dry runs. More... | |
| struct | Obligation |
| One order a serialized runner still owes (Runner::obligations). More... | |
| struct | OpenInstruction |
| One instruction of unknown outcome, and the span in which it may have reached the broker. More... | |
| class | OrderIntent |
| One order a strategy asks the runner to place. More... | |
| struct | OrderMatch |
| One instruction's verdict, with context for the operator. More... | |
| class | OrderUpdateWatch |
| Turns successive working-order listings into order updates: the rows that changed since the previous listing. More... | |
| class | PollingLoop |
| Runs a runner for a live session: polls a source on a schedule, gates placements, derives the market phase, and honours stop requests. More... | |
| struct | PollSchedule |
| How often a PollingLoop polls each kind; an unset interval disables that poll. More... | |
| struct | Portfolio |
| What the account holds and which orders are still working, as a strategy sees it. More... | |
| struct | QuoteEvent |
| A quote the runner has just read, delivered to on_quote. More... | |
| struct | ReconcileReport |
| What one sweep of the broker's order list settled, and what is still withheld. More... | |
| class | RecordingExecutor |
| An executor that sends nothing and records what it was given (the dry run's default). More... | |
| struct | RecoveryReport |
| What a journal showed was left owed by the process that wrote it. More... | |
| struct | RefusedCancel |
| A cancellation a hold refused (nothing was sent), and which hold. More... | |
| struct | RejectedCancel |
| A cancellation that was refused, by the broker or before it was sent. More... | |
| class | Runner |
| Runs one strategy: feeds it events, reconciles what it asks for, checks the risk limits, and sends through an executor. More... | |
| struct | runner_counts_kept_drops |
| Detects whether a runner reports kept_intents_dropped(). More... | |
| struct | runner_counts_kept_drops< Runner, std::void_t< decltype(std::declval< const Runner & >().kept_intents_dropped())> > |
| struct | runner_counts_warmup |
| Detects whether a runner reports warmup_instructions_discarded(). More... | |
| struct | runner_counts_warmup< Runner, std::void_t< decltype(std::declval< const Runner & >().warmup_instructions_discarded())> > |
| struct | runner_keeps_sent_orders |
| Detects Runner::keeps_sent_orders_until_listed. More... | |
| struct | runner_keeps_sent_orders< Runner, std::void_t< decltype(Runner::keeps_sent_orders_until_listed)> > |
| struct | SeriesKey |
| Identifies one cached bar series: an instrument at one bar interval. More... | |
| class | SignalStop |
| Routes SIGINT and SIGTERM to a StopSource as a quiesce, and ignores SIGHUP where it exists (POSIX); only when install is called. More... | |
| struct | source_names_buying_power_currencies |
| Detects whether a source provides const std::vector<Currency>& buying_power_currencies()
const. More... | |
| struct | source_names_buying_power_currencies< Source, std::void_t< decltype(std::declval< const Source & >().buying_power_currencies())> > |
| struct | source_provides_working_orders |
| Detects whether a source declares static constexpr bool provides_working_orders = true, meaning it leaves the broker's working orders in the portfolio after an order-list read. More... | |
| struct | source_provides_working_orders< Source, std::void_t< decltype(Source::provides_working_orders)> > |
| struct | source_states_charged_costs |
| Detects whether a source provides const ChargedCosts& charged_costs() const, which LoopReport then reports. More... | |
| struct | source_states_charged_costs< Source, std::void_t< decltype(std::declval< const Source & >().charged_costs())> > |
| class | SteadyClock |
| The real clock a live loop uses: wall-clock time to stamp events, monotonic time to wait and to measure how long something took. More... | |
| class | StopSource |
| A stop request the loop polls; safe to set from a signal handler. More... | |
| struct | TargetPosition |
| The position a strategy wants to hold in one instrument. More... | |
| struct | WithheldOrder |
| One order the runner held back without sending, and why. More... | |
| struct | WithheldPlan |
| One reconciliation plan the runner held back, and what it would have done. More... | |
Typedefs | |
| template<typename Broker> | |
| using | Instruction = std::variant<OrderIntent, TargetPosition, CancelIntent<Broker>> |
| One request a strategy queued: an order, a target position or a cancellation. | |
| using | RouteEvidence = Evidence |
| Evidence, under the name used for the route comparison. | |
| template<typename Strategy, typename CapsType = strategy::NoCaps> | |
| using | DryRunner = Runner<Strategy, CapsType, DryTag, RecordingExecutor<DryTag>> |
| A runner that sends nothing: handlers fire and instructions are recorded by a RecordingExecutor. | |
Enumerations | |
| enum class | SendOutcome { ACCEPTED , REJECTED , INDETERMINATE , UNAVAILABLE , REFUSED_LOCALLY } |
| What became of one instruction (a placement or a cancellation) an executor was asked to send. More... | |
| enum class | WithheldReason { RECONCILE_REQUIRED , LOCAL_FAILURE , AWAITING_CONFIRMATION } |
| Why the runner held back a planned order without sending it. More... | |
| enum class | WithheldPlanReason { PORTFOLIO_ABSENT , PORTFOLIO_STALE , PLACEMENT_HELD , PORTFOLIO_SUPERSEDED , AWAITING_CONFIRMATION } |
| Why the runner held back a whole reconciliation plan (cancellations and placements) before sending any of it. More... | |
| enum class | ObligationState { NONE , NAMED , UNNAMED , OPERATOR } |
| What a serialized runner still owes on an instrument (Runner::obligation_state). More... | |
| enum class | JournalAction { PLACE , CANCEL } |
| Which kind of instruction a journal line records. More... | |
| enum class | JournalOutcome { PENDING , ACCEPTED , REJECTED , INDETERMINATE , RESOLVED , CONFIRMED , HELD } |
| What a journal line says about an instruction. More... | |
| enum class | JournalReadStatus { MISSING , READ , UNREADABLE } |
| Whether a journal file could be read. More... | |
| enum class | PollKind { BARS , QUOTES , HOLDINGS , WORKING_ORDERS , BUYING_POWER , CALENDAR , PRICE_LIMITS } |
| What a PollingLoop polls for; each has a cadence in PollSchedule. More... | |
| enum class | PollOutcome { UPDATED , UNCHANGED , FAILED , RATE_LIMITED } |
| What became of one poll. More... | |
| enum class | MatchVerdict { MATCHED , NOT_PLACED , AMBIGUOUS , UNDECIDED , NEEDS_OPERATOR } |
| What the broker's order list says about one instruction of unknown outcome. More... | |
| enum class | Evidence { CONFIRMS , CONTRADICTS , ABSENT } |
| What one attribute of a broker row says about an instruction. More... | |
| enum class | StopIntent { QUIESCE , WITHDRAW , FLATTEN } |
| What an operator asks for when stopping a running loop. More... | |
| enum class | MarketPhase |
| Where the clock stands relative to the trading session. More... | |
Functions | |
| constexpr std::string_view | send_outcome_name (SendOutcome outcome) noexcept |
| Returns a lowercase name for an outcome, such as "indeterminate", for logs. | |
| SendOutcome | outcome_of (const BrokerError &error) |
| Classifies an error from an order request: did the order come to exist? | |
| constexpr bool | error_retries_when_unsent (ErrorCategory category) noexcept |
| Tests whether a request that was never sent may be tried again on a later pass, by its error's category. | |
| bool | broker_unreachable (const BrokerError &error) noexcept |
| Tests whether an error means the broker could not be reached (as opposed to the binding refusing the instruction itself). | |
| bool | broker_rate_limited (const BrokerError &error) noexcept |
| Tests whether an error is the broker's rate-limit refusal (such as KIS EGW00201). | |
| constexpr bool | send_outcome_reached_broker (SendOutcome outcome) noexcept |
| Tests whether an outcome means a request reached the broker. | |
| constexpr bool | send_outcome_is_local_failure (SendOutcome outcome) noexcept |
| Tests whether an outcome means the runner's own machinery failed (not the broker, and not a check that refused the order), which stops it from sending until someone looks. | |
| constexpr std::string_view | withheld_reason_name (WithheldReason reason) noexcept |
| Returns a lowercase name for a reason, such as "reconcile_required", for logs. | |
| constexpr std::string_view | withheld_plan_reason_name (WithheldPlanReason reason) noexcept |
| Returns a lowercase name for a reason, such as "portfolio_stale", for logs. | |
| constexpr int | obligation_weight (ObligationState state) noexcept |
| Returns how much an obligation state weighs when one instrument owes several orders: the instrument reports the heaviest. | |
| constexpr bool | obligation_is_unaccounted (ObligationState state) noexcept |
| Tests whether an order in this state counts toward the loop's owed-order time limit (PollingLoop::set_owed_order_limit). | |
| constexpr bool | obligation_needs_operator (ObligationState state) noexcept |
| Tests whether only an operator can settle an obligation in this state, so no read of the broker's lists can. | |
| constexpr std::string_view | obligation_state_name (ObligationState state) noexcept |
| Returns a lowercase name for a state, such as "named", for logs. | |
| constexpr std::string_view | journal_format_name () noexcept |
| Returns the format name in a journal header's journal field. | |
| std::string | journal_header_line (std::string_view scope) |
| Renders the header line a journal file starts with, naming its broker and account. | |
| bool | journal_header_declares_checksums (std::string_view line) |
| Tests whether a header line declares that every entry after it carries a checksum. | |
| std::optional< std::string > | journal_header_scope (std::string_view line) |
| Returns the scope a header line declares. | |
| std::string | journal_entry_to_line (const JournalEntry &entry) |
| Renders one entry as a journal line: a JSON object ending in a CRC-32 checksum member. | |
| JournalEntry | unattributable_journal_entry (std::string_view line) |
| Makes the entry that stands for a torn line naming no instrument. | |
| std::optional< JournalEntry > | journal_entry_from_line (std::string_view line) |
| Parses one journal line. | |
| bool | salvage_damaged (std::string_view line, std::string_view key) |
| Tests whether a journal line has a field that was written completely but cannot be read. | |
| std::optional< JournalEntry > | salvage_journal_line (std::string_view line) |
| Salvages a torn final line into an entry nothing can resolve automatically. | |
| JournalBytes | read_journal_bytes (const std::string &path) |
| Reads a journal file's bytes, without opening it for appending. | |
| JournalReplay | parse_journal_bytes (const JournalBytes &bytes) |
| Parses a journal's bytes, salvaging a torn final line. | |
| JournalReplay | read_journal_file (const std::string &path) |
| Reads and parses a journal file. | |
| constexpr std::string_view | journal_action_name (JournalAction action) noexcept |
| Returns an action's name as written to the journal ("place", "cancel"). | |
| constexpr bool | journal_action_matches_by_order_id (JournalAction action) noexcept |
| Tests whether recovery matches an instruction of this action by the broker's order id it names, rather than by its attributes. | |
| std::optional< JournalAction > | journal_action_from (std::string_view text) noexcept |
| Parses an action's name. | |
| constexpr std::string_view | journal_outcome_name (JournalOutcome outcome) noexcept |
| Returns an outcome's name as written to the journal ("pending", ...). | |
| std::optional< JournalOutcome > | journal_outcome_from (std::string_view text) noexcept |
| Parses an outcome's name. | |
| constexpr JournalOutcome | journal_outcome_of (SendOutcome outcome) noexcept |
| Maps a send outcome to the journal outcome that records it. | |
| constexpr bool | journal_outcome_is_terminal (JournalOutcome outcome) noexcept |
| Tests whether an outcome answers a PENDING line. | |
| constexpr bool | journal_outcome_answers_send (JournalOutcome outcome) noexcept |
| Tests whether a line with this outcome answers the send itself (the broker's reply, or its absence), rather than a later account of it. | |
| constexpr bool | journal_outcome_names_order (JournalOutcome outcome) noexcept |
| Tests whether a line with this outcome may carry the broker's id for the order. | |
| constexpr bool | journal_outcome_refuses (JournalOutcome outcome) noexcept |
| Tests whether a line with this outcome says the instruction was refused, so it does not exist. | |
| constexpr bool | journal_outcome_is_closing_account (JournalOutcome outcome) noexcept |
| Tests whether a line with this outcome is a serialized runner's closing account of a placement (it confirmed it, or held it for an operator), which repeats none of the instruction's shape. | |
| constexpr bool | journal_outcome_requires_operator (JournalOutcome outcome) noexcept |
| Tests whether a line with this outcome is written with requires_operator_ by design, so the flag is not damage. | |
| constexpr bool | journal_outcome_leaves_open (JournalOutcome outcome) noexcept |
| Tests whether a line with this outcome leaves its instruction's fate unknown, so recovery must still settle it. | |
| constexpr std::string_view | journal_read_status_name (JournalReadStatus status) noexcept |
| Returns a status's lowercase name, such as "unreadable". | |
| std::vector< OpenInstruction > | unresolved_instructions (const JournalReplay &replay) |
| Lists the instructions whose outcome is unknown, in the order they were opened. | |
| std::vector< OpenInstruction > | placements_of (const JournalReplay &replay, const std::vector< std::string > &ids) |
| Returns the placements with the given journal ids, each with the span in which it may have reached the broker, whatever was written about them since. | |
| constexpr std::string_view | poll_kind_name (PollKind kind) noexcept |
| Returns a poll kind's lowercase name, such as "working_orders". | |
| constexpr std::string_view | poll_outcome_name (PollOutcome outcome) noexcept |
| Returns an outcome's lowercase name, such as "rate_limited". | |
| constexpr std::string_view | match_verdict_name (MatchVerdict verdict) noexcept |
| Returns a verdict's lowercase name, such as "not_placed", for logs. | |
| constexpr bool | match_verdict_resolves (MatchVerdict verdict) noexcept |
| Tests whether a verdict settles the question. | |
| std::chrono::system_clock::time_point | instruction_sent_by (const OpenInstruction &instruction, const MatchWindow &window) |
| Returns the last instant an instruction could have reached the broker. | |
| bool | match_window_closed (const OpenInstruction &instruction, std::chrono::system_clock::time_point now, const MatchWindow &window) |
| Tests whether a missing row may now be read as "not placed". | |
| constexpr bool | evidence_confirms (Evidence evidence) noexcept |
| Tests whether a piece of evidence confirms the row is the instruction's order. | |
| constexpr bool | evidence_contradicts (Evidence evidence) noexcept |
| Tests whether a piece of evidence rules the row out. | |
| constexpr bool | evidence_leaves_open (Evidence evidence) noexcept |
| Tests whether a piece of evidence leaves the question open, so the row might still be the order and cannot count toward proving it absent. | |
| template<typename Enum> | |
| Evidence | attribute_evidence (Enum row_value, Enum entry_value) noexcept |
| Compares an enumerated attribute of a row with the instruction's. | |
| Evidence | trigger_evidence (const std::optional< Decimal64 > &row_trigger, const std::optional< Decimal64 > &entry_trigger) |
| Compares a row's trigger price with the instruction's. | |
| Evidence | time_evidence (const OpenInstruction &instruction, const OrderSnapshot &row, const MatchWindow &window) |
| Compares a row's order time with the window in which the instruction was sent. | |
| RouteEvidence | route_evidence (const OpenInstruction &instruction, const OrderSnapshot &row) |
| Compares a row's venue with the route the instruction recorded. | |
| bool | row_corresponds (const OpenInstruction &instruction, const OrderSnapshot &row, const MatchWindow &window) |
| Tests whether a row is established to be an instruction's order. | |
| bool | row_might_correspond (const OpenInstruction &instruction, const OrderSnapshot &row, const MatchWindow &window) |
| Tests whether a row might be an instruction's order although some attributes could not be read (such as an order type outside the broker's published table). | |
| std::string | unresolvable_reason (const JournalEntry &entry) |
| Returns why an instruction cannot be resolved from a broker listing. | |
| std::vector< OpenInstruction > | recorded_placements (const JournalReplay &replay) |
| Returns the placements a journal records an order id for, each with the span of its send. | |
| const OpenInstruction * | recorded_owner (const OpenInstruction &instruction, const OrderSnapshot &row, const std::vector< OpenInstruction > &recorded, const MatchWindow &window) |
| Returns the recorded placement whose order a row is: the row carries the order id the journal records for it and fits that placement's own send (row_corresponds or row_might_correspond). | |
| OrderMatch | match_against (const OpenInstruction &instruction, const std::vector< OrderSnapshot > &rows, const std::vector< OpenInstruction > &recorded, std::chrono::system_clock::time_point now, const MatchWindow &window={}) |
| Decides what a broker listing says about one instruction of unknown outcome. | |
| OrderMatch | match_against (const OpenInstruction &instruction, const std::vector< OrderSnapshot > &rows, std::chrono::system_clock::time_point now, const MatchWindow &window={}) |
| Decides what a broker listing says about one instruction, with no other placement's recorded order to set aside: every row that fits is a candidate. | |
| void | drop_rows_fitting_another_placement (std::vector< OrderSnapshot > &rows, const JournalReplay &replay, const std::vector< OpenInstruction > &matching, const MatchWindow &window={}) |
| Removes the rows that could be another placement's order as well. | |
| JournalEntry | resolution_entry (const OpenInstruction &instruction, const OrderMatch &match, std::chrono::system_clock::time_point now) |
| Makes the RESOLVED journal line that records a sweep's verdict. | |
| template<typename Journal> | |
| ReconcileReport | reconcile_against (const std::vector< OpenInstruction > &open, const std::vector< OrderSnapshot > &rows, const JournalReplay &replay, std::chrono::system_clock::time_point now, IndeterminacyLedger &ledger, Journal &journal, const MatchWindow &window={}, std::string_view unplaced_note={}) |
| Resolves what a broker listing settles, records it in the journal, and clears the ledger for each instrument whose instructions are all decided. | |
| template<typename Journal> | |
| ReconcileReport | reconcile_against (const std::vector< OpenInstruction > &open, const std::vector< OrderSnapshot > &rows, std::chrono::system_clock::time_point now, IndeterminacyLedger &ledger, Journal &journal, const MatchWindow &window={}, std::string_view unplaced_note={}) |
| Resolves what a broker listing settles, reading the journal's contents from journal; see the other overload. | |
| ReconcileReport | decide_nothing (const std::vector< OpenInstruction > &open, std::string detail) |
| Makes a report that decides nothing, for a sweep that could not see a complete listing. | |
| bool | any_placement (const std::vector< OpenInstruction > &open) |
| Tests whether any instruction is a placement a listing could decide (which needs history, not only working orders). | |
| bool | exact_copy (const OrderSnapshot &a, const OrderSnapshot &b) |
| Tests whether two rows are established copies of one order: the same order id and instrument, and the same order time on both. | |
| bool | dates_listed_order (const OrderSnapshot &assumed, const OrderSnapshot &row) |
| Tests whether a dated history row is the order a listing row whose date was assumed shows: the same order id and instrument at the same time of day, nothing either row states disagrees (side, quantity, type, time in force, session, trigger, venue), and the price is stated alike on both (both absent, or equal). | |
| void | merge_dated_history (std::vector< OrderSnapshot > &into, const std::vector< OrderSnapshot > &rows) |
| Adds history rows to a working-order listing, dropping established copies (exact_copy) and listing rows a history row dates; for brokers whose history takes no range (Kiwoom, Toss). | |
| void | merge_rows (std::vector< OrderSnapshot > &into, const std::vector< OrderSnapshot > &rows) |
| Adds rows to a listing, skipping any whose order id is already there. | |
| Date | date_of (std::chrono::system_clock::time_point at) |
| Returns the UTC calendar date of an instant. | |
| std::pair< Date, Date > | history_range_for (const std::vector< OpenInstruction > &open, const MatchWindow &window) |
| Returns the date range an order-history inquiry must cover for some instructions. | |
| RecoveryReport | recover_into (const JournalReplay &replay, IndeterminacyLedger &ledger) |
| Marks the ledger for every instrument a journal left an instruction of unknown outcome for. | |
| template<typename Journal> | |
| RecoveryReport | recover_into (const Journal &journal, IndeterminacyLedger &ledger) |
| Reads a journal and marks the ledger for what it left owed; see the other overload. | |
| template<typename Runner, typename Journal> | |
| RecoveryReport | recover_runner (Runner &runner_instance, const Journal &journal) |
| Recovers a journal into a runner at startup: marks each instrument left owed, restores a serialized runner's orders not yet accounted for (Runner::restore_obligations), and halts the runner when damage names no instrument. | |
| constexpr std::string_view | stop_intent_name (StopIntent intent) noexcept |
| Returns a lowercase name for an intent, as written in the control file ("withdraw"). | |
| std::optional< StopIntent > | stop_intent_from (std::string_view text) noexcept |
| Parses an intent's name. | |
| constexpr int | stop_intent_strength (StopIntent intent) noexcept |
| Returns an intent's strength: a stronger intent does everything a weaker one does. | |
| constexpr bool | stop_intent_closes (StopIntent intent) noexcept |
| Tests whether a stop intent asks for a closing pass (cancellations, and for FLATTEN closing orders) after sending stops, and so needs the broker's order list read first. | |
| constexpr bool | stop_intent_closes_positions (StopIntent intent) noexcept |
| Tests whether a stop intent closes positions with market orders, after withdrawing the working orders. | |
| constexpr bool | stop_intent_covers (StopIntent held, StopIntent candidate) noexcept |
| Tests whether one intent does everything another would. | |
Variables | |
| constexpr std::array< SendOutcome, 5 > | all_send_outcomes |
| Every SendOutcome, in declaration order. | |
| constexpr std::array< JournalAction, 2 > | all_journal_actions {JournalAction::PLACE, JournalAction::CANCEL} |
| Every JournalAction, in declaration order. | |
| constexpr std::array< JournalOutcome, 7 > | all_journal_outcomes |
| Every JournalOutcome, in declaration order. | |
| constexpr PollKind | all_poll_kinds [] |
| Every poll kind, in the order an iteration polls them. | |
| constexpr std::size_t | poll_kind_count = std::size(all_poll_kinds) |
| The number of PollKind values. | |
| constexpr std::array< PollOutcome, 4 > | all_poll_outcomes |
| Every PollOutcome, in declaration order. | |
| constexpr std::array< StopIntent, 3 > | all_stop_intents |
| Every StopIntent, in declaration order. | |
Runs a strategy: the runner, the polling loop, the order journal, and stopping.
| using algotradelib::runner::DryRunner = Runner<Strategy, CapsType, DryTag, RecordingExecutor<DryTag>> |
A runner that sends nothing: handlers fire and instructions are recorded by a RecordingExecutor.
It runs the same pipeline as a live session. A dry-run program contains no broker or network code (though the package's link line still carries the transport libraries).
| Strategy | The strategy type. |
| CapsType | The broker capabilities the strategy sees. |
Definition at line 4524 of file runner.hpp.
| using algotradelib::runner::Instruction = std::variant<OrderIntent, TargetPosition, CancelIntent<Broker>> |
One request a strategy queued: an order, a target position or a cancellation.
Requests are kept in one queue in the order the strategy made them, so a cancellation followed by a target is handled in that order.
| Broker | The broker tag of the cancellation's order reference. |
Definition at line 45 of file context.hpp.
Evidence, under the name used for the route comparison.
Definition at line 249 of file reconcile_orders.hpp.
|
strong |
What one attribute of a broker row says about an instruction.
ABSENT (nothing recorded to compare) neither confirms a match nor allows an absence verdict.
| Enumerator | |
|---|---|
| CONFIRMS | The row agrees. |
| CONTRADICTS | The row disagrees; it is not this order. |
| ABSENT | Not enough was recorded to say. |
Definition at line 190 of file reconcile_orders.hpp.
|
strong |
Which kind of instruction a journal line records.
Recovery resolves them differently: a cancellation names the broker's order id, a placement is matched by its attributes.
| Enumerator | |
|---|---|
| PLACE | A new order. |
| CANCEL | A cancellation of a resting order. |
Definition at line 30 of file journal.hpp.
|
strong |
What a journal line says about an instruction.
PENDING is written before the instruction is sent; a later line with any other outcome answers it. A PENDING line with no answer means the process stopped while the request may have been in flight, so the order's existence is unknown.
| Enumerator | |
|---|---|
| PENDING | Written before the send; whether the instruction exists is not yet known. |
| ACCEPTED | The broker accepted the instruction; it exists. |
| REJECTED | The instruction was refused, by the broker or before it was sent, so it does not exist. The journal does not record who refused; a pass's report does. |
| INDETERMINATE | The outcome is unknown (SendOutcome::INDETERMINATE: a failure in transit, an unreadable reply, an HTTP 5xx, or a broker refusal reported as PROTOCOL). |
| RESOLVED | A recovery sweep read the broker's order list and closed the question. order_id_ is set if a matching order was found and empty if none was; detail_ says what was seen. For a cancellation, a match means the named order was in the listing read (resting only if that listing held working orders alone); it does not mean the cancellation completed. |
| CONFIRMED | A serialized runner accounted for the placement: holdings showed what it filled, its history showed it ended with nothing filled, or an operator released it. baseline_ is the instrument's holding afterwards, where holdings showed it; detail_ says which. See Runner::allow_overlapping_orders. |
| HELD | Evidence contradicted the placement (holdings moved past what it can explain), so only an operator may account for it (Runner::release_obligations). Written with requires_operator_. |
Definition at line 93 of file journal.hpp.
|
strong |
Whether a journal file could be read.
A missing file means a first start with nothing owed; an unreadable one may hold orders left in flight, and must not be treated as empty.
| Enumerator | |
|---|---|
| MISSING | No such file: a first start, nothing owed. |
| READ | The file was read in full. |
| UNREADABLE | The file exists and could not be read; its contents are unknown. |
Definition at line 433 of file journal.hpp.
|
strong |
|
strong |
What the broker's order list says about one instruction of unknown outcome.
A missing row means NOT_PLACED only after the matching window has closed (the listing may lag an accepted write); before that it is UNDECIDED. NOT_PLACED is a finding about the rows supplied, not the broker's word that no order exists: an overlapping runner then forgets the placement, and a serialized runner (Runner::serialized) keeps it owed.
| Enumerator | |
|---|---|
| MATCHED | Exactly one row corresponds; the order exists. For a cancellation: the named order is in the listing supplied (which may include history, so not necessarily resting). |
| NOT_PLACED | No row corresponds and the window has closed: no order was found. For a cancellation: the named order is not in the listing supplied. |
| AMBIGUOUS | Several rows could correspond, a row that fits is another placement's, or a row that fits cannot be confirmed; the instrument stays withheld until a later sweep or an operator decides. |
| UNDECIDED | No row yet, and the window is still open; wait for the next sweep. |
| NEEDS_OPERATOR | The instruction came from a damaged journal line, or its line cannot be matched (unresolvable_reason); only an operator may resolve it. |
Definition at line 31 of file reconcile_orders.hpp.
|
strong |
What a serialized runner still owes on an instrument (Runner::obligation_state).
| Enumerator | |
|---|---|
| NONE | Nothing: an order may be placed. |
| NAMED | An order the broker named, waiting for its history and holdings to account for it. |
| UNNAMED | An order whose existence is unknown (its reply was lost and no sweep named it). |
| OPERATOR | An order only an operator may account for (Runner::release_obligations). |
Definition at line 374 of file execution.hpp.
|
strong |
What a PollingLoop polls for; each has a cadence in PollSchedule.
Each iteration polls in the order of all_poll_kinds: calendar, price limits, working orders, holdings, buying power, bars, quotes.
| Enumerator | |
|---|---|
| BARS | Completed bars. |
| QUOTES | Current quotes, for strategies that act between bars. |
| HOLDINGS | Holdings, which orders are sized against. |
| WORKING_ORDERS | Working orders, which reconciliation and cancellation need. |
| BUYING_POWER | Buying power, polled beside holdings (not before each order). |
| CALENDAR | The trading calendar, from which the loop derives the market phase; polled first, and on by default.
|
| PRICE_LIMITS | Today's price bands, which an aggressive limit price is clamped to; polled second, before anything that feeds. It installs bands with Runner::set_price_limits and feeds nothing. Orders decided from a poll use this iteration's bands; an order decided inside Source::read_order_list (which runs before the polls) would use the previous iteration's. |
|
strong |
What became of one poll.
Only FAILED counts toward FailurePolicy; nothing new (UNCHANGED) and a rate-limiter refusal (RATE_LIMITED) do not.
|
strong |
What became of one instruction (a placement or a cancellation) an executor was asked to send.
A request of unknown outcome (INDETERMINATE) is never replayed automatically: the runner places nothing more for that instrument until the broker's order list is read and the instrument resolved, though a named cancellation may still go. (A request known not to have reached the broker, or refused for its rate limit, can be offered again; see Runner::retry_retained_targets.)
For a cancellation, ACCEPTED means the request was accepted, not that the order is gone, and a refused cancellation leaves the order as it was (resting, or filled meanwhile).
| Enumerator | |
|---|---|
| ACCEPTED | The broker accepted the instruction (for a placement, the order exists). |
| REJECTED | The broker refused the instruction (for a placement, the order does not exist); nothing needs reconciling. |
| INDETERMINATE | The outcome is unknown (see outcome_of): the request failed in transit or was cancelled, the reply could not be read, the broker answered with an HTTP 5xx, or its answer is reported as PROTOCOL. At KIS (an unrecognized reply with rt_cd not 0, such as insufficient balance), Toss (any refusal but a rate limit or a refused token) and Kiwoom (a return_code outside its documented error list) the broker's own refusals are reported as PROTOCOL, so they land here, not in REJECTED. The exception is the few order refusals the KIS and Kiwoom clients recognize (most from their demo servers, three from their real servers), which are REJECTED. Nothing more is placed for that instrument until the broker's order list has been read and the instrument resolved. |
| UNAVAILABLE | Local machinery failed (such as the order journal not being writable), so nothing was sent. The runner stops sending (strategy::HaltReason::LOCAL_FAILURE) until Runner::resume_after_local_failure, since every later order would fail the same way. |
| REFUSED_LOCALLY | The binding refused the instruction before sending it (such as an idempotency key at a broker without one, or a cancellation of an order the broker has no reference for). No request was counted against the rate limit (for a placement, the order does not exist), and the runner keeps trading. |
Definition at line 30 of file execution.hpp.
|
strong |
What an operator asks for when stopping a running loop.
| Intent | Stops sending | Requests cancellation of resting orders | Requests closing orders |
|---|---|---|---|
| QUIESCE | yes | no | no |
| WITHDRAW | yes | yes | no |
| FLATTEN | yes | yes | yes |
Only "stops sending" is certain. Cancellations and closing orders are requests: an accepted cancellation can still be rejected later, and an accepted closing order may not have filled. runner::LoopReport counts what was accepted and closing_complete() says whether everything was; the broker's order list and holdings say what is left.
|
strong |
Why the runner held back a whole reconciliation plan (cancellations and placements) before sending any of it.
| Enumerator | |
|---|---|
| PORTFOLIO_ABSENT | No holdings have been read, so the plan was computed against an account that looks flat (and could cancel orders protecting a real holding). |
| PORTFOLIO_STALE | The holdings the plan was computed from are older than the configured maximum age. |
| PLACEMENT_HELD | A hold stops placements, so the plan's cancellations are held too (a reprice must not become a bare cancellation). |
| PORTFOLIO_SUPERSEDED | The working-order listing is newer than the holdings the plan was sized against (see strategy::Portfolio::listing_newer_than_holdings). A TargetPosition withheld for this, or as absent or stale, is kept and planned again once newer holdings arrive (Runner::retry_retained_targets); an OrderIntent is not. |
| AWAITING_CONFIRMATION | A serialized runner may not place on the instrument yet, so the plan's cancellations are held too: an order there is not yet accounted for, the runner was not recovered, or holdings cannot serve as the next order's baseline. The detail says which; a TargetPosition is kept and planned again after a newer holdings read. See Runner::allow_overlapping_orders. |
Definition at line 299 of file execution.hpp.
|
strong |
Why the runner held back a planned order without sending it.
| Enumerator | |
|---|---|
| RECONCILE_REQUIRED | An earlier instruction for this instrument has an unknown outcome; nothing is sent until the broker's order list resolves it. |
| LOCAL_FAILURE | Local machinery cannot send (see SendOutcome::UNAVAILABLE). |
| AWAITING_CONFIRMATION | A serialized runner already has an order on this instrument that holdings have not yet accounted for (see Runner::allow_overlapping_orders). |
Definition at line 263 of file execution.hpp.
|
inline |
Tests whether any instruction is a placement a listing could decide (which needs history, not only working orders).
| open | The instructions. |
Definition at line 1077 of file reconcile_orders.hpp.
Referenced by any_placement().
|
inlinenoexcept |
Compares an enumerated attribute of a row with the instruction's.
| Enum | The enumeration (it must have an UNKNOWN value). |
| row_value | The row's value. |
| entry_value | The instruction's value. |
Definition at line 259 of file reconcile_orders.hpp.
Referenced by attribute_evidence(), dates_listed_order(), row_corresponds(), and row_might_correspond().
|
inlinenoexcept |
Tests whether an error is the broker's rate-limit refusal (such as KIS EGW00201).
It is REJECTED, but the refusal is about the moment, so Runner keeps the instruction for a later pass. (On an order, a KIS rate-limit refusal sent with an HTTP status of 500 or more is HTTP, so it is INDETERMINATE.)
| error | The error. |
Definition at line 190 of file execution.hpp.
Referenced by broker_rate_limited().
|
inlinenoexcept |
Tests whether an error means the broker could not be reached (as opposed to the binding refusing the instruction itself).
Both are REFUSED_LOCALLY, but a connection problem (TRANSPORT, CANCELLED, a failed token request) may clear, so Runner keeps the instruction for a later pass; a client's own validation (INVALID_ARGUMENT) would refuse it again.
| error | The error. |
Definition at line 176 of file execution.hpp.
Referenced by broker_unreachable().
|
inline |
Returns the UTC calendar date of an instant.
| at | The instant. |
Definition at line 1204 of file reconcile_orders.hpp.
Referenced by date_of(), and history_range_for().
|
inline |
Tests whether a dated history row is the order a listing row whose date was assumed shows: the same order id and instrument at the same time of day, nothing either row states disagrees (side, quantity, type, time in force, session, trigger, venue), and the price is stated alike on both (both absent, or equal).
| assumed | The listing row (OrderSnapshot::ordered_date_assumed_). |
| row | The history row. |
Definition at line 1111 of file reconcile_orders.hpp.
Referenced by dates_listed_order().
|
inline |
Makes a report that decides nothing, for a sweep that could not see a complete listing.
Matching a partial listing could read a missing row as NOT_PLACED.
| open | The unresolved instructions. |
| detail | Why nothing was decided. |
Definition at line 1044 of file reconcile_orders.hpp.
Referenced by decide_nothing().
|
inline |
Removes the rows that could be another placement's order as well.
A row could be another placement's when row_corresponds says it is that placement's order (the same instrument, side and shape, dated inside that placement's own send window: from its PENDING line to the answer of that send, ACCEPTED or INDETERMINATE, or maximum_request_ after the PENDING line where no such answer was written), or when row_might_correspond says it may be: nothing disagrees and something could not be compared, such as the route of a line written before routes were recorded. Whatever order id the journal records for that placement plays no part: a sweep may have given it another order's number. A placement the broker or the binding refused (REJECTED) has no order and claims no row.
For a search that acts only on finding an order (live::SessionSource uses it where it looks again for an order a serialized runner still owes): what is left can be matched to the instruction with no other placement in the journal as a rival, and an order sent beside another of the same shape stays unfound. It is not for a sweep whose negative verdict is acted on.
| rows | The rows to filter. |
| replay | The journal's contents. |
| matching | The instructions about to be matched, which are not rivals of each other here. |
| window | The allowances. |
Definition at line 815 of file reconcile_orders.hpp.
Referenced by drop_rows_fitting_another_placement().
|
inlineconstexprnoexcept |
Tests whether a request that was never sent may be tried again on a later pass, by its error's category.
Only a client's own validation (INVALID_ARGUMENT) would refuse it again; every other category may clear (a connection, a token, a pacing hold).
| category | The category. |
Definition at line 150 of file execution.hpp.
Referenced by broker_unreachable(), and error_retries_when_unsent().
|
inlineconstexprnoexcept |
Tests whether a piece of evidence confirms the row is the instruction's order.
| evidence | The evidence. |
Definition at line 204 of file reconcile_orders.hpp.
Referenced by evidence_confirms(), and row_corresponds().
|
inlineconstexprnoexcept |
Tests whether a piece of evidence rules the row out.
| evidence | The evidence. |
Definition at line 220 of file reconcile_orders.hpp.
Referenced by dates_listed_order(), evidence_contradicts(), and row_might_correspond().
|
inlineconstexprnoexcept |
Tests whether a piece of evidence leaves the question open, so the row might still be the order and cannot count toward proving it absent.
| evidence | The evidence. |
Definition at line 237 of file reconcile_orders.hpp.
Referenced by evidence_leaves_open(), and row_might_correspond().
|
inline |
Tests whether two rows are established copies of one order: the same order id and instrument, and the same order time on both.
| a | The first row. |
| b | The second row. |
Definition at line 1097 of file reconcile_orders.hpp.
Referenced by exact_copy(), and merge_dated_history().
|
inline |
Returns the date range an order-history inquiry must cover for some instructions.
Widened by a day at each end, since the instants are UTC and brokers date orders in their own market's time.
| open | The instructions; must not be empty. |
| window | The allowances. |
Definition at line 1230 of file reconcile_orders.hpp.
Referenced by history_range_for().
|
inline |
Returns the last instant an instruction could have reached the broker.
| instruction | The instruction. |
| window | The allowances. |
Definition at line 151 of file reconcile_orders.hpp.
Referenced by history_range_for(), instruction_sent_by(), match_window_closed(), and time_evidence().
|
inlinenoexcept |
Parses an action's name.
| text | The name. |
Definition at line 82 of file journal.hpp.
Referenced by journal_action_from(), journal_entry_from_line(), and salvage_journal_line().
|
inlineconstexprnoexcept |
Tests whether recovery matches an instruction of this action by the broker's order id it names, rather than by its attributes.
| action | The action. |
Definition at line 67 of file journal.hpp.
Referenced by journal_action_matches_by_order_id(), and unresolvable_reason().
|
inlineconstexprnoexcept |
Returns an action's name as written to the journal ("place", "cancel").
| action | The action. |
Definition at line 45 of file journal.hpp.
Referenced by journal_action_from(), journal_action_name(), and journal_entry_to_line().
|
inline |
Parses one journal line.
| line | The line, without its newline. |
Definition at line 652 of file file_journal.hpp.
Referenced by journal_entry_from_line(), and parse_journal_bytes().
|
inline |
Renders one entry as a journal line: a JSON object ending in a CRC-32 checksum member.
| entry | The entry. |
Definition at line 557 of file file_journal.hpp.
Referenced by algotradelib::runner::FileJournal::append(), and journal_entry_to_line().
|
inlineconstexprnoexcept |
Returns the format name in a journal header's journal field.
Definition at line 487 of file file_journal.hpp.
Referenced by journal_format_name(), journal_header_line(), and journal_header_scope().
|
inline |
Tests whether a header line declares that every entry after it carries a checksum.
| line | The line. |
Definition at line 511 of file file_journal.hpp.
Referenced by journal_header_declares_checksums(), and parse_journal_bytes().
|
inline |
Renders the header line a journal file starts with, naming its broker and account.
| scope | The broker and account. |
Definition at line 496 of file file_journal.hpp.
Referenced by journal_header_line().
|
inline |
Returns the scope a header line declares.
| line | The line. |
Definition at line 527 of file file_journal.hpp.
Referenced by journal_header_scope(), and parse_journal_bytes().
|
inlineconstexprnoexcept |
Tests whether a line with this outcome answers the send itself (the broker's reply, or its absence), rather than a later account of it.
| outcome | The outcome. |
Definition at line 234 of file journal.hpp.
Referenced by journal_outcome_answers_send(), and recorded_placements().
|
inlinenoexcept |
Parses an outcome's name.
| text | The name. |
Definition at line 178 of file journal.hpp.
Referenced by journal_entry_from_line(), and journal_outcome_from().
|
inlineconstexprnoexcept |
Tests whether a line with this outcome is a serialized runner's closing account of a placement (it confirmed it, or held it for an operator), which repeats none of the instruction's shape.
| outcome | The outcome. |
Definition at line 295 of file journal.hpp.
Referenced by journal_outcome_is_closing_account().
|
inlineconstexprnoexcept |
Tests whether an outcome answers a PENDING line.
| outcome | The outcome. |
Definition at line 213 of file journal.hpp.
Referenced by journal_outcome_is_terminal(), placements_of(), and unresolved_instructions().
|
inlineconstexprnoexcept |
Tests whether a line with this outcome leaves its instruction's fate unknown, so recovery must still settle it.
| outcome | The outcome. |
Definition at line 338 of file journal.hpp.
Referenced by journal_outcome_leaves_open(), placements_of(), and unresolved_instructions().
|
inlineconstexprnoexcept |
Returns an outcome's name as written to the journal ("pending", ...).
| outcome | The outcome. |
Definition at line 148 of file journal.hpp.
Referenced by journal_entry_to_line(), journal_outcome_from(), and journal_outcome_name().
|
inlineconstexprnoexcept |
Tests whether a line with this outcome may carry the broker's id for the order.
| outcome | The outcome. |
Definition at line 254 of file journal.hpp.
Referenced by journal_outcome_names_order(), and recorded_placements().
|
inlineconstexprnoexcept |
Maps a send outcome to the journal outcome that records it.
| outcome | The send outcome. |
Definition at line 190 of file journal.hpp.
Referenced by algotradelib::runner::JournalingExecutor< Inner, Journal, Clock >::cancel(), journal_outcome_of(), and algotradelib::runner::JournalingExecutor< Inner, Journal, Clock >::place().
|
inlineconstexprnoexcept |
Tests whether a line with this outcome says the instruction was refused, so it does not exist.
| outcome | The outcome. |
Definition at line 274 of file journal.hpp.
Referenced by journal_outcome_refuses(), and recorded_placements().
|
inlineconstexprnoexcept |
Tests whether a line with this outcome is written with requires_operator_ by design, so the flag is not damage.
| outcome | The outcome. |
Definition at line 316 of file journal.hpp.
Referenced by journal_outcome_requires_operator().
|
inlineconstexprnoexcept |
Returns a status's lowercase name, such as "unreadable".
| status | The status. |
Definition at line 447 of file journal.hpp.
Referenced by journal_read_status_name().
|
inline |
Decides what a broker listing says about one instruction of unknown outcome.
A cancellation is matched by the broker order id it names (AMBIGUOUS only if two rows carry that id); a placement by attributes (row_corresponds, row_might_correspond). An operator-only or unresolvable (unresolvable_reason) instruction is NEEDS_OPERATOR.
For a placement, a row that fits it but is the order of another placement in recorded (recorded_owner) is no candidate, and makes the verdict AMBIGUOUS whatever else fits: an operator decides, because the record may itself be a sweep's mistaken name.
| instruction | The instruction. |
| rows | The listing (working orders and history). |
| recorded | The journal's placements with a recorded order id (recorded_placements). |
| now | The current instant. |
| window | The allowances. |
Definition at line 626 of file reconcile_orders.hpp.
Referenced by match_against(), and match_against().
|
inline |
Decides what a broker listing says about one instruction, with no other placement's recorded order to set aside: every row that fits is a candidate.
For a listing already filtered of other placements' rows. A sweep over the journal's open instructions should pass recorded_placements (the other overload), as reconcile_against does.
| instruction | The instruction. |
| rows | The listing (working orders and history). |
| now | The current instant. |
| window | The allowances. |
Definition at line 784 of file reconcile_orders.hpp.
|
inlineconstexprnoexcept |
Returns a verdict's lowercase name, such as "not_placed", for logs.
| verdict | The verdict. |
Definition at line 64 of file reconcile_orders.hpp.
Referenced by match_verdict_name().
|
inlineconstexprnoexcept |
Tests whether a verdict settles the question.
| verdict | The verdict. |
Definition at line 85 of file reconcile_orders.hpp.
Referenced by match_verdict_resolves().
|
inline |
Tests whether a missing row may now be read as "not placed".
| instruction | The instruction. |
| now | The current instant. |
| window | The allowances. |
Definition at line 166 of file reconcile_orders.hpp.
Referenced by match_window_closed().
|
inline |
Adds history rows to a working-order listing, dropping established copies (exact_copy) and listing rows a history row dates; for brokers whose history takes no range (Kiwoom, Toss).
A listing row whose date was assumed (OrderSnapshot::ordered_date_assumed_) is dropped where a history row dates the same order (dates_listed_order): the history row stands for it, on its own evidence, and nothing of the listing row is carried over. An uncertain row is kept, at the cost of a possible AMBIGUOUS. An adapter should stamp ordered_at_ the same way on working and history rows of one order, or both are kept.
| into | The listing, extended in place. |
| rows | The history rows. |
Definition at line 1146 of file reconcile_orders.hpp.
Referenced by merge_dated_history().
|
inline |
Adds rows to a listing, skipping any whose order id is already there.
| into | The listing, extended in place. |
| rows | The rows to add. |
Definition at line 1181 of file reconcile_orders.hpp.
Referenced by merge_rows().
|
inlineconstexprnoexcept |
Tests whether an order in this state counts toward the loop's owed-order time limit (PollingLoop::set_owed_order_limit).
| state | The state. |
Definition at line 411 of file execution.hpp.
Referenced by obligation_is_unaccounted().
|
inlineconstexprnoexcept |
Tests whether only an operator can settle an obligation in this state, so no read of the broker's lists can.
| state | The state. |
Definition at line 429 of file execution.hpp.
Referenced by obligation_needs_operator().
|
inlineconstexprnoexcept |
Returns a lowercase name for a state, such as "named", for logs.
| state | The state. |
Definition at line 464 of file execution.hpp.
Referenced by obligation_state_name().
|
inlineconstexprnoexcept |
Returns how much an obligation state weighs when one instrument owes several orders: the instrument reports the heaviest.
| state | The state. |
Definition at line 391 of file execution.hpp.
Referenced by algotradelib::runner::Runner< Strategy, CapsType, Tag, Executor >::obligation_state(), and obligation_weight().
|
inline |
Classifies an error from an order request: did the order come to exist?
Doubtful cases are classified as unknown, which costs a reconciliation, rather than as refused, which could leave a live order unwatched.
| error | The error. |
Definition at line 117 of file execution.hpp.
Referenced by algotradelib::live::SessionExecutor< Session >::cancel(), outcome_of(), and algotradelib::live::SessionExecutor< Session >::place().
|
inline |
Parses a journal's bytes, salvaging a torn final line.
Unparsed lines are counted and a torn last line is salvaged as an operator-only entry: the instruction it names, or, when it names no instrument, the entry unattributable_journal_entry makes, on which recovery halts all trading. An empty line, or a header that is not the first line, counts as damage.
| bytes | The bytes and read status; a status other than READ is passed through. |
Definition at line 1013 of file file_journal.hpp.
Referenced by parse_journal_bytes(), and read_journal_file().
|
inline |
Returns the placements with the given journal ids, each with the span in which it may have reached the broker, whatever was written about them since.
For a placement a sweep closed without finding its order and that a serialized runner still owes (Runner::obligations): unresolved_instructions no longer lists it, and this gives a later sweep the same instruction and span to match against.
| replay | The journal's contents. |
| ids | The journal ids wanted. |
Definition at line 592 of file journal.hpp.
Referenced by placements_of().
|
inlineconstexprnoexcept |
Returns a poll kind's lowercase name, such as "working_orders".
| kind | The kind. |
Definition at line 66 of file loop.hpp.
Referenced by poll_kind_name(), and live_program::print_loop().
|
inlineconstexprnoexcept |
Returns an outcome's lowercase name, such as "rate_limited".
| outcome | The outcome. |
Definition at line 141 of file loop.hpp.
Referenced by poll_outcome_name().
|
inline |
Reads a journal file's bytes, without opening it for appending.
| path | The file. |
Definition at line 966 of file file_journal.hpp.
Referenced by read_journal_bytes(), and read_journal_file().
|
inline |
Reads and parses a journal file.
| path | The file. |
Definition at line 1111 of file file_journal.hpp.
Referenced by read_journal_file(), and algotradelib::runner::FileJournal::replay().
| ReconcileReport algotradelib::runner::reconcile_against | ( | const std::vector< OpenInstruction > & | open, |
| const std::vector< OrderSnapshot > & | rows, | ||
| const JournalReplay & | replay, | ||
| std::chrono::system_clock::time_point | now, | ||
| IndeterminacyLedger & | ledger, | ||
| Journal & | journal, | ||
| const MatchWindow & | window = {}, | ||
| std::string_view | unplaced_note = {} ) |
Resolves what a broker listing settles, records it in the journal, and clears the ledger for each instrument whose instructions are all decided.
An instrument is cleared only when every instruction for it is MATCHED or NOT_PLACED, and only after the resolution is written. Ledger entries the journal knows nothing about are left. A row the journal records as another placement's order is set aside (match_against).
| Journal | The journal type. |
| open | The unresolved instructions. |
| rows | The listing, which must be complete. |
| replay | The journal's contents, which open was taken from. |
| now | The current instant. |
| ledger | The ledger to clear. |
| journal | The journal to record resolutions in. |
| window | The allowances. |
| unplaced_note | Text added to the journal detail of a placement found NOT_PLACED: what the caller does with that finding. |
Definition at line 937 of file reconcile_orders.hpp.
Referenced by reconcile_against(), and reconcile_against().
| ReconcileReport algotradelib::runner::reconcile_against | ( | const std::vector< OpenInstruction > & | open, |
| const std::vector< OrderSnapshot > & | rows, | ||
| std::chrono::system_clock::time_point | now, | ||
| IndeterminacyLedger & | ledger, | ||
| Journal & | journal, | ||
| const MatchWindow & | window = {}, | ||
| std::string_view | unplaced_note = {} ) |
Resolves what a broker listing settles, reading the journal's contents from journal; see the other overload.
| Journal | The journal type; it must provide replay(). |
| open | The unresolved instructions. |
| rows | The listing, which must be complete. |
| now | The current instant. |
| ledger | The ledger to clear. |
| journal | The journal to read and to record resolutions in. |
| window | The allowances. |
| unplaced_note | Text added to the journal detail of a placement found NOT_PLACED. |
Definition at line 1023 of file reconcile_orders.hpp.
|
inline |
Returns the recorded placement whose order a row is: the row carries the order id the journal records for it and fits that placement's own send (row_corresponds or row_might_correspond).
The send window matters because some brokers reuse order numbers on another day.
| instruction | The instruction being matched, which is never its own rival. |
| row | The row. |
| recorded | The placements with recorded ids (recorded_placements). |
| window | The allowances. |
Definition at line 588 of file reconcile_orders.hpp.
Referenced by recorded_owner().
|
inline |
Returns the placements a journal records an order id for, each with the span of its send.
The id is the one an ACCEPTED line (the broker's reply) or a RESOLVED line (a sweep's name) records. The span runs from the placement's first line to the line that answered the send (ACCEPTED, REJECTED or INDETERMINATE). A placement with no such id, a refused one and an operator-only one are left out.
| replay | The journal's contents. |
Definition at line 535 of file reconcile_orders.hpp.
Referenced by recorded_placements().
| RecoveryReport algotradelib::runner::recover_into | ( | const Journal & | journal, |
| IndeterminacyLedger & | ledger ) |
Reads a journal and marks the ledger for what it left owed; see the other overload.
| Journal | The journal type. |
| journal | The journal. |
| ledger | The ledger to mark. |
Definition at line 1330 of file reconcile_orders.hpp.
|
inline |
Marks the ledger for every instrument a journal left an instruction of unknown outcome for.
It halts nothing. Prefer recover_runner; with a bare ledger, stop trading yourself if the report has unattributable_, unreadable_lines_ or unreadable_file_ set: then the ledger can be empty while the journal's contents are unknown.
| replay | The journal's contents. |
| ledger | The ledger to mark. |
Definition at line 1291 of file reconcile_orders.hpp.
Referenced by recover_into(), recover_into(), and recover_runner().
| RecoveryReport algotradelib::runner::recover_runner | ( | Runner & | runner_instance, |
| const Journal & | journal ) |
Recovers a journal into a runner at startup: marks each instrument left owed, restores a serialized runner's orders not yet accounted for (Runner::restore_obligations), and halts the runner when damage names no instrument.
The runner is halted (LOCAL_FAILURE) when a torn line names no instrument, a complete line does not parse, or the file cannot be read. An operator reads the broker's order list and calls Runner::resume_after_local_failure.
| Runner | The runner type. |
| Journal | The journal type. |
| runner_instance | The runner. |
| journal | The journal. |
Definition at line 1350 of file reconcile_orders.hpp.
Referenced by recover_runner().
|
inline |
Makes the RESOLVED journal line that records a sweep's verdict.
| instruction | The instruction. |
| match | The verdict. |
| now | When it was resolved. |
Definition at line 901 of file reconcile_orders.hpp.
Referenced by resolution_entry().
|
inline |
Compares a row's venue with the route the instruction recorded.
The recorded route is where the order actually went (an unrouted KIS order reaches KRX).
| instruction | The instruction. |
| row | The row. |
Definition at line 337 of file reconcile_orders.hpp.
Referenced by route_evidence(), row_corresponds(), and row_might_correspond().
|
inline |
Tests whether a row is established to be an instruction's order.
Matched by attributes, since no broker lists a client order id: the instrument, side and type (both known), quantity and price must match, and time in force, session, trigger, route and time must each CONFIRMS.
| instruction | The instruction. |
| row | The row. |
| window | The allowances. |
Definition at line 368 of file reconcile_orders.hpp.
Referenced by recorded_owner(), and row_corresponds().
|
inline |
Tests whether a row might be an instruction's order although some attributes could not be read (such as an order type outside the broker's published table).
Such a row makes the verdict AMBIGUOUS (an operator decides) rather than NOT_PLACED. It compares instrument, side, quantity and time, and the price when both order types are known, and rules the row out on any positive disagreement.
| instruction | The instruction. |
| row | The row. |
| window | The allowances. |
Definition at line 423 of file reconcile_orders.hpp.
Referenced by recorded_owner(), and row_might_correspond().
|
inline |
Tests whether a journal line has a field that was written completely but cannot be read.
Used when salvaging a torn line: a value followed by a comma was written to completion, so failing to read it is damage, not the truncation that cut the line's tail.
| line | The journal line. |
| key | The field name. |
Definition at line 850 of file file_journal.hpp.
Referenced by salvage_damaged(), and salvage_journal_line().
|
inline |
Salvages a torn final line into an entry nothing can resolve automatically.
The entry's id is suffixed so it pairs with no PENDING line, its outcome is PENDING whatever the text said, and it is operator-only. An instrument, side, type, condition or session field that was written in full but cannot be read leaves no instrument; a number that cannot be read is left absent (the quantity at its default) and a route unknown, and the instrument is kept.
| line | The torn line. |
Definition at line 870 of file file_journal.hpp.
Referenced by parse_journal_bytes(), and salvage_journal_line().
|
inlineconstexprnoexcept |
Tests whether an outcome means the runner's own machinery failed (not the broker, and not a check that refused the order), which stops it from sending until someone looks.
| outcome | The outcome. |
Definition at line 218 of file execution.hpp.
Referenced by send_outcome_is_local_failure().
|
inlineconstexprnoexcept |
Returns a lowercase name for an outcome, such as "indeterminate", for logs.
| outcome | The outcome. |
Definition at line 80 of file execution.hpp.
Referenced by send_outcome_name().
|
inlineconstexprnoexcept |
Tests whether an outcome means a request reached the broker.
| outcome | The outcome. |
Definition at line 199 of file execution.hpp.
Referenced by send_outcome_reached_broker().
|
inlineconstexprnoexcept |
Tests whether a stop intent asks for a closing pass (cancellations, and for FLATTEN closing orders) after sending stops, and so needs the broker's order list read first.
| intent | The intent. |
Definition at line 114 of file stop.hpp.
Referenced by stop_intent_closes().
|
inlineconstexprnoexcept |
Tests whether a stop intent closes positions with market orders, after withdrawing the working orders.
| intent | The intent. |
Definition at line 131 of file stop.hpp.
Referenced by stop_intent_closes_positions().
|
inlineconstexprnoexcept |
Tests whether one intent does everything another would.
| held | The intent in force. |
| candidate | The intent requested. |
Definition at line 148 of file stop.hpp.
Referenced by stop_intent_covers().
|
inlinenoexcept |
Parses an intent's name.
| text | "quiesce", "withdraw" or "flatten". |
Definition at line 83 of file stop.hpp.
Referenced by algotradelib::runner::FileStopChannel::poll(), and stop_intent_from().
|
inlineconstexprnoexcept |
Returns a lowercase name for an intent, as written in the control file ("withdraw").
| intent | The intent. |
Definition at line 61 of file stop.hpp.
Referenced by live_program::print_loop(), stop_intent_from(), and stop_intent_name().
|
inlineconstexprnoexcept |
Returns an intent's strength: a stronger intent does everything a weaker one does.
Stated per intent rather than read from the declaration order. Async-signal-safe (StopSource::request calls it from a handler).
| intent | The intent. |
Definition at line 96 of file stop.hpp.
Referenced by algotradelib::runner::StopSource::request(), stop_intent_covers(), and stop_intent_strength().
|
inline |
Compares a row's order time with the window in which the instruction was sent.
A row with no time is judged on its other attributes (CONFIRMS here), because every KIS real-account working-order row lacks a date. So an identical order placed through another channel, while this runner's own order is not listed, can be matched to it; when both are listed the result is AMBIGUOUS. A row whose date the adapter assumed (OrderSnapshot::ordered_date_assumed_) may be another day's order at the same time of day, so it establishes nothing (ABSENT), whether or not its time could be read.
| instruction | The instruction. |
| row | The row. |
| window | The allowances. |
Definition at line 312 of file reconcile_orders.hpp.
Referenced by row_corresponds(), row_might_correspond(), and time_evidence().
|
inline |
Compares a row's trigger price with the instruction's.
| Row | Entry | Evidence |
|---|---|---|
| t | t | CONFIRMS |
| t | u | CONTRADICTS |
| none | none | CONFIRMS |
| none | t | ABSENT (the broker may not have reported it) |
| t | none | ABSENT (the broker's row contradicts its own type) |
| row_trigger | The row's trigger. |
| entry_trigger | The instruction's trigger. |
Definition at line 281 of file reconcile_orders.hpp.
Referenced by dates_listed_order(), row_corresponds(), row_might_correspond(), and trigger_evidence().
|
inline |
Makes the entry that stands for a torn line naming no instrument.
It is PENDING, operator-only and names no instrument; recovery halts all trading on it.
| line | The torn line (quoted in the detail). |
Definition at line 632 of file file_journal.hpp.
Referenced by journal_entry_from_line(), parse_journal_bytes(), salvage_journal_line(), and unattributable_journal_entry().
|
inline |
Returns why an instruction cannot be resolved from a broker listing.
A cancellation with no order id, or a placement whose recorded price or trigger price does not fit its type (missing where required, or present where not taken), would otherwise read as absent. Such an instruction needs an operator (match_against returns NEEDS_OPERATOR).
| entry | The journalled instruction. |
Definition at line 485 of file reconcile_orders.hpp.
Referenced by unresolvable_reason().
|
inline |
Lists the instructions whose outcome is unknown, in the order they were opened.
A PENDING line with no answer, or one answered INDETERMINATE, is listed; ACCEPTED and REJECTED answers resolve it. An answer is paired with the first open line carrying its id, so ids must be unique (see JournalingExecutor::set_id_prefix). An INDETERMINATE line whose PENDING line is missing (a rotated or edited file) is listed too.
| replay | The journal's contents. |
Definition at line 537 of file journal.hpp.
Referenced by recover_into(), and unresolved_instructions().
|
inlineconstexprnoexcept |
Returns a lowercase name for a reason, such as "portfolio_stale", for logs.
| reason | The reason. |
Definition at line 334 of file execution.hpp.
Referenced by withheld_plan_reason_name().
|
inlineconstexprnoexcept |
Returns a lowercase name for a reason, such as "reconcile_required", for logs.
| reason | The reason. |
Definition at line 283 of file execution.hpp.
Referenced by withheld_reason_name().
|
inlineconstexpr |
Every JournalAction, in declaration order.
Definition at line 38 of file journal.hpp.
Referenced by journal_action_from().
|
inlineconstexpr |
Every JournalOutcome, in declaration order.
Definition at line 133 of file journal.hpp.
Referenced by journal_outcome_from().
|
inlineconstexpr |
Every poll kind, in the order an iteration polls them.
|
inlineconstexpr |
Every PollOutcome, in declaration order.
|
inlineconstexpr |
Every SendOutcome, in declaration order.
Definition at line 67 of file execution.hpp.
|
inlineconstexpr |
Every StopIntent, in declaration order.
Definition at line 50 of file stop.hpp.
Referenced by stop_intent_from().
|
inlineconstexpr |