algotradelib 0.0.0.9000
C++ header-only library for algorithmic trading
Loading...
Searching...
No Matches
algotradelib::live::SessionExecutor< Session > Class Template Reference

The executor that sends a runner's orders and cancellations through a broker session. More...

#include <algotradelib/src/live/session_executor.hpp>

Public Types

using Caps = typename Session::Caps
 The broker's capabilities, from the session.
using BrokerTag = typename Session::BrokerTag
 The broker tag, from the session.

Public Member Functions

 SessionExecutor (Session &session, Venue default_route=Venue::UNSPECIFIED)
 Constructs an executor for a session.
Venue default_route () const noexcept
 Returns the venue an order that names none is sent to.
Venue requested_route (Venue asked) const noexcept
 Returns the venue this executor requests for an order.
Venue effective_route (Venue asked) const noexcept
 Returns the route an order is sent with, for the journal to record before sending (for SOR, COMBINED, not the venue it executes on).
runner::SendOutcome place (const strategy::PlannedOrder &order)
 Places one order.
runner::SendOutcome cancel (const WorkingOrder< BrokerTag > &working)
 Cancels the whole remaining quantity of a working order.
std::optional< Decimal64 > sellable_quantity (const InstrumentId &instrument)
 Asks the broker how much of an instrument may be sold, where the broker answers that by a separate inquiry (SellableSource::INQUIRY).
const std::optional< OrderRef< BrokerTag > > & last_ref () const noexcept
 Returns the reference the broker issued for the last accepted order.
const std::optional< BrokerError > & last_error () const noexcept
 Returns why the last instruction failed.

Static Public Member Functions

static constexpr SellableBasis sellable_inquiry_basis ()
 Returns what the broker's sellable-quantity inquiry establishes, recorded with each figure.

Static Public Attributes

static constexpr bool reaches_a_broker = true
 true: a runner built on this executor requires holdings to have been read before it places, however the runner was assembled (see Runner::allow_absent_portfolio).
static constexpr bool inquires_sellable = Caps::sellable_source == SellableSource::INQUIRY
 true if the sellable quantity is a separate inquiry (one request per instrument sold).

Detailed Description

template<typename Session>
class algotradelib::live::SessionExecutor< Session >

The executor that sends a runner's orders and cancellations through a broker session.

It copies a strategy::PlannedOrder into an OrderRequest (prices and quantities are already on the grid) and classifies a failure with runner::outcome_of. Usually made by bind or bind_journaled.

Template Parameters
SessionThe broker session type (it must not be a market-data-only session).

Definition at line 25 of file session_executor.hpp.

Member Typedef Documentation

◆ BrokerTag

template<typename Session>
using algotradelib::live::SessionExecutor< Session >::BrokerTag = typename Session::BrokerTag

The broker tag, from the session.

Definition at line 36 of file session_executor.hpp.

◆ Caps

template<typename Session>
using algotradelib::live::SessionExecutor< Session >::Caps = typename Session::Caps

The broker's capabilities, from the session.

Definition at line 34 of file session_executor.hpp.

Constructor & Destructor Documentation

◆ SessionExecutor()

template<typename Session>
algotradelib::live::SessionExecutor< Session >::SessionExecutor ( Session & session,
Venue default_route = Venue::UNSPECIFIED )
inlineexplicit

Constructs an executor for a session.

Parameters
sessionThe session; borrowed, and must outlive the executor.
default_routeThe venue for an order that names none; see default_route().

Definition at line 50 of file session_executor.hpp.

Member Function Documentation

◆ cancel()

template<typename Session>
runner::SendOutcome algotradelib::live::SessionExecutor< Session >::cancel ( const WorkingOrder< BrokerTag > & working)
inline

Cancels the whole remaining quantity of a working order.

An order with no broker reference is refused (REFUSED_LOCALLY) without a request.

Parameters
workingThe order, as listed (or reserved).
Returns
The outcome (accepted means the request was accepted, not that the order is gone).

Definition at line 160 of file session_executor.hpp.

◆ default_route()

template<typename Session>
Venue algotradelib::live::SessionExecutor< Session >::default_route ( ) const
inlinenoexcept

Returns the venue an order that names none is sent to.

A strategy's orders name no venue, so this is the route of every order a runner plans; an order that names a venue keeps it. The runner writes the route into the order before sending, so the journal and reports name it.

UNSPECIFIED (the default) takes the broker's own default: KRX at KIS, none needed at Toss, and a refusal at Kiwoom, which has no default (give Venue::KRX, Venue::NXT, or Venue::COMBINED for its SOR). At KIS, Venue::COMBINED selects SOR, which a demo account refuses. A route the broker cannot take is refused before any request.

Warning
Prefer Venue::KRX or Venue::NXT to Venue::COMBINED until SOR orders have been seen listed on your account. Journal recovery matches a listed order to the recorded route; if the broker lists a SOR order under the venue where it rests, recovery can conclude the order was never placed, and a restarted runner could send it again. Neither broker's SOR listing has been observed.
Returns
The default route.

Definition at line 73 of file session_executor.hpp.

Referenced by SessionExecutor().

◆ effective_route()

template<typename Session>
Venue algotradelib::live::SessionExecutor< Session >::effective_route ( Venue asked) const
inlinenoexcept

Returns the route an order is sent with, for the journal to record before sending (for SOR, COMBINED, not the venue it executes on).

default_route() is applied first; then the broker's traits say where an unspecified venue goes (KRX at KIS). A session whose traits do not say returns the requested route.

Parameters
askedThe order's venue.
Returns
The venue.

Definition at line 94 of file session_executor.hpp.

◆ last_error()

template<typename Session>
const std::optional< BrokerError > & algotradelib::live::SessionExecutor< Session >::last_error ( ) const
inlinenoexcept

Returns why the last instruction failed.

Returns
The error, or empty if the last instruction succeeded.

Definition at line 237 of file session_executor.hpp.

◆ last_ref()

template<typename Session>
const std::optional< OrderRef< BrokerTag > > & algotradelib::live::SessionExecutor< Session >::last_ref ( ) const
inlinenoexcept

Returns the reference the broker issued for the last accepted order.

Returns
The reference, or empty if no order was accepted yet.

Definition at line 231 of file session_executor.hpp.

◆ place()

template<typename Session>
runner::SendOutcome algotradelib::live::SessionExecutor< Session >::place ( const strategy::PlannedOrder & order)
inline

Places one order.

An order with an idempotency key (client_order_id_) at a broker that accepts none is refused (REFUSED_LOCALLY), not sent without the key.

Parameters
orderThe order.
Returns
The outcome; on failure last_error() says why, and on success last_ref() is the broker's reference.

Definition at line 108 of file session_executor.hpp.

◆ requested_route()

template<typename Session>
Venue algotradelib::live::SessionExecutor< Session >::requested_route ( Venue asked) const
inlinenoexcept

Returns the venue this executor requests for an order.

Parameters
askedThe order's venue.
Returns
asked, or default_route() if asked is UNSPECIFIED.

Definition at line 80 of file session_executor.hpp.

Referenced by effective_route(), and place().

◆ sellable_inquiry_basis()

template<typename Session>
constexpr SellableBasis algotradelib::live::SessionExecutor< Session >::sellable_inquiry_basis ( )
inlinestaticconstexpr

Returns what the broker's sellable-quantity inquiry establishes, recorded with each figure.

Returns
The basis.

Definition at line 221 of file session_executor.hpp.

◆ sellable_quantity()

template<typename Session>
std::optional< Decimal64 > algotradelib::live::SessionExecutor< Session >::sellable_quantity ( const InstrumentId & instrument)
inline

Asks the broker how much of an instrument may be sold, where the broker answers that by a separate inquiry (SellableSource::INQUIRY).

Elsewhere the figure comes with the holdings, and this returns std::nullopt without a request.

Parameters
instrumentThe instrument.
Returns
The quantity, or std::nullopt if not asked or the inquiry failed (last_error() says why); the runner treats an unknown quantity as nothing sellable.

Definition at line 199 of file session_executor.hpp.

Member Data Documentation

◆ inquires_sellable

template<typename Session>
bool algotradelib::live::SessionExecutor< Session >::inquires_sellable = Caps::sellable_source == SellableSource::INQUIRY
staticconstexpr

true if the sellable quantity is a separate inquiry (one request per instrument sold).

Definition at line 215 of file session_executor.hpp.

◆ reaches_a_broker

template<typename Session>
bool algotradelib::live::SessionExecutor< Session >::reaches_a_broker = true
staticconstexpr

true: a runner built on this executor requires holdings to have been read before it places, however the runner was assembled (see Runner::allow_absent_portfolio).

Definition at line 32 of file session_executor.hpp.


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