|
FastMM C++ API 0.6.0
Public headers, tier 1 and tier 2
|
Strategy hooks (ADR-0012): the hook table, the compile-time checker and the Fill view. More...
#include "fastmm/core/enums.hpp"#include "fastmm/core/fixed_point.hpp"#include "fastmm/core/messages.hpp"#include "fastmm/core/oms.hpp"#include "fastmm/core/strong_id.hpp"#include "fastmm/core/timer_wheel.hpp"#include <array>#include <concepts>#include <cstddef>#include <cstdint>#include <string_view>#include <type_traits>Go to the source code of this file.
Classes | |
| struct | fastmm::Fill |
| One execution as a strategy sees it (on_fill). More... | |
| struct | fastmm::RiskReject |
| A new order or replace the engine's own risk check refused (RiskEngine, [risk]): nothing was sent and no order exists for it. More... | |
| struct | fastmm::HookInfo |
Namespaces | |
| namespace | fastmm |
Concepts | |
| concept | fastmm::KeepsState |
Optional state the engine keeps across sessions ([strategy] state_file): std::string_view state() returns the bytes to save (valid until the strategy's next hook; the engine copies them at once) and bool restore(std::string_view) takes the bytes saved before, false when they are not this strategy's (it then starts fresh). | |
Macros | |
| #define | FASTMM_STRATEGY_HOOKS(X) |
| The hook table. | |
| #define | FASTMM_STRATEGY_HOOK_NEAR_MISSES(Y) |
| Y(misspelling, hook): names that produce a "did you mean" warning. | |
| #define | FASTMM_HOOK_ENUM(E, name, word, params, args, sig) E, |
| #define | FASTMM_HOOK_INFO(E, name, word, params, args, sig) {Hook::E, #name, word, sig}, |
| #define | FASTMM_HOOK_UNPAREN(...) __VA_ARGS__ |
| #define | FASTMM_HOOK_PROBE(name) |
| #define | FASTMM_HOOK_CALL(E, name, word, params, args, sig) |
| #define | FASTMM_HOOK_NEAR_MISS(name, hook) |
| #define | FASTMM_HOOK_STATUS(E, name, word, params, args, sig) |
| #define | FASTMM_HOOK_ASSERT(E, name, word, params, args, sig) |
| #define | FASTMM_HOOK_WARN(name, hook) |
Enumerations | |
| enum class | fastmm::Hook : std::uint8_t { fastmm::FASTMM_HOOK_ENUM , fastmm::FASTMM_STRATEGY_HOOKS } |
| enum class | fastmm::HookStatus : std::uint8_t { fastmm::Absent , fastmm::Ok , fastmm::Mismatch } |
| Absent: no member with the hook's name. More... | |
Functions | |
| template<class S , class Ctx , class Book > | |
| constexpr HookStatus | fastmm::hook_status (Hook h) noexcept |
| template<class S , class Ctx , class Book > | |
| constexpr bool | fastmm::implements_hook (Hook h) noexcept |
True when the engine calls S's hook h (the engine dispatches on this at compile time). | |
| template<class S , class Ctx = detail::hooks::StandInContext, class Book = detail::hooks::StandInBook> | |
| constexpr bool | fastmm::verify_strategy () noexcept |
Compile-time check of every hook of S; always returns true (failures are static_asserts), so it can be written as static_assert(fastmm::verify_strategy<MyMM>());. | |
| template<class S , class Ctx , class Book > | |
| constexpr std::string_view | fastmm::implemented_hooks () noexcept |
| The implemented hooks as words in table order ("start book fill timer connection quoting"). | |
Variables | |
| constexpr std::array< HookInfo, static_cast< std::size_t >(Hook::Count)> | fastmm::kHooks |
Strategy hooks (ADR-0012): the hook table, the compile-time checker and the Fill view.
A strategy is a plain class. Its hooks are ordinary public member functions, all optional:
on_start(ctx) on_stop(ctx) on_book(ctx, id, book) on_book_ticker(ctx, id, m) on_trade(ctx, id, m) on_option_ticker(ctx, id, m) on_fill(ctx, fill) on_order_update(ctx, u) on_timer(ctx, timer_id, tag) on_connection(ctx, m) on_quoting(ctx, enabled) on_params(ctx) on_balance(ctx, m) on_perp_state(ctx, id, m) on_risk_reject(ctx, r) on_batch_end(ctx)
The engine checks every hook name when it is instantiated. If the strategy has a member with a hook's name (function, template, data member, static, inherited or private) and the engine's call does not compile, the build stops with one error per hook:
fastmm: on_trade has the wrong signature or is not public; expected void on_trade(auto& ctx, InstrumentId id, const TradeMsg& m)
A few likely misspellings (on_fills, on_tick, onBook, ...) produce a deprecation warning instead, because a private helper may use such a name; static constexpr bool fastmm_allow_near_miss_names = true; in the strategy silences it. Strategy headers can run the same check early with stand-in context and book types:
static_assert(fastmm::verify_strategy<MyMM>());
Limits:
final class loses the name probe; only the call check remains, so a wrong signature is silently not called;auto) return type must not be checked with verify_strategy: the stand-in types instantiate its body;| #define FASTMM_STRATEGY_HOOKS | ( | X | ) |
The hook table.
X(Enum, name, word, (parameters), (arguments), "expected signature"). The parameters name the engine's call; Ctx and Book are the engine's context and book types.
| #define FASTMM_STRATEGY_HOOK_NEAR_MISSES | ( | Y | ) |
Y(misspelling, hook): names that produce a "did you mean" warning.
| #define FASTMM_HOOK_ENUM | ( | E, | |
| name, | |||
| word, | |||
| params, | |||
| args, | |||
| sig | |||
| ) | E, |
| #define FASTMM_HOOK_INFO | ( | E, | |
| name, | |||
| word, | |||
| params, | |||
| args, | |||
| sig | |||
| ) | {Hook::E, #name, word, sig}, |
| #define FASTMM_HOOK_UNPAREN | ( | ... | ) | __VA_ARGS__ |
| #define FASTMM_HOOK_PROBE | ( | name | ) |
| #define FASTMM_HOOK_CALL | ( | E, | |
| name, | |||
| word, | |||
| params, | |||
| args, | |||
| sig | |||
| ) |
| #define FASTMM_HOOK_NEAR_MISS | ( | name, | |
| hook | |||
| ) |
| #define FASTMM_HOOK_STATUS | ( | E, | |
| name, | |||
| word, | |||
| params, | |||
| args, | |||
| sig | |||
| ) |
| #define FASTMM_HOOK_ASSERT | ( | E, | |
| name, | |||
| word, | |||
| params, | |||
| args, | |||
| sig | |||
| ) |
| #define FASTMM_HOOK_WARN | ( | name, | |
| hook | |||
| ) |