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>
33 Strategy,
34 typename Session::Caps,
35 typename Session::BrokerTag,
37>;
38
44template <typename Strategy, typename Session>
46 Strategy,
47 typename Session::Caps,
48 typename Session::BrokerTag,
50>;
51
70template <typename Strategy, typename Session>
72 Session& session,
73 Strategy strategy,
74 strategy::RiskLimits limits = {},
75 std::size_t series_capacity = default_series_capacity,
76 Venue default_route = Venue::UNSPECIFIED
77) {
79 std::move(strategy),
80 std::move(limits),
81 series_capacity,
82 SessionExecutor<Session>(session, default_route)
83 );
84 // **A runner that can reach a broker requires an account it has actually read** -- and that is not
85 // arranged here. It comes from `SessionExecutor::reaches_a_broker`, so a runner assembled by hand
86 // carries it too: `doxygen/vignettes/binding-a-broker.md` shows exactly that, and a rule this
87 // factory installed would hold for its own callers and for nobody else. A run that genuinely reads
88 // no holdings says `allow_absent_portfolio()` on the runner.
89 return bound;
90}
91
99template <typename Strategy, typename Session, typename Journal, typename Clock = runner::SteadyClock>
101 Strategy,
102 typename Session::Caps,
103 typename Session::BrokerTag,
105>;
106
136template <typename Strategy, typename Session, typename Journal, typename Clock = runner::SteadyClock>
138 Session& session,
139 Journal& journal,
140 Strategy strategy,
141 strategy::RiskLimits limits = {},
142 std::size_t series_capacity = default_series_capacity,
143 Venue default_route = Venue::UNSPECIFIED,
144 Clock clock = {}
145) {
147 std::move(strategy),
148 std::move(limits),
149 series_capacity,
150 runner::JournalingExecutor<SessionExecutor<Session>, Journal, Clock>(
151 SessionExecutor<Session>(session, default_route), journal, std::move(clock)
152 )
153 );
154 // As in `bind`: the requirement travels with the executor, not with this factory.
155 return bound;
156}
157
174template <typename Strategy, typename Session>
176 Session& session,
177 Strategy strategy,
178 strategy::RiskLimits limits = {},
179 std::size_t series_capacity = default_series_capacity
180) {
181 (void)session;
183 std::move(strategy), std::move(limits), series_capacity, {}
184 );
185}
186
187} // namespace live
188} // namespace algotradelib
The executor that sends a runner's orders and cancellations through a broker session.
An executor wrapper that records each instruction in a journal before sending it.
Definition journal.hpp:695
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:297
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::RecordingExecutor< typename Session::BrokerTag > > ObservingRunner
The runner type bind_observer returns: the same capabilities and tag, sending nowhere.
Definition bind.hpp:45
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:137
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:175
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:100
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:71
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:43
The limits the operator sets for RiskGuard.
Definition risk.hpp:268