algotradelib 0.0.0.9000
C++ header-only library for algorithmic trading
Loading...
Searching...
No Matches
algotradelib::runner Namespace Reference

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.

Detailed Description

Runs a strategy: the runner, the polling loop, the order journal, and stopping.

Typedef Documentation

◆ DryRunner

template<typename Strategy, typename CapsType = strategy::NoCaps>
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).

runner::DryRunner<MyStrategy> dry(MyStrategy{}, limits);
dry.context().set_instrument(reference);
const auto report = dry.feed(strategy::make_bar_event(id, BarInterval::ONE_DAY, BarStamp::CLOSE, bar));
// report.would_place_ holds what would have been sent
Runner< Strategy, CapsType, DryTag, RecordingExecutor< DryTag > > DryRunner
A runner that sends nothing: handlers fire and instructions are recorded by a RecordingExecutor.
Definition runner.hpp:4524
BarEvent make_bar_event(InstrumentId instrument, BarInterval interval, BarStamp stamp, Bar bar)
Makes a bar event, computing its period_end_ with bar_period_end.
Definition event.hpp:273
@ CLOSE
The timestamp is the instant the period ended.
Template Parameters
StrategyThe strategy type.
CapsTypeThe broker capabilities the strategy sees.

Definition at line 4524 of file runner.hpp.

◆ Instruction

template<typename Broker>
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.

Template Parameters
BrokerThe broker tag of the cancellation's order reference.

Definition at line 45 of file context.hpp.

◆ RouteEvidence

Evidence, under the name used for the route comparison.

Definition at line 249 of file reconcile_orders.hpp.

Enumeration Type Documentation

◆ Evidence

enum class algotradelib::runner::Evidence
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.

◆ JournalAction

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.

◆ JournalOutcome

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.

◆ JournalReadStatus

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.

◆ MarketPhase

Where the clock stands relative to the trading session.

Whether a date trades comes from the broker's calendar; the intraday open and close come from the configured SessionWindow.

Definition at line 30 of file event.hpp.

◆ MatchVerdict

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.

◆ ObligationState

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.

◆ PollKind

enum class algotradelib::runner::PollKind
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.

Note
A source must install the calendar during this poll only, and must not feed the runner from it (live::SessionSource::poll_calendar does exactly that). A call that both sends an order and changes the phase is counted (LoopReport::sends_under_a_revised_phase_).
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.

Definition at line 30 of file loop.hpp.

◆ PollOutcome

What became of one poll.

Only FAILED counts toward FailurePolicy; nothing new (UNCHANGED) and a rate-limiter refusal (RATE_LIMITED) do not.

Enumerator
UPDATED 

New data arrived and was fed to the runner, or installed in it (a calendar, price bands).

UNCHANGED 

The poll succeeded and there was nothing new.

FAILED 

The poll failed; counted toward the failure budget.

RATE_LIMITED 

The rate limiter refused the poll; not counted as a failure.

Definition at line 117 of file loop.hpp.

◆ SendOutcome

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.

◆ StopIntent

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.

Enumerator
QUIESCE 

Stop sending new orders; nothing is cancelled or closed. The default, and what a signal means.

WITHDRAW 

Quiesce, then ask the broker to cancel the working orders.

Each cancellation can itself have an unknown outcome; read the order list afterwards.

FLATTEN 

Withdraw, then ask the broker to close the positions with market orders.

Never what a signal means. Being flat is shown by a later holdings read, not by this intent.

Definition at line 29 of file stop.hpp.

◆ WithheldPlanReason

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.

◆ WithheldReason

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.

Function Documentation

◆ any_placement()

bool algotradelib::runner::any_placement ( const std::vector< OpenInstruction > & open)
inline

Tests whether any instruction is a placement a listing could decide (which needs history, not only working orders).

Parameters
openThe instructions.
Returns
true if any is a PLACE that is not operator-only.

Definition at line 1077 of file reconcile_orders.hpp.

Referenced by any_placement().

◆ attribute_evidence()

template<typename Enum>
Evidence algotradelib::runner::attribute_evidence ( Enum row_value,
Enum entry_value )
inlinenoexcept

Compares an enumerated attribute of a row with the instruction's.

Template Parameters
EnumThe enumeration (it must have an UNKNOWN value).
Parameters
row_valueThe row's value.
entry_valueThe instruction's value.
Returns
ABSENT if either is UNKNOWN; otherwise CONFIRMS or CONTRADICTS.

Definition at line 259 of file reconcile_orders.hpp.

Referenced by attribute_evidence(), dates_listed_order(), row_corresponds(), and row_might_correspond().

◆ broker_rate_limited()

bool algotradelib::runner::broker_rate_limited ( const BrokerError & error)
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.)

Parameters
errorThe error.
Returns
true if the request reached the broker and the category is RATE_LIMIT.

Definition at line 190 of file execution.hpp.

Referenced by broker_rate_limited().

◆ broker_unreachable()

bool algotradelib::runner::broker_unreachable ( const BrokerError & error)
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.

Parameters
errorThe error.
Returns
true if nothing was sent and the category is not INVALID_ARGUMENT.

Definition at line 176 of file execution.hpp.

Referenced by broker_unreachable().

◆ date_of()

Date algotradelib::runner::date_of ( std::chrono::system_clock::time_point at)
inline

Returns the UTC calendar date of an instant.

Parameters
atThe instant.
Returns
The date.

Definition at line 1204 of file reconcile_orders.hpp.

Referenced by date_of(), and history_range_for().

◆ dates_listed_order()

bool algotradelib::runner::dates_listed_order ( const OrderSnapshot & assumed,
const OrderSnapshot & row )
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).

Parameters
assumedThe listing row (OrderSnapshot::ordered_date_assumed_).
rowThe history row.
Returns
true if the history row dates the listed order.

Definition at line 1111 of file reconcile_orders.hpp.

Referenced by dates_listed_order().

◆ decide_nothing()

ReconcileReport algotradelib::runner::decide_nothing ( const std::vector< OpenInstruction > & open,
std::string detail )
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.

Parameters
openThe unresolved instructions.
detailWhy nothing was decided.
Returns
A report with every instruction UNDECIDED and withheld.

Definition at line 1044 of file reconcile_orders.hpp.

Referenced by decide_nothing().

◆ drop_rows_fitting_another_placement()

void algotradelib::runner::drop_rows_fitting_another_placement ( std::vector< OrderSnapshot > & rows,
const JournalReplay & replay,
const std::vector< OpenInstruction > & matching,
const MatchWindow & window = {} )
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.

Parameters
rowsThe rows to filter.
replayThe journal's contents.
matchingThe instructions about to be matched, which are not rivals of each other here.
windowThe allowances.

Definition at line 815 of file reconcile_orders.hpp.

Referenced by drop_rows_fitting_another_placement().

◆ error_retries_when_unsent()

bool algotradelib::runner::error_retries_when_unsent ( ErrorCategory category)
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).

Parameters
categoryThe category.
Returns
false for INVALID_ARGUMENT; true otherwise.

Definition at line 150 of file execution.hpp.

Referenced by broker_unreachable(), and error_retries_when_unsent().

◆ evidence_confirms()

bool algotradelib::runner::evidence_confirms ( Evidence evidence)
inlineconstexprnoexcept

Tests whether a piece of evidence confirms the row is the instruction's order.

Parameters
evidenceThe evidence.
Returns
true for CONFIRMS only.

Definition at line 204 of file reconcile_orders.hpp.

Referenced by evidence_confirms(), and row_corresponds().

◆ evidence_contradicts()

bool algotradelib::runner::evidence_contradicts ( Evidence evidence)
inlineconstexprnoexcept

Tests whether a piece of evidence rules the row out.

Parameters
evidenceThe evidence.
Returns
true for CONTRADICTS only.

Definition at line 220 of file reconcile_orders.hpp.

Referenced by dates_listed_order(), evidence_contradicts(), and row_might_correspond().

◆ evidence_leaves_open()

bool algotradelib::runner::evidence_leaves_open ( Evidence evidence)
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.

Parameters
evidenceThe evidence.
Returns
true for ABSENT only.

Definition at line 237 of file reconcile_orders.hpp.

Referenced by evidence_leaves_open(), and row_might_correspond().

◆ exact_copy()

bool algotradelib::runner::exact_copy ( const OrderSnapshot & a,
const OrderSnapshot & b )
inline

Tests whether two rows are established copies of one order: the same order id and instrument, and the same order time on both.

Parameters
aThe first row.
bThe second row.
Returns
true only if all three are stated and equal.

Definition at line 1097 of file reconcile_orders.hpp.

Referenced by exact_copy(), and merge_dated_history().

◆ history_range_for()

std::pair< Date, Date > algotradelib::runner::history_range_for ( const std::vector< OpenInstruction > & open,
const MatchWindow & window )
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.

Parameters
openThe instructions; must not be empty.
windowThe allowances.
Returns
The first and last date.

Definition at line 1230 of file reconcile_orders.hpp.

Referenced by history_range_for().

◆ instruction_sent_by()

std::chrono::system_clock::time_point algotradelib::runner::instruction_sent_by ( const OpenInstruction & instruction,
const MatchWindow & window )
inline

Returns the last instant an instruction could have reached the broker.

Parameters
instructionThe instruction.
windowThe allowances.
Returns
When its answering line was written, or its PENDING time plus maximum_request_.

Definition at line 151 of file reconcile_orders.hpp.

Referenced by history_range_for(), instruction_sent_by(), match_window_closed(), and time_evidence().

◆ journal_action_from()

std::optional< JournalAction > algotradelib::runner::journal_action_from ( std::string_view text)
inlinenoexcept

Parses an action's name.

Parameters
textThe name.
Returns
The action, or std::nullopt if text names none.

Definition at line 82 of file journal.hpp.

Referenced by journal_action_from(), journal_entry_from_line(), and salvage_journal_line().

◆ journal_action_matches_by_order_id()

bool algotradelib::runner::journal_action_matches_by_order_id ( JournalAction action)
inlineconstexprnoexcept

Tests whether recovery matches an instruction of this action by the broker's order id it names, rather than by its attributes.

Parameters
actionThe action.
Returns
true for CANCEL (it names the order it cancels); false for PLACE (matched by instrument, side, shape, quantity and time).

Definition at line 67 of file journal.hpp.

Referenced by journal_action_matches_by_order_id(), and unresolvable_reason().

◆ journal_action_name()

std::string_view algotradelib::runner::journal_action_name ( JournalAction action)
inlineconstexprnoexcept

Returns an action's name as written to the journal ("place", "cancel").

Parameters
actionThe action.
Returns
The name; empty for a value that is not a JournalAction.

Definition at line 45 of file journal.hpp.

Referenced by journal_action_from(), journal_action_name(), and journal_entry_to_line().

◆ journal_entry_from_line()

std::optional< JournalEntry > algotradelib::runner::journal_entry_from_line ( std::string_view line)
inline

Parses one journal line.

Parameters
lineThe line, without its newline.
Returns
The entry, or std::nullopt if the line is not a readable journal entry: not JSON, its action, outcome or time missing or unreadable, an unknown field, or a checksum that does not match. If a field describing the order (symbol, country, venue, side, type, quantity, or a present condition, session, price or trigger) is missing or unreadable, the entry is operator-only, names no instrument, and its id is suffixed ~damaged; it keeps its outcome. An unreadable route leaves the route unknown on an otherwise complete entry.

Definition at line 652 of file file_journal.hpp.

Referenced by journal_entry_from_line(), and parse_journal_bytes().

◆ journal_entry_to_line()

std::string algotradelib::runner::journal_entry_to_line ( const JournalEntry & entry)
inline

Renders one entry as a journal line: a JSON object ending in a CRC-32 checksum member.

Parameters
entryThe entry.
Returns
The line, without a newline.

Definition at line 557 of file file_journal.hpp.

Referenced by algotradelib::runner::FileJournal::append(), and journal_entry_to_line().

◆ journal_format_name()

std::string_view algotradelib::runner::journal_format_name ( )
inlineconstexprnoexcept

Returns the format name in a journal header's journal field.

Returns
"algotradelib-order-journal".

Definition at line 487 of file file_journal.hpp.

Referenced by journal_format_name(), journal_header_line(), and journal_header_scope().

◆ journal_header_declares_checksums()

bool algotradelib::runner::journal_header_declares_checksums ( std::string_view line)
inline

Tests whether a header line declares that every entry after it carries a checksum.

Parameters
lineThe line.
Returns
true if it declares "integrity":"crc32".

Definition at line 511 of file file_journal.hpp.

Referenced by journal_header_declares_checksums(), and parse_journal_bytes().

◆ journal_header_line()

std::string algotradelib::runner::journal_header_line ( std::string_view scope)
inline

Renders the header line a journal file starts with, naming its broker and account.

Parameters
scopeThe broker and account.
Returns
The JSON line, without a newline.

Definition at line 496 of file file_journal.hpp.

Referenced by journal_header_line().

◆ journal_header_scope()

std::optional< std::string > algotradelib::runner::journal_header_scope ( std::string_view line)
inline

Returns the scope a header line declares.

Parameters
lineThe line.
Returns
The scope, or std::nullopt if the line is not a journal header.

Definition at line 527 of file file_journal.hpp.

Referenced by journal_header_scope(), and parse_journal_bytes().

◆ journal_outcome_answers_send()

bool algotradelib::runner::journal_outcome_answers_send ( JournalOutcome outcome)
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.

Parameters
outcomeThe outcome.
Returns
true for ACCEPTED, REJECTED and INDETERMINATE.

Definition at line 234 of file journal.hpp.

Referenced by journal_outcome_answers_send(), and recorded_placements().

◆ journal_outcome_from()

std::optional< JournalOutcome > algotradelib::runner::journal_outcome_from ( std::string_view text)
inlinenoexcept

Parses an outcome's name.

Parameters
textThe name.
Returns
The outcome, or std::nullopt if text names none.

Definition at line 178 of file journal.hpp.

Referenced by journal_entry_from_line(), and journal_outcome_from().

◆ journal_outcome_is_closing_account()

bool algotradelib::runner::journal_outcome_is_closing_account ( JournalOutcome outcome)
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.

Parameters
outcomeThe outcome.
Returns
true for CONFIRMED and HELD.

Definition at line 295 of file journal.hpp.

Referenced by journal_outcome_is_closing_account().

◆ journal_outcome_is_terminal()

bool algotradelib::runner::journal_outcome_is_terminal ( JournalOutcome outcome)
inlineconstexprnoexcept

Tests whether an outcome answers a PENDING line.

Parameters
outcomeThe outcome.
Returns
true for every outcome but PENDING.

Definition at line 213 of file journal.hpp.

Referenced by journal_outcome_is_terminal(), placements_of(), and unresolved_instructions().

◆ journal_outcome_leaves_open()

bool algotradelib::runner::journal_outcome_leaves_open ( JournalOutcome outcome)
inlineconstexprnoexcept

Tests whether a line with this outcome leaves its instruction's fate unknown, so recovery must still settle it.

Parameters
outcomeThe outcome.
Returns
true for PENDING (not answered yet) and INDETERMINATE (answered, outcome unknown); false for every outcome that settles it.

Definition at line 338 of file journal.hpp.

Referenced by journal_outcome_leaves_open(), placements_of(), and unresolved_instructions().

◆ journal_outcome_name()

std::string_view algotradelib::runner::journal_outcome_name ( JournalOutcome outcome)
inlineconstexprnoexcept

Returns an outcome's name as written to the journal ("pending", ...).

Parameters
outcomeThe outcome.
Returns
The name; empty for a value that is not a JournalOutcome.

Definition at line 148 of file journal.hpp.

Referenced by journal_entry_to_line(), journal_outcome_from(), and journal_outcome_name().

◆ journal_outcome_names_order()

bool algotradelib::runner::journal_outcome_names_order ( JournalOutcome outcome)
inlineconstexprnoexcept

Tests whether a line with this outcome may carry the broker's id for the order.

Parameters
outcomeThe outcome.
Returns
true for ACCEPTED and RESOLVED.

Definition at line 254 of file journal.hpp.

Referenced by journal_outcome_names_order(), and recorded_placements().

◆ journal_outcome_of()

JournalOutcome algotradelib::runner::journal_outcome_of ( SendOutcome outcome)
inlineconstexprnoexcept

Maps a send outcome to the journal outcome that records it.

Parameters
outcomeThe send outcome.
Returns
ACCEPTED, INDETERMINATE, or REJECTED for REJECTED, UNAVAILABLE and REFUSED_LOCALLY. For a placement, REJECTED means the order does not exist; for a cancellation, only that the request was refused or not sent, which says nothing about the named order's state (it may have filled).

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().

◆ journal_outcome_refuses()

bool algotradelib::runner::journal_outcome_refuses ( JournalOutcome outcome)
inlineconstexprnoexcept

Tests whether a line with this outcome says the instruction was refused, so it does not exist.

Parameters
outcomeThe outcome.
Returns
true for REJECTED only.

Definition at line 274 of file journal.hpp.

Referenced by journal_outcome_refuses(), and recorded_placements().

◆ journal_outcome_requires_operator()

bool algotradelib::runner::journal_outcome_requires_operator ( JournalOutcome outcome)
inlineconstexprnoexcept

Tests whether a line with this outcome is written with requires_operator_ by design, so the flag is not damage.

Parameters
outcomeThe outcome.
Returns
true for HELD only.

Definition at line 316 of file journal.hpp.

Referenced by journal_outcome_requires_operator().

◆ journal_read_status_name()

std::string_view algotradelib::runner::journal_read_status_name ( JournalReadStatus status)
inlineconstexprnoexcept

Returns a status's lowercase name, such as "unreadable".

Parameters
statusThe status.
Returns
The name.

Definition at line 447 of file journal.hpp.

Referenced by journal_read_status_name().

◆ match_against() [1/2]

OrderMatch algotradelib::runner::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 = {} )
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.

Parameters
instructionThe instruction.
rowsThe listing (working orders and history).
recordedThe journal's placements with a recorded order id (recorded_placements).
nowThe current instant.
windowThe allowances.
Returns
The verdict.

Definition at line 626 of file reconcile_orders.hpp.

Referenced by match_against(), and match_against().

◆ match_against() [2/2]

OrderMatch algotradelib::runner::match_against ( const OpenInstruction & instruction,
const std::vector< OrderSnapshot > & rows,
std::chrono::system_clock::time_point now,
const MatchWindow & window = {} )
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.

Parameters
instructionThe instruction.
rowsThe listing (working orders and history).
nowThe current instant.
windowThe allowances.
Returns
The verdict.

Definition at line 784 of file reconcile_orders.hpp.

◆ match_verdict_name()

std::string_view algotradelib::runner::match_verdict_name ( MatchVerdict verdict)
inlineconstexprnoexcept

Returns a verdict's lowercase name, such as "not_placed", for logs.

Parameters
verdictThe verdict.
Returns
The name.

Definition at line 64 of file reconcile_orders.hpp.

Referenced by match_verdict_name().

◆ match_verdict_resolves()

bool algotradelib::runner::match_verdict_resolves ( MatchVerdict verdict)
inlineconstexprnoexcept

Tests whether a verdict settles the question.

Parameters
verdictThe verdict.
Returns
true for MATCHED and NOT_PLACED.

Definition at line 85 of file reconcile_orders.hpp.

Referenced by match_verdict_resolves().

◆ match_window_closed()

bool algotradelib::runner::match_window_closed ( const OpenInstruction & instruction,
std::chrono::system_clock::time_point now,
const MatchWindow & window )
inline

Tests whether a missing row may now be read as "not placed".

Parameters
instructionThe instruction.
nowThe current instant.
windowThe allowances.
Returns
true once now is past instruction_sent_by plus the clock skew and listing delay.

Definition at line 166 of file reconcile_orders.hpp.

Referenced by match_window_closed().

◆ merge_dated_history()

void algotradelib::runner::merge_dated_history ( std::vector< OrderSnapshot > & into,
const std::vector< OrderSnapshot > & rows )
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.

Parameters
intoThe listing, extended in place.
rowsThe history rows.

Definition at line 1146 of file reconcile_orders.hpp.

Referenced by merge_dated_history().

◆ merge_rows()

void algotradelib::runner::merge_rows ( std::vector< OrderSnapshot > & into,
const std::vector< OrderSnapshot > & rows )
inline

Adds rows to a listing, skipping any whose order id is already there.

Parameters
intoThe listing, extended in place.
rowsThe rows to add.

Definition at line 1181 of file reconcile_orders.hpp.

Referenced by merge_rows().

◆ obligation_is_unaccounted()

bool algotradelib::runner::obligation_is_unaccounted ( ObligationState state)
inlineconstexprnoexcept

Tests whether an order in this state counts toward the loop's owed-order time limit (PollingLoop::set_owed_order_limit).

Parameters
stateThe state.
Returns
true for UNNAMED and OPERATOR: an order nobody can account for without help.

Definition at line 411 of file execution.hpp.

Referenced by obligation_is_unaccounted().

◆ obligation_needs_operator()

bool algotradelib::runner::obligation_needs_operator ( ObligationState state)
inlineconstexprnoexcept

Tests whether only an operator can settle an obligation in this state, so no read of the broker's lists can.

Parameters
stateThe state.
Returns
true for OPERATOR only.

Definition at line 429 of file execution.hpp.

Referenced by obligation_needs_operator().

◆ obligation_state_name()

std::string_view algotradelib::runner::obligation_state_name ( ObligationState state)
inlineconstexprnoexcept

Returns a lowercase name for a state, such as "named", for logs.

Parameters
stateThe state.
Returns
The name.

Definition at line 464 of file execution.hpp.

Referenced by obligation_state_name().

◆ obligation_weight()

int algotradelib::runner::obligation_weight ( ObligationState state)
inlineconstexprnoexcept

Returns how much an obligation state weighs when one instrument owes several orders: the instrument reports the heaviest.

Parameters
stateThe state.
Returns
0 for NONE, 1 for NAMED, 2 for UNNAMED, 3 for OPERATOR.

Definition at line 391 of file execution.hpp.

Referenced by algotradelib::runner::Runner< Strategy, CapsType, Tag, Executor >::obligation_state(), and obligation_weight().

◆ outcome_of()

SendOutcome algotradelib::runner::outcome_of ( const BrokerError & error)
inline

Classifies an error from an order request: did the order come to exist?

  • REFUSED_LOCALLY when reached_broker_ is false (nothing was sent), whatever the category;
  • INDETERMINATE for TRANSPORT, CANCELLED (a local timeout says nothing about whether the request went out), PROTOCOL (an unreadable reply may have been an acknowledgement; at KIS, Toss and Kiwoom this also covers most of the broker's own refusals, whatever http_status_ the reply carried), HTTP with a status of 500 or more, and any unknown category;
  • REJECTED for HTTP with a status below 500, AUTHENTICATION, RATE_LIMIT and INVALID_ARGUMENT.

Doubtful cases are classified as unknown, which costs a reconciliation, rather than as refused, which could leave a live order unwatched.

Parameters
errorThe error.
Returns
The outcome.

Definition at line 117 of file execution.hpp.

Referenced by algotradelib::live::SessionExecutor< Session >::cancel(), outcome_of(), and algotradelib::live::SessionExecutor< Session >::place().

◆ parse_journal_bytes()

JournalReplay algotradelib::runner::parse_journal_bytes ( const JournalBytes & bytes)
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.

Parameters
bytesThe bytes and read status; a status other than READ is passed through.
Returns
The replay.

Definition at line 1013 of file file_journal.hpp.

Referenced by parse_journal_bytes(), and read_journal_file().

◆ placements_of()

std::vector< OpenInstruction > algotradelib::runner::placements_of ( const JournalReplay & replay,
const std::vector< std::string > & ids )
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.

Parameters
replayThe journal's contents.
idsThe journal ids wanted.
Returns
One instruction per id that has a PENDING or INDETERMINATE placement line, in file order; one recovered from a damaged line is left out.

Definition at line 592 of file journal.hpp.

Referenced by placements_of().

◆ poll_kind_name()

std::string_view algotradelib::runner::poll_kind_name ( PollKind kind)
inlineconstexprnoexcept

Returns a poll kind's lowercase name, such as "working_orders".

Parameters
kindThe kind.
Returns
The name; empty for a value that is not a PollKind.

Definition at line 66 of file loop.hpp.

Referenced by poll_kind_name(), and live_program::print_loop().

◆ poll_outcome_name()

std::string_view algotradelib::runner::poll_outcome_name ( PollOutcome outcome)
inlineconstexprnoexcept

Returns an outcome's lowercase name, such as "rate_limited".

Parameters
outcomeThe outcome.
Returns
The name; empty for a value that is not a PollOutcome.

Definition at line 141 of file loop.hpp.

Referenced by poll_outcome_name().

◆ read_journal_bytes()

JournalBytes algotradelib::runner::read_journal_bytes ( const std::string & path)
inline

Reads a journal file's bytes, without opening it for appending.

Parameters
pathThe file.
Returns
The bytes and READ; MISSING if there is no file (a first start, nothing owed); or UNREADABLE if it exists and could not be opened or read to the end.

Definition at line 966 of file file_journal.hpp.

Referenced by read_journal_bytes(), and read_journal_file().

◆ read_journal_file()

JournalReplay algotradelib::runner::read_journal_file ( const std::string & path)
inline

Reads and parses a journal file.

Parameters
pathThe file.
Returns
The replay; see read_journal_bytes and parse_journal_bytes.

Definition at line 1111 of file file_journal.hpp.

Referenced by read_journal_file(), and algotradelib::runner::FileJournal::replay().

◆ reconcile_against() [1/2]

template<typename Journal>
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).

Template Parameters
JournalThe journal type.
Parameters
openThe unresolved instructions.
rowsThe listing, which must be complete.
replayThe journal's contents, which open was taken from.
nowThe current instant.
ledgerThe ledger to clear.
journalThe journal to record resolutions in.
windowThe allowances.
unplaced_noteText added to the journal detail of a placement found NOT_PLACED: what the caller does with that finding.
Returns
The report.

Definition at line 937 of file reconcile_orders.hpp.

Referenced by reconcile_against(), and reconcile_against().

◆ reconcile_against() [2/2]

template<typename Journal>
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.

Template Parameters
JournalThe journal type; it must provide replay().
Parameters
openThe unresolved instructions.
rowsThe listing, which must be complete.
nowThe current instant.
ledgerThe ledger to clear.
journalThe journal to read and to record resolutions in.
windowThe allowances.
unplaced_noteText added to the journal detail of a placement found NOT_PLACED.
Returns
The report.

Definition at line 1023 of file reconcile_orders.hpp.

◆ recorded_owner()

const OpenInstruction * algotradelib::runner::recorded_owner ( const OpenInstruction & instruction,
const OrderSnapshot & row,
const std::vector< OpenInstruction > & recorded,
const MatchWindow & window )
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.

Parameters
instructionThe instruction being matched, which is never its own rival.
rowThe row.
recordedThe placements with recorded ids (recorded_placements).
windowThe allowances.
Returns
The placement, or nullptr.

Definition at line 588 of file reconcile_orders.hpp.

Referenced by recorded_owner().

◆ recorded_placements()

std::vector< OpenInstruction > algotradelib::runner::recorded_placements ( const JournalReplay & replay)
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.

Parameters
replayThe journal's contents.
Returns
The placements, with entry_.order_id_ set to the recorded id.

Definition at line 535 of file reconcile_orders.hpp.

Referenced by recorded_placements().

◆ recover_into() [1/2]

template<typename Journal>
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.

Template Parameters
JournalThe journal type.
Parameters
journalThe journal.
ledgerThe ledger to mark.
Returns
The report.

Definition at line 1330 of file reconcile_orders.hpp.

◆ recover_into() [2/2]

RecoveryReport algotradelib::runner::recover_into ( const JournalReplay & replay,
IndeterminacyLedger & ledger )
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.

Parameters
replayThe journal's contents.
ledgerThe ledger to mark.
Returns
The report.

Definition at line 1291 of file reconcile_orders.hpp.

Referenced by recover_into(), recover_into(), and recover_runner().

◆ recover_runner()

template<typename Runner, typename Journal>
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.

Template Parameters
RunnerThe runner type.
JournalThe journal type.
Parameters
runner_instanceThe runner.
journalThe journal.
Returns
The report.

Definition at line 1350 of file reconcile_orders.hpp.

Referenced by recover_runner().

◆ resolution_entry()

JournalEntry algotradelib::runner::resolution_entry ( const OpenInstruction & instruction,
const OrderMatch & match,
std::chrono::system_clock::time_point now )
inline

Makes the RESOLVED journal line that records a sweep's verdict.

Parameters
instructionThe instruction.
matchThe verdict.
nowWhen it was resolved.
Returns
The line.

Definition at line 901 of file reconcile_orders.hpp.

Referenced by resolution_entry().

◆ route_evidence()

RouteEvidence algotradelib::runner::route_evidence ( const OpenInstruction & instruction,
const OrderSnapshot & row )
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).

Parameters
instructionThe instruction.
rowThe row.
Returns
ABSENT if the line predates routes or the row names no venue; CONFIRMS if the instruction asked for no venue (as at Toss) or the venues agree; otherwise CONTRADICTS.

Definition at line 337 of file reconcile_orders.hpp.

Referenced by route_evidence(), row_corresponds(), and row_might_correspond().

◆ row_corresponds()

bool algotradelib::runner::row_corresponds ( const OpenInstruction & instruction,
const OrderSnapshot & row,
const MatchWindow & window )
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.

Parameters
instructionThe instruction.
rowThe row.
windowThe allowances.
Returns
true if every attribute confirms.

Definition at line 368 of file reconcile_orders.hpp.

Referenced by recorded_owner(), and row_corresponds().

◆ row_might_correspond()

bool algotradelib::runner::row_might_correspond ( const OpenInstruction & instruction,
const OrderSnapshot & row,
const MatchWindow & window )
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.

Parameters
instructionThe instruction.
rowThe row.
windowThe allowances.
Returns
true if some attribute is unknown and nothing disagrees; false for a row that fully corresponds (see row_corresponds) or disagrees.

Definition at line 423 of file reconcile_orders.hpp.

Referenced by recorded_owner(), and row_might_correspond().

◆ salvage_damaged()

bool algotradelib::runner::salvage_damaged ( std::string_view line,
std::string_view key )
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.

Parameters
lineThe journal line.
keyThe field name.
Returns
true if the field is damaged.

Definition at line 850 of file file_journal.hpp.

Referenced by salvage_damaged(), and salvage_journal_line().

◆ salvage_journal_line()

std::optional< JournalEntry > algotradelib::runner::salvage_journal_line ( std::string_view 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.

Parameters
lineThe torn line.
Returns
The entry, or std::nullopt if the line does not even name a symbol.

Definition at line 870 of file file_journal.hpp.

Referenced by parse_journal_bytes(), and salvage_journal_line().

◆ send_outcome_is_local_failure()

bool algotradelib::runner::send_outcome_is_local_failure ( SendOutcome outcome)
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.

Parameters
outcomeThe outcome.
Returns
true for UNAVAILABLE only.

Definition at line 218 of file execution.hpp.

Referenced by send_outcome_is_local_failure().

◆ send_outcome_name()

std::string_view algotradelib::runner::send_outcome_name ( SendOutcome outcome)
inlineconstexprnoexcept

Returns a lowercase name for an outcome, such as "indeterminate", for logs.

Parameters
outcomeThe outcome.
Returns
The name; empty for a value that is not a SendOutcome.

Definition at line 80 of file execution.hpp.

Referenced by send_outcome_name().

◆ send_outcome_reached_broker()

bool algotradelib::runner::send_outcome_reached_broker ( SendOutcome outcome)
inlineconstexprnoexcept

Tests whether an outcome means a request reached the broker.

Parameters
outcomeThe outcome.
Returns
false for UNAVAILABLE and REFUSED_LOCALLY; true otherwise.

Definition at line 199 of file execution.hpp.

Referenced by send_outcome_reached_broker().

◆ stop_intent_closes()

bool algotradelib::runner::stop_intent_closes ( StopIntent intent)
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.

Parameters
intentThe intent.
Returns
false for QUIESCE; true for WITHDRAW and FLATTEN.

Definition at line 114 of file stop.hpp.

Referenced by stop_intent_closes().

◆ stop_intent_closes_positions()

bool algotradelib::runner::stop_intent_closes_positions ( StopIntent intent)
inlineconstexprnoexcept

Tests whether a stop intent closes positions with market orders, after withdrawing the working orders.

Parameters
intentThe intent.
Returns
true for FLATTEN; false for QUIESCE and WITHDRAW.

Definition at line 131 of file stop.hpp.

Referenced by stop_intent_closes_positions().

◆ stop_intent_covers()

bool algotradelib::runner::stop_intent_covers ( StopIntent held,
StopIntent candidate )
inlineconstexprnoexcept

Tests whether one intent does everything another would.

Parameters
heldThe intent in force.
candidateThe intent requested.
Returns
true if held is at least as strong (QUIESCE < WITHDRAW < FLATTEN).

Definition at line 148 of file stop.hpp.

Referenced by stop_intent_covers().

◆ stop_intent_from()

std::optional< StopIntent > algotradelib::runner::stop_intent_from ( std::string_view text)
inlinenoexcept

Parses an intent's name.

Parameters
text"quiesce", "withdraw" or "flatten".
Returns
The intent, or std::nullopt for any other text.

Definition at line 83 of file stop.hpp.

Referenced by algotradelib::runner::FileStopChannel::poll(), and stop_intent_from().

◆ stop_intent_name()

std::string_view algotradelib::runner::stop_intent_name ( StopIntent intent)
inlineconstexprnoexcept

Returns a lowercase name for an intent, as written in the control file ("withdraw").

Parameters
intentThe intent.
Returns
The name; empty for a value that is not a StopIntent.

Definition at line 61 of file stop.hpp.

Referenced by live_program::print_loop(), stop_intent_from(), and stop_intent_name().

◆ stop_intent_strength()

int algotradelib::runner::stop_intent_strength ( StopIntent intent)
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).

Parameters
intentThe intent.
Returns
0 for QUIESCE, 1 for WITHDRAW, 2 for FLATTEN.

Definition at line 96 of file stop.hpp.

Referenced by algotradelib::runner::StopSource::request(), stop_intent_covers(), and stop_intent_strength().

◆ time_evidence()

Evidence algotradelib::runner::time_evidence ( const OpenInstruction & instruction,
const OrderSnapshot & row,
const MatchWindow & window )
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.

Parameters
instructionThe instruction.
rowThe row.
windowThe allowances.
Returns
ABSENT if the row's date was assumed; otherwise CONFIRMS if it has no time or its time is inside the widened send window, and CONTRADICTS if not.

Definition at line 312 of file reconcile_orders.hpp.

Referenced by row_corresponds(), row_might_correspond(), and time_evidence().

◆ trigger_evidence()

Evidence algotradelib::runner::trigger_evidence ( const std::optional< Decimal64 > & row_trigger,
const std::optional< Decimal64 > & entry_trigger )
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)
Parameters
row_triggerThe row's trigger.
entry_triggerThe instruction's trigger.
Returns
The evidence.

Definition at line 281 of file reconcile_orders.hpp.

Referenced by dates_listed_order(), row_corresponds(), row_might_correspond(), and trigger_evidence().

◆ unattributable_journal_entry()

JournalEntry algotradelib::runner::unattributable_journal_entry ( std::string_view line)
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.

Parameters
lineThe torn line (quoted in the detail).
Returns
The entry.

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().

◆ unresolvable_reason()

std::string algotradelib::runner::unresolvable_reason ( const JournalEntry & 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).

Parameters
entryThe journalled instruction.
Returns
The reason, or an empty string if it can be matched.

Definition at line 485 of file reconcile_orders.hpp.

Referenced by unresolvable_reason().

◆ unresolved_instructions()

std::vector< OpenInstruction > algotradelib::runner::unresolved_instructions ( const JournalReplay & replay)
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.

Parameters
replayThe journal's contents.
Returns
The unresolved instructions.

Definition at line 537 of file journal.hpp.

Referenced by recover_into(), and unresolved_instructions().

◆ withheld_plan_reason_name()

std::string_view algotradelib::runner::withheld_plan_reason_name ( WithheldPlanReason reason)
inlineconstexprnoexcept

Returns a lowercase name for a reason, such as "portfolio_stale", for logs.

Parameters
reasonThe reason.
Returns
The name.

Definition at line 334 of file execution.hpp.

Referenced by withheld_plan_reason_name().

◆ withheld_reason_name()

std::string_view algotradelib::runner::withheld_reason_name ( WithheldReason reason)
inlineconstexprnoexcept

Returns a lowercase name for a reason, such as "reconcile_required", for logs.

Parameters
reasonThe reason.
Returns
The name.

Definition at line 283 of file execution.hpp.

Referenced by withheld_reason_name().

Variable Documentation

◆ all_journal_actions

std::array<JournalAction, 2> algotradelib::runner::all_journal_actions {JournalAction::PLACE, JournalAction::CANCEL}
inlineconstexpr

Every JournalAction, in declaration order.

Definition at line 38 of file journal.hpp.

Referenced by journal_action_from().

◆ all_journal_outcomes

std::array<JournalOutcome, 7> algotradelib::runner::all_journal_outcomes
inlineconstexpr
Initial value:
{
}
@ CONFIRMED
A serialized runner accounted for the placement: holdings showed what it filled, its history showed i...
Definition journal.hpp:124
@ INDETERMINATE
The outcome is unknown (SendOutcome::INDETERMINATE: a failure in transit, an unreadable reply,...
Definition journal.hpp:108
@ RESOLVED
A recovery sweep read the broker's order list and closed the question.
Definition journal.hpp:116
@ REJECTED
The instruction was refused, by the broker or before it was sent, so it does not exist.
Definition journal.hpp:103
@ ACCEPTED
The broker accepted the instruction; it exists.
Definition journal.hpp:97
@ HELD
Evidence contradicted the placement (holdings moved past what it can explain), so only an operator ma...
Definition journal.hpp:129
@ PENDING
Written before the send; whether the instruction exists is not yet known.
Definition journal.hpp:95

Every JournalOutcome, in declaration order.

Definition at line 133 of file journal.hpp.

Referenced by journal_outcome_from().

◆ all_poll_kinds

PollKind algotradelib::runner::all_poll_kinds[]
inlineconstexpr
Initial value:
= {
}
@ WORKING_ORDERS
Working orders, which reconciliation and cancellation need.
Definition loop.hpp:38
@ BARS
Completed bars.
Definition loop.hpp:32
@ PRICE_LIMITS
Today's price bands, which an aggressive limit price is clamped to; polled second,...
Definition loop.hpp:58
@ HOLDINGS
Holdings, which orders are sized against.
Definition loop.hpp:36
@ QUOTES
Current quotes, for strategies that act between bars.
Definition loop.hpp:34
@ CALENDAR
The trading calendar, from which the loop derives the market phase; polled first, and on by default.
Definition loop.hpp:49
@ BUYING_POWER
Buying power, polled beside holdings (not before each order).
Definition loop.hpp:40

Every poll kind, in the order an iteration polls them.

Definition at line 87 of file loop.hpp.

◆ all_poll_outcomes

std::array<PollOutcome, 4> algotradelib::runner::all_poll_outcomes
inlineconstexpr
Initial value:
{
}
@ RATE_LIMITED
The rate limiter refused the poll; not counted as a failure.
Definition loop.hpp:125
@ UNCHANGED
The poll succeeded and there was nothing new.
Definition loop.hpp:121
@ FAILED
The poll failed; counted toward the failure budget.
Definition loop.hpp:123
@ UPDATED
New data arrived and was fed to the runner, or installed in it (a calendar, price bands).
Definition loop.hpp:119

Every PollOutcome, in declaration order.

Definition at line 129 of file loop.hpp.

◆ all_send_outcomes

std::array<SendOutcome, 5> algotradelib::runner::all_send_outcomes
inlineconstexpr
Initial value:
{
}
@ UNAVAILABLE
Local machinery failed (such as the order journal not being writable), so nothing was sent.
Definition execution.hpp:55
@ INDETERMINATE
The outcome is unknown (see outcome_of): the request failed in transit or was cancelled,...
Definition execution.hpp:48
@ REJECTED
The broker refused the instruction (for a placement, the order does not exist); nothing needs reconci...
Definition execution.hpp:34
@ ACCEPTED
The broker accepted the instruction (for a placement, the order exists).
Definition execution.hpp:32
@ REFUSED_LOCALLY
The binding refused the instruction before sending it (such as an idempotency key at a broker without...
Definition execution.hpp:63

Every SendOutcome, in declaration order.

Definition at line 67 of file execution.hpp.

◆ all_stop_intents

std::array<StopIntent, 3> algotradelib::runner::all_stop_intents
inlineconstexpr
Initial value:
{
}
@ FLATTEN
Withdraw, then ask the broker to close the positions with market orders.
Definition stop.hpp:46
@ WITHDRAW
Quiesce, then ask the broker to cancel the working orders.
Definition stop.hpp:40
@ QUIESCE
Stop sending new orders; nothing is cancelled or closed. The default, and what a signal means.
Definition stop.hpp:34

Every StopIntent, in declaration order.

Definition at line 50 of file stop.hpp.

Referenced by stop_intent_from().

◆ poll_kind_count

std::size_t algotradelib::runner::poll_kind_count = std::size(all_poll_kinds)
inlineconstexpr

The number of PollKind values.

Definition at line 109 of file loop.hpp.