algotradelib 0.0.0.9000
C++ header-only library for algorithmic trading
Loading...
Searching...
No Matches
algotradelib::runner::JournalingExecutor< Inner, Journal, Clock > Class Template Reference

An executor wrapper that records each instruction in a journal before sending it. More...

#include <algotradelib/src/runner/journal.hpp>

Public Member Functions

 JournalingExecutor (Inner inner, Journal &journal, Clock clock={})
 Wraps an executor.
void set_id_prefix (std::string prefix)
 Sets the prefix of line ids.
template<typename E = Inner>
auto route_of (const strategy::PlannedOrder &order, int) const -> decltype(std::declval< const E & >().effective_route(order.venue_))
 Returns the venue the wrapped executor says an order will reach.
Venue route_of (const strategy::PlannedOrder &order, long) const
 Returns the venue an order asked for, when the wrapped executor cannot resolve routes (the fallback of route_of(order, 0); the second argument's value is ignored).
Venue effective_route_of (const strategy::PlannedOrder &order) const
 Returns the venue to record for an order: the binding's route, or the venue asked for.
SendOutcome place (const strategy::PlannedOrder &order)
 Records and places one order.
SendOutcome place (const strategy::PlannedOrder &order, std::optional< Decimal64 > baseline)
 Records and places one order, stating the holding it was decided against (a serialized Runner calls this).
const std::optional< JournalEntry > & last_entry () const noexcept
 Returns the answering line last written (or attempted) for a placement the wrapped executor was asked to place, sent or refused before sending.
bool record (JournalEntry &entry)
 Appends a line the caller built, such as a serialized Runner's CONFIRMED line.
template<typename BrokerTag>
SendOutcome cancel (const WorkingOrder< BrokerTag > &working)
 Records and sends one cancellation.
const Inner & inner () const noexcept
 Returns the wrapped executor.
Inner & inner () noexcept
 Returns the wrapped executor.
const Journal & journal () const noexcept
 Returns the journal.
const std::string & last_journal_error () const noexcept
 Returns the first journal failure's description.
std::size_t unjournaled_refusals () const noexcept
 Returns how many instructions were not sent because their PENDING line could not be written.
std::size_t journal_failures () const noexcept
 Returns how many journal writes have failed; Runner compares it with the count it last acknowledged to tell a new failure from an old one.
template<typename Executor = Inner>
auto requested_route (Venue asked) const noexcept -> decltype(std::declval< const Executor & >().requested_route(asked))
 Returns the wrapped executor's route for a requested venue.
template<typename Executor = Inner>
auto last_ref () const noexcept -> decltype(std::declval< const Executor & >().last_ref())
 Returns the reference of the last order the wrapped executor placed.
template<typename Executor = Inner>
auto last_error () const noexcept -> decltype(std::declval< const Executor & >().last_error())
 Returns why the last instruction failed, from the wrapped executor.

Static Public Attributes

static constexpr bool reaches_a_broker = runner_detail::sends_to_a_broker<Inner>::value
 Whether the wrapped executor reaches a broker.

Detailed Description

template<typename Inner, typename Journal, typename Clock = SteadyClock>
class algotradelib::runner::JournalingExecutor< Inner, Journal, Clock >

An executor wrapper that records each instruction in a journal before sending it.

place and cancel append a PENDING line, call the wrapped executor only if the append succeeded, and append its outcome. The line is as durable as the journal makes it before append returns: FileJournal flushes it to disk, MemoryJournal (for tests and dry runs) loses it at exit. A journal of your own must write durably before returning success if it is to be recovered from after a crash. The wrapped executor's outcome is returned unchanged, except that if the PENDING line cannot be written, nothing is sent and the outcome is SendOutcome::UNAVAILABLE (which stops the runner). If only the answering line fails, the send has happened; the failure is recorded and the instruction will look unresolved to recovery. A backtest does not use it.

Template Parameters
InnerThe wrapped executor.
JournalThe journal type (MemoryJournal or FileJournal).
ClockThe clock lines are stamped with.

Definition at line 695 of file journal.hpp.

Constructor & Destructor Documentation

◆ JournalingExecutor()

template<typename Inner, typename Journal, typename Clock = SteadyClock>
algotradelib::runner::JournalingExecutor< Inner, Journal, Clock >::JournalingExecutor ( Inner inner,
Journal & journal,
Clock clock = {} )
inline

Wraps an executor.

Parameters
innerThe executor to wrap.
journalThe journal; borrowed, and must outlive this executor.
clockThe clock lines are stamped with; pass a ClockReference to share a loop's clock.

Definition at line 706 of file journal.hpp.

Member Function Documentation

◆ cancel()

template<typename Inner, typename Journal, typename Clock = SteadyClock>
template<typename BrokerTag>
SendOutcome algotradelib::runner::JournalingExecutor< Inner, Journal, Clock >::cancel ( const WorkingOrder< BrokerTag > & working)
inline

Records and sends one cancellation.

Template Parameters
BrokerTagThe broker tag.
Parameters
workingThe order to cancel.
Returns
The wrapped executor's outcome, or UNAVAILABLE if the PENDING line could not be written.

Definition at line 839 of file journal.hpp.

◆ effective_route_of()

template<typename Inner, typename Journal, typename Clock = SteadyClock>
Venue algotradelib::runner::JournalingExecutor< Inner, Journal, Clock >::effective_route_of ( const strategy::PlannedOrder & order) const
inline

Returns the venue to record for an order: the binding's route, or the venue asked for.

Parameters
orderThe order.
Returns
The venue.

Definition at line 752 of file journal.hpp.

Referenced by place().

◆ inner() [1/2]

template<typename Inner, typename Journal, typename Clock = SteadyClock>
const Inner & algotradelib::runner::JournalingExecutor< Inner, Journal, Clock >::inner ( ) const
inlinenoexcept

Returns the wrapped executor.

Returns
The executor.

Definition at line 872 of file journal.hpp.

Referenced by JournalingExecutor().

◆ inner() [2/2]

template<typename Inner, typename Journal, typename Clock = SteadyClock>
Inner & algotradelib::runner::JournalingExecutor< Inner, Journal, Clock >::inner ( )
inlinenoexcept

Returns the wrapped executor.

Returns
The executor.

Definition at line 877 of file journal.hpp.

◆ journal()

template<typename Inner, typename Journal, typename Clock = SteadyClock>
const Journal & algotradelib::runner::JournalingExecutor< Inner, Journal, Clock >::journal ( ) const
inlinenoexcept

Returns the journal.

Returns
The journal.

Definition at line 883 of file journal.hpp.

Referenced by JournalingExecutor().

◆ journal_failures()

template<typename Inner, typename Journal, typename Clock = SteadyClock>
std::size_t algotradelib::runner::JournalingExecutor< Inner, Journal, Clock >::journal_failures ( ) const
inlinenoexcept

Returns how many journal writes have failed; Runner compares it with the count it last acknowledged to tell a new failure from an old one.

Returns
The count.

Definition at line 902 of file journal.hpp.

◆ last_entry()

template<typename Inner, typename Journal, typename Clock = SteadyClock>
const std::optional< JournalEntry > & algotradelib::runner::JournalingExecutor< Inner, Journal, Clock >::last_entry ( ) const
inlinenoexcept

Returns the answering line last written (or attempted) for a placement the wrapped executor was asked to place, sent or refused before sending.

Returns
The line, or std::nullopt before any placement was asked for.

Definition at line 812 of file journal.hpp.

◆ last_error()

template<typename Inner, typename Journal, typename Clock = SteadyClock>
template<typename Executor = Inner>
auto algotradelib::runner::JournalingExecutor< Inner, Journal, Clock >::last_error ( ) const -> decltype(std::declval< const Executor & >().last_error())
inlinenoexcept

Returns why the last instruction failed, from the wrapped executor.

Template Parameters
ExecutorThe wrapped executor type (deduced).
Returns
The error, if the wrapped executor reports one.

Definition at line 932 of file journal.hpp.

Referenced by last_error().

◆ last_journal_error()

template<typename Inner, typename Journal, typename Clock = SteadyClock>
const std::string & algotradelib::runner::JournalingExecutor< Inner, Journal, Clock >::last_journal_error ( ) const
inlinenoexcept

Returns the first journal failure's description.

Returns
The description, or empty if no write has failed; never cleared.

Definition at line 889 of file journal.hpp.

◆ last_ref()

template<typename Inner, typename Journal, typename Clock = SteadyClock>
template<typename Executor = Inner>
auto algotradelib::runner::JournalingExecutor< Inner, Journal, Clock >::last_ref ( ) const -> decltype(std::declval< const Executor & >().last_ref())
inlinenoexcept

Returns the reference of the last order the wrapped executor placed.

Template Parameters
ExecutorThe wrapped executor type (deduced).
Returns
The reference, if the wrapped executor reports one.

Definition at line 922 of file journal.hpp.

Referenced by last_ref().

◆ place() [1/2]

template<typename Inner, typename Journal, typename Clock = SteadyClock>
SendOutcome algotradelib::runner::JournalingExecutor< Inner, Journal, Clock >::place ( const strategy::PlannedOrder & order)
inline

Records and places one order.

Parameters
orderThe order.
Returns
The wrapped executor's outcome, or UNAVAILABLE if the PENDING line could not be written.

Definition at line 761 of file journal.hpp.

Referenced by place().

◆ place() [2/2]

template<typename Inner, typename Journal, typename Clock = SteadyClock>
SendOutcome algotradelib::runner::JournalingExecutor< Inner, Journal, Clock >::place ( const strategy::PlannedOrder & order,
std::optional< Decimal64 > baseline )
inline

Records and places one order, stating the holding it was decided against (a serialized Runner calls this).

Parameters
orderThe order.
baselineThe instrument's net holding, written on every line for the order.
Returns
The wrapped executor's outcome, or UNAVAILABLE if the PENDING line could not be written.

Definition at line 770 of file journal.hpp.

◆ record()

template<typename Inner, typename Journal, typename Clock = SteadyClock>
bool algotradelib::runner::JournalingExecutor< Inner, Journal, Clock >::record ( JournalEntry & entry)
inline

Appends a line the caller built, such as a serialized Runner's CONFIRMED line.

A failure is counted like any other journal failure (journal_failures).

Parameters
entryThe line. It is stamped here with this executor's clock (recorded_at_), and its scope by the journal.
Returns
Whether it was written.

Definition at line 823 of file journal.hpp.

◆ requested_route()

template<typename Inner, typename Journal, typename Clock = SteadyClock>
template<typename Executor = Inner>
auto algotradelib::runner::JournalingExecutor< Inner, Journal, Clock >::requested_route ( Venue asked) const -> decltype(std::declval< const Executor & >().requested_route(asked))
inlinenoexcept

Returns the wrapped executor's route for a requested venue.

Template Parameters
ExecutorThe wrapped executor type (deduced).
Parameters
askedThe venue asked for.
Returns
The venue it routes to.

Definition at line 911 of file journal.hpp.

◆ route_of() [1/2]

template<typename Inner, typename Journal, typename Clock = SteadyClock>
template<typename E = Inner>
auto algotradelib::runner::JournalingExecutor< Inner, Journal, Clock >::route_of ( const strategy::PlannedOrder & order,
int  ) const -> decltype(std::declval< const E & >().effective_route(order.venue_))
inline

Returns the venue the wrapped executor says an order will reach.

Call it as route_of(order, 0); the second argument selects this overload over the fallback, and its value is ignored.

Template Parameters
EThe wrapped executor type (deduced).
Parameters
orderThe order.
Returns
The wrapped executor's effective_route for the order's venue.

Definition at line 734 of file journal.hpp.

Referenced by effective_route_of().

◆ route_of() [2/2]

template<typename Inner, typename Journal, typename Clock = SteadyClock>
Venue algotradelib::runner::JournalingExecutor< Inner, Journal, Clock >::route_of ( const strategy::PlannedOrder & order,
long  ) const
inline

Returns the venue an order asked for, when the wrapped executor cannot resolve routes (the fallback of route_of(order, 0); the second argument's value is ignored).

Parameters
orderThe order.
Returns
order.venue_.

Definition at line 745 of file journal.hpp.

◆ set_id_prefix()

template<typename Inner, typename Journal, typename Clock = SteadyClock>
void algotradelib::runner::JournalingExecutor< Inner, Journal, Clock >::set_id_prefix ( std::string prefix)
inline

Sets the prefix of line ids.

Ids are the prefix, a hyphen and a counter starting at one (<prefix>-1), and recovery pairs lines by id, so the prefix must differ between every executor run that shares a journal. The default is the wall-clock construction time in microseconds (not the injected clock's), which is distinct only if no two executors on the journal are made at the same instant.

Parameters
prefixThe prefix.

Definition at line 721 of file journal.hpp.

◆ unjournaled_refusals()

template<typename Inner, typename Journal, typename Clock = SteadyClock>
std::size_t algotradelib::runner::JournalingExecutor< Inner, Journal, Clock >::unjournaled_refusals ( ) const
inlinenoexcept

Returns how many instructions were not sent because their PENDING line could not be written.

Returns
The count.

Definition at line 895 of file journal.hpp.

Member Data Documentation

◆ reaches_a_broker

template<typename Inner, typename Journal, typename Clock = SteadyClock>
bool algotradelib::runner::JournalingExecutor< Inner, Journal, Clock >::reaches_a_broker = runner_detail::sends_to_a_broker<Inner>::value
staticconstexpr

Whether the wrapped executor reaches a broker.

Definition at line 698 of file journal.hpp.


The documentation for this class was generated from the following file: