![]() |
algotradelib 0.0.0.9000
C++ header-only library for algorithmic trading
|
The production wiring of a live run, with no broker named: the part of example-live-program a consumer keeps. More...
#include <algotradelib/live>#include <algotradelib/runner>#include <chrono>#include <cstddef>#include <ostream>#include <string>#include <string_view>#include <utility>#include <vector>Go to the source code of this file.
Classes | |
| struct | live_program::Settings |
| What a run is told, gathered so main states it once and a test can state it differently. More... | |
Enumerations | |
| enum class | live_program::Exit : int { CLEAN = 0 , CLOSING_INCOMPLETE = 1 , JOURNAL_REFUSED = 2 , RECOVERY_HALTED = 3 , REFERENCE_UNREADABLE = 4 , LOOP_ABANDONED = 5 , LOCAL_FAILURE = 6 , ACCOUNT_UNRESOLVED = 7 , OWED_ORDER = 8 } |
| What the program exits with, so a supervisor can tell its endings apart. More... | |
Functions | |
| template<typename Session, typename Runner> | |
| bool | live_program::load_reference_data (Session &session, Runner &bound, const Settings &settings, std::ostream &out) |
| Reads each instrument's reference data (lot size, price grid) onto the runner, once; the loop does not poll it, and no order can be built without it. | |
| void | live_program::print_recovery (const runner::RecoveryReport &recovery, std::ostream &out) |
| Prints what recovery found, in the words an operator acts on. | |
| void | live_program::print_how_to_stop (const Settings &settings, std::ostream &out) |
| Prints how to stop the run, before it starts, so nobody reaches for kill -9. | |
| void | live_program::print_loop (const runner::LoopReport &report, std::ostream &out) |
| Prints the loop's own figures and notes, which read the same in both modes. | |
| void | live_program::print_report (const runner::LoopReport &report, std::ostream &out) |
| Prints the loop report and what closing_complete() does and does not mean. | |
| bool | live_program::stop_closes (const runner::LoopReport &report) noexcept |
| Tests whether a run ended with a stop that sends closing instructions. | |
| template<typename Loop> | |
| void | live_program::configure (Loop &loop, const Settings &settings) |
| Configures the loop the same way for both modes: every age stated, the control file installed. | |
| template<typename Strategy, typename Session, typename MarketData, typename Clock = runner::SteadyClock> | |
| Exit | live_program::trade (Session &session, MarketData &market_data, Strategy strategy_instance, const Settings &settings, runner::StopSource &stop, std::ostream &out, Clock clock={}) |
| Trades a strategy through a session, reading market data and reference data from another. | |
| template<typename Strategy, typename Session, typename Clock = runner::SteadyClock> | |
| Exit | live_program::trade (Session &session, Strategy strategy_instance, const Settings &settings, runner::StopSource &stop, std::ostream &out, Clock clock={}) |
| Trades a strategy through a session: journal, recover, loop, report. | |
| template<typename Strategy, typename Session, typename MarketData, typename Clock = runner::SteadyClock> | |
| Exit | live_program::observe (Session &session, MarketData &market_data, Strategy strategy_instance, const Settings &settings, runner::StopSource &stop, std::ostream &out, Clock clock={}) |
| Runs a strategy against a session's account and another's market data, with nothing to send through. | |
| template<typename Strategy, typename Session, typename Clock = runner::SteadyClock> | |
| Exit | live_program::observe (Session &session, Strategy strategy_instance, const Settings &settings, runner::StopSource &stop, std::ostream &out, Clock clock={}) |
| Observes a strategy against a session's real data, reading market data from it too. | |
The production wiring of a live run, with no broker named: the part of example-live-program a consumer keeps.
example-live-program.cpp chooses a broker and calls live_program::trade or live_program::observe. Everything that makes a run safe to restart is here, in the order it has to happen, and the test suite drives it against an in-memory session – which a main could not be.
The order is the whole point, and each step exists because leaving it out fails silently:
Definition in file live_program.hpp.
|
strong |
What the program exits with, so a supervisor can tell its endings apart.
Definition at line 105 of file live_program.hpp.
| void live_program::configure | ( | Loop & | loop, |
| const Settings & | settings ) |
Configures the loop the same way for both modes: every age stated, the control file installed.
| Loop | The loop type. |
| loop | The loop. |
| settings | The settings. |
Definition at line 295 of file live_program.hpp.
| bool live_program::load_reference_data | ( | Session & | session, |
| Runner & | bound, | ||
| const Settings & | settings, | ||
| std::ostream & | out ) |
Reads each instrument's reference data (lot size, price grid) onto the runner, once; the loop does not poll it, and no order can be built without it.
| Session | The session type. |
| Runner | The runner type. |
| session | The session to read from. |
| bound | The runner. |
| settings | The settings (its universe). |
| out | Where to print a failure. |
Definition at line 144 of file live_program.hpp.
| Exit live_program::observe | ( | Session & | session, |
| MarketData & | market_data, | ||
| Strategy | strategy_instance, | ||
| const Settings & | settings, | ||
| runner::StopSource & | stop, | ||
| std::ostream & | out, | ||
| Clock | clock = {} ) |
Runs a strategy against a session's account and another's market data, with nothing to send through.
live::bind_observer gives the runner the session's real capabilities and no executor that reaches the broker, so the pipeline, the guard and the gates all run, and no order can leave. No journal is opened.
| Strategy | The strategy type. |
| Session | The account session type. |
| MarketData | The market-data session type. |
| Clock | The clock type. |
| session | The account session. |
| market_data | The session market data is read from. |
| strategy_instance | The strategy. |
| settings | The settings. |
| stop | The stop source the loop polls. |
| out | Where the program prints. |
| clock | The clock. |
Definition at line 495 of file live_program.hpp.
| Exit live_program::observe | ( | Session & | session, |
| Strategy | strategy_instance, | ||
| const Settings & | settings, | ||
| runner::StopSource & | stop, | ||
| std::ostream & | out, | ||
| Clock | clock = {} ) |
Observes a strategy against a session's real data, reading market data from it too.
| Strategy | The strategy type. |
| Session | The session type. |
| Clock | The clock type. |
| session | The session. |
| strategy_instance | The strategy. |
| settings | The settings. |
| stop | The stop source the loop polls. |
| out | Where the program prints. |
| clock | The clock. |
Definition at line 544 of file live_program.hpp.
|
inline |
Prints how to stop the run, before it starts, so nobody reaches for kill -9.
| settings | The settings (its control file). |
| out | Where to print. |
Definition at line 193 of file live_program.hpp.
|
inline |
Prints the loop's own figures and notes, which read the same in both modes.
| report | The loop report. |
| out | Where to print. |
Definition at line 216 of file live_program.hpp.
|
inline |
Prints what recovery found, in the words an operator acts on.
| recovery | The recovery report. |
| out | Where to print. |
Definition at line 162 of file live_program.hpp.
|
inline |
Prints the loop report and what closing_complete() does and does not mean.
| report | The loop report. |
| out | Where to print. |
Definition at line 272 of file live_program.hpp.
|
inlinenoexcept |
Tests whether a run ended with a stop that sends closing instructions.
| report | The loop report. |
Definition at line 284 of file live_program.hpp.
| Exit live_program::trade | ( | Session & | session, |
| MarketData & | market_data, | ||
| Strategy | strategy_instance, | ||
| const Settings & | settings, | ||
| runner::StopSource & | stop, | ||
| std::ostream & | out, | ||
| Clock | clock = {} ) |
Trades a strategy through a session, reading market data and reference data from another.
This places orders, through session only; market_data is only read. Use a session that cannot trade for market_data (a KIS session with an empty KisAccount, a Toss session with account sequence 0), so that a swapped pair refuses rather than trades.
| Strategy | The strategy type. |
| Session | The trading session type. |
| MarketData | The market-data session type. |
| Clock | The clock type. |
| session | The session orders go through. |
| market_data | The session market data is read from. |
| strategy_instance | The strategy. |
| settings | The settings. |
| stop | The stop source the loop polls. |
| out | Where the program prints. |
| clock | The clock. |
Definition at line 325 of file live_program.hpp.
| Exit live_program::trade | ( | Session & | session, |
| Strategy | strategy_instance, | ||
| const Settings & | settings, | ||
| runner::StopSource & | stop, | ||
| std::ostream & | out, | ||
| Clock | clock = {} ) |
Trades a strategy through a session: journal, recover, loop, report.
This places orders. observe is the same loop with nowhere to send.
| Strategy | The strategy type. |
| Session | The session type. |
| Clock | The clock type. |
| session | The session (orders and market data). |
| strategy_instance | The strategy. |
| settings | The settings. |
| stop | The stop source the loop polls. |
| out | Where the program prints. |
| clock | The clock. |
Definition at line 462 of file live_program.hpp.