5#include <algotradelib/core>
87 return "indeterminate";
91 return "refused_locally";
98 "all_send_outcomes must list every SendOutcome"
231namespace runner_detail {
253template <
typename Executor,
typename =
void>
254struct sends_to_a_broker : std::true_type {};
256template <
typename Executor>
257struct sends_to_a_broker<Executor, std::void_t<decltype(Executor::reaches_a_broker)>>
258 : std::bool_constant<Executor::reaches_a_broker> {};
286 return "reconcile_required";
288 return "local_failure";
290 return "awaiting_confirmation";
337 return "portfolio_absent";
339 return "portfolio_stale";
341 return "portfolio_superseded";
343 return "placement_held";
345 return "awaiting_confirmation";
355template <
typename BrokerTag>
526 for (
auto& entry : pending_) {
527 if (entry.instrument_ ==
id) {
532 pending_.push_back(Entry{id, std::move(
detail)});
541 for (
const auto& entry : pending_) {
542 if (entry.instrument_ ==
id) {
555 for (
const auto& entry : pending_) {
556 if (entry.instrument_ ==
id) {
557 return entry.detail_;
568 for (
auto at = pending_.begin(); at != pending_.end(); ++at) {
569 if (at->instrument_ ==
id) {
581 std::vector<InstrumentId> ids;
582 ids.reserve(pending_.size());
583 for (
const auto& entry : pending_) {
584 ids.push_back(entry.instrument_);
593 bool empty() const noexcept {
return pending_.empty(); }
601 std::vector<Entry> pending_;
611template <
typename BrokerTag>
623 placed_.push_back(order);
633 canceled_.push_back(working.
ref_);
641 const std::vector<strategy::PlannedOrder>&
placed() const noexcept {
return placed_; }
647 const std::vector<OrderRef<BrokerTag>>&
canceled() const noexcept {
return canceled_; }
650 std::vector<strategy::PlannedOrder> placed_;
651 std::vector<OrderRef<BrokerTag>> canceled_;
An exact signed decimal: an int64 coefficient times 10^-scale.
The instruments with an order of unknown outcome, where nothing may be placed until the broker's orde...
std::string_view detail(const InstrumentId &id) const
Returns why an instrument is unresolved.
bool empty() const noexcept
Tests whether nothing is unresolved.
std::vector< InstrumentId > pending() const
Returns every instrument waiting for reconciliation.
bool requires_reconcile(const InstrumentId &id) const
Tests whether an instrument is waiting for reconciliation.
void mark(const InstrumentId &id, std::string detail)
Records an instrument's order of unknown outcome; an existing entry keeps its first detail.
void resolve_after_reading_orders(const InstrumentId &id)
Clears an instrument; call it only after reading the broker's order list for it.
An executor that sends nothing and records what it was given (the dry run's default).
const std::vector< strategy::PlannedOrder > & placed() const noexcept
Returns every placement recorded.
SendOutcome place(const strategy::PlannedOrder &order)
Records a placement.
static constexpr bool reaches_a_broker
false: a dry run reaches no broker, so the runner does not require a read account.
const std::vector< OrderRef< BrokerTag > > & canceled() const noexcept
Returns every cancellation recorded.
SendOutcome cancel(const WorkingOrder< BrokerTag > &working)
Records a cancellation.
Runs a strategy: the runner, the polling loop, the order journal, and stopping.
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 ...
constexpr bool send_outcome_reached_broker(SendOutcome outcome) noexcept
Tests whether an outcome means a request reached the broker.
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...
constexpr std::array< SendOutcome, 5 > all_send_outcomes
Every SendOutcome, in declaration order.
constexpr std::string_view obligation_state_name(ObligationState state) noexcept
Returns a lowercase name for a state, such as "named", for logs.
SendOutcome
What became of one instruction (a placement or a cancellation) an executor was asked to send.
@ UNAVAILABLE
Local machinery failed (such as the order journal not being writable), so nothing was sent.
@ INDETERMINATE
The outcome is unknown (see outcome_of): the request failed in transit or was cancelled,...
@ REJECTED
The broker refused the instruction (for a placement, the order does not exist); nothing needs reconci...
@ ACCEPTED
The broker accepted the instruction (for a placement, the order exists).
@ REFUSED_LOCALLY
The binding refused the instruction before sending it (such as an idempotency key at a broker without...
WithheldPlanReason
Why the runner held back a whole reconciliation plan (cancellations and placements) before sending an...
@ PLACEMENT_HELD
A hold stops placements, so the plan's cancellations are held too (a reprice must not become a bare c...
@ PORTFOLIO_ABSENT
No holdings have been read, so the plan was computed against an account that looks flat (and could ca...
@ AWAITING_CONFIRMATION
A serialized runner may not place on the instrument yet, so the plan's cancellations are held too: an...
@ PORTFOLIO_STALE
The holdings the plan was computed from are older than the configured maximum age.
@ PORTFOLIO_SUPERSEDED
The working-order listing is newer than the holdings the plan was sized against (see strategy::Portfo...
constexpr std::string_view withheld_reason_name(WithheldReason reason) noexcept
Returns a lowercase name for a reason, such as "reconcile_required", for logs.
WithheldReason
Why the runner held back a planned order without sending 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 ...
@ RECONCILE_REQUIRED
An earlier instruction for this instrument has an unknown outcome; nothing is sent until the broker's...
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 lis...
SendOutcome outcome_of(const BrokerError &error)
Classifies an error from an order request: did the order come to exist?
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 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 catego...
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 tha...
ObligationState
What a serialized runner still owes on an instrument (Runner::obligation_state).
@ NAMED
An order the broker named, waiting for its history and holdings to account for it.
@ OPERATOR
An order only an operator may account for (Runner::release_obligations).
@ NONE
Nothing: an order may be placed.
@ UNNAMED
An order whose existence is unknown (its reply was lost and no sweep named it).
constexpr int obligation_weight(ObligationState state) noexcept
Returns how much an obligation state weighs when one instrument owes several orders: the instrument r...
constexpr std::string_view send_outcome_name(SendOutcome outcome) noexcept
Returns a lowercase name for an outcome, such as "indeterminate", for logs.
bool broker_rate_limited(const BrokerError &error) noexcept
Tests whether an error is the broker's rate-limit refusal (such as KIS EGW00201).
The library: broker-neutral types (core), and the modules below.
constexpr bool lists_every_value(const std::array< Enum, N > &values, IsEnumerator is_enumerator) noexcept
Tests whether a list holds every value of an enum exactly once, in any order.
ErrorCategory
The kind of failure a BrokerError reports.
@ RATE_LIMIT
The broker refused the request for its rate limit.
@ HTTP
The broker answered with an HTTP error status (http_status_).
@ PROTOCOL
The reply could not be read, or the broker declared a failure this client does not classify further: ...
@ CANCELLED
The operation was cancelled, such as by closing the client or a local deadline.
@ AUTHENTICATION
The credentials or token were refused.
@ TRANSPORT
The connection failed (DNS, connect, TLS, write or read).
@ INVALID_ARGUMENT
The request was invalid, refused by the client before sending or by the broker.
constexpr bool error_category_is_rate_limit(ErrorCategory category) noexcept
Tests whether an error of this category is a broker asking the caller to slow down,...
OrderSide
The side of an order: its economic direction, buy or sell.
Reconciliation: turning a strategy's intents and targets into the orders and cancellations to send.
The error a broker or transport operation returns.
int http_status_
The HTTP status of the reply: set for an HTTP error and for a reply whose body is not a JSON object....
ErrorCategory category_
The kind of failure; the field to branch on.
bool reached_broker_
Whether a request was sent before this error.
Identifies an instrument: its country, venue and symbol.
An order still open to modification or cancellation.
OrderRef< Broker > ref_
The reference to amend or cancel the order with.
The broker's own code and message for a refusal, kept for diagnosis.
std::string tag_
The tag of the instruction.
std::string message_
The broker's message.
std::string code_
The broker's error code, if it gave one.
InstrumentId instrument_
The instrument of the refused instruction.
One order a serialized runner still owes (Runner::obligations).
std::string order_id_
The broker's order id; empty while unnamed.
Decimal64 quantity_
The quantity holdings must still account for.
ObligationState state_
Its state: NAMED, UNNAMED or OPERATOR.
std::chrono::system_clock::time_point sent_at_
When it was sent, on the journal's clock.
InstrumentId instrument_
The instrument.
std::string journal_id_
The id of the order's journal lines.
One order the runner held back without sending, and why.
WithheldReason reason_
Why it was held back.
strategy::PlannedOrder order_
The order.
std::string detail_
A description of why.
One reconciliation plan the runner held back, and what it would have done.
std::vector< OrderRef< BrokerTag > > not_canceled_
The orders the plan would have cancelled.
std::size_t not_placed_
How many orders the plan would have placed.
std::string tag_
The tag of the strategy's instruction.
InstrumentId instrument_
The instrument.
WithheldPlanReason reason_
Why the plan was held back.
std::string detail_
A description of why, naming the hold if there was one.
One order the runner is to place.