algotradelib 0.0.0.9000
C++ header-only library for algorithmic trading
Loading...
Searching...
No Matches
bind.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "./session_executor.hpp"
4
5#include "../runner/journal.hpp"
6#include "../runner/runner.hpp"
7
8#include <cstddef>
9#include <utility>
10
11namespace algotradelib {
12namespace live {
13
22
24inline constexpr std::size_t default_series_capacity = 512;
25
31template <typename Strategy, typename Session>
34
40template <typename Strategy, typename Session>
42 Strategy, typename Session::Caps, typename Session::BrokerTag, runner::RecordingExecutor<typename Session::BrokerTag>
43>;
44
63template <typename Strategy, typename Session>
65 Session& session, Strategy strategy, strategy::RiskLimits limits = {},
66 std::size_t series_capacity = default_series_capacity, Venue default_route = Venue::UNSPECIFIED
67) {
69 std::move(strategy), std::move(limits), series_capacity, SessionExecutor<Session>(session, default_route)
70 );
71 // **A runner that can reach a broker requires an account it has actually read** -- and that is not
72 // arranged here. It comes from `SessionExecutor::reaches_a_broker`, so a runner assembled by hand
73 // carries it too: `doxygen/vignettes/binding-a-broker.md` shows exactly that, and a rule this
74 // factory installed would hold for its own callers and for nobody else. A run that genuinely reads
75 // no holdings says `allow_absent_portfolio()` on the runner.
76 return bound;
77}
78
86template <typename Strategy, typename Session, typename Journal, typename Clock = runner::SteadyClock>
88 Strategy, typename Session::Caps, typename Session::BrokerTag,
90>;
91
121template <typename Strategy, typename Session, typename Journal, typename Clock = runner::SteadyClock>
123 Session& session, Journal& journal, Strategy strategy, strategy::RiskLimits limits = {},
124 std::size_t series_capacity = default_series_capacity, Venue default_route = Venue::UNSPECIFIED, Clock clock = {}
125) {
127 std::move(strategy), std::move(limits), series_capacity,
128 runner::JournalingExecutor<SessionExecutor<Session>, Journal, Clock>(
129 SessionExecutor<Session>(session, default_route), journal, std::move(clock)
130 )
131 );
132 // As in `bind`: the requirement travels with the executor, not with this factory.
133 return bound;
134}
135
152template <typename Strategy, typename Session>
154 Session& session, Strategy strategy, strategy::RiskLimits limits = {},
155 std::size_t series_capacity = default_series_capacity
156) {
157 (void)session;
158 return ObservingRunner<Strategy, Session>(std::move(strategy), std::move(limits), series_capacity, {});
159}
160
161} // namespace live
162} // namespace algotradelib
An executor wrapper that records each instruction in a journal before sending it.
Definition journal.hpp:842
An executor that sends nothing and records what it was given (the dry run's default).
Runs one strategy: feeds it events, reconciles what it asks for, checks the risk limits,...
Definition runner.hpp:305
Connects a runner to a broker session for live trading.
Definition bind.hpp:12
constexpr std::size_t default_series_capacity
The number of trailing bars per instrument a bound runner keeps by default.
Definition bind.hpp:24
runner::Runner< Strategy, typename Session::Caps, typename Session::BrokerTag, runner::JournalingExecutor< SessionExecutor< Session >, Journal, Clock > > JournaledRunner
The runner type bind_journaled returns: the same pipeline, journaling before it sends.
Definition bind.hpp:87
JournaledRunner< Strategy, Session, Journal, Clock > bind_journaled(Session &session, Journal &journal, Strategy strategy, strategy::RiskLimits limits={}, std::size_t series_capacity=default_series_capacity, Venue default_route=Venue::UNSPECIFIED, Clock clock={})
Binds a strategy to a broker session, recording every instruction in a journal before it is sent.
Definition bind.hpp:122
ObservingRunner< Strategy, Session > bind_observer(Session &session, Strategy strategy, strategy::RiskLimits limits={}, std::size_t series_capacity=default_series_capacity)
Binds a strategy for observation: the session's capabilities and broker tag, and nothing to send thro...
Definition bind.hpp:153
runner::Runner< Strategy, typename Session::Caps, typename Session::BrokerTag, runner::RecordingExecutor< typename Session::BrokerTag > > ObservingRunner
The runner type bind_observer returns: the same capabilities and tag, sending nowhere.
Definition bind.hpp:41
runner::Runner< Strategy, typename Session::Caps, typename Session::BrokerTag, SessionExecutor< Session > > BoundRunner
The runner type bind returns.
Definition bind.hpp:32
BoundRunner< Strategy, Session > bind(Session &session, Strategy strategy, strategy::RiskLimits limits={}, std::size_t series_capacity=default_series_capacity, Venue default_route=Venue::UNSPECIFIED)
Binds a strategy to a broker session, so its instructions are sent to the broker.
Definition bind.hpp:64
What a strategy sees and emits: events, intents, the portfolio, reconciliation and risk limits.
Definition concept.hpp:16
The library: broker-neutral types (core), and the modules below.
Venue
A trading venue: an exchange, or the combined view across exchanges.
Definition types.hpp:45
The limits the operator sets for RiskGuard.
Definition risk.hpp:412