|
| | RiskGuard (RiskLimits limits={}) |
| | Constructs a guard.
|
| const RiskLimits & | limits () const noexcept |
| | Returns the limits.
|
| bool | permits_phase (MarketPhase phase) const noexcept |
| | Tests whether a phase permits opening or increasing a position.
|
| void | halt () noexcept |
| | Takes the operator's hold (HaltReason::OPERATOR): no order or cancellation is sent until resume().
|
| void | halt (HaltReason reason, std::string detail) |
| | Takes a hold, with a description.
|
| void | halt (HaltReason reason) |
| | Takes a hold, with no description.
|
| void | resume () noexcept |
| | Releases the operator's hold; other holds, if any, still stop trading.
|
| void | resume (HaltReason reason) noexcept |
| | Releases a hold; releasing one that is not held does nothing.
|
| bool | halted () const noexcept |
| | Tests whether any hold is in force.
|
| bool | halted (HaltReason reason) const noexcept |
| | Tests whether one hold is in force.
|
| std::optional< HaltReason > | blocking_reason () const noexcept |
| | Returns the hold that stops placements, the most fundamental first.
|
| std::optional< HaltReason > | blocking_reason_for (InstructionClass klass) const noexcept |
| | Returns the hold that stops an instruction class, the most fundamental first.
|
| std::vector< HaltReason > | holds () const |
| | Returns every hold in force.
|
| void | note_sent (std::chrono::system_clock::time_point when) |
| | Records that a request was sent, for the rate limit.
|
| std::size_t | total_sent () const noexcept |
| | Returns how many orders have been recorded with note_sent over the guard's life.
|
| std::size_t | recent_orders (std::chrono::system_clock::time_point now) const |
| | Returns how many orders were sent within RiskLimits::rate_window_ before an instant.
|
| void | forget_before (std::chrono::system_clock::time_point cutoff) |
| | Forgets sends recorded before an instant, to bound memory.
|
| template<typename Broker> |
| std::optional< GuardRejection > | check (const PlannedOrder &order, const Portfolio< Broker > &portfolio, const GuardInputs &inputs) const |
| | Checks one planned order against the limits and holds.
|
| template<typename Broker> |
| GuardDecision | evaluate (const PlannedOrder &order, const Portfolio< Broker > &portfolio, const GuardInputs &inputs) const |
| | Checks one planned order, and reports whether only the closing exception admitted it.
|
Checks planned orders against RiskLimits, holds trading stopped, and counts orders sent.
The rate limit counts what was recorded with note_sent. The runner records every placement or cancellation that was sent or may have been sent: accepted, rejected by the broker, or of unknown outcome. A request refused before sending (by this guard, the binding or the adapter) is not recorded, so it uses no budget.
- Note
- Not thread-safe; one guard belongs to one runner.
Definition at line 706 of file risk.hpp.
template<typename Broker>
Checks one planned order, and reports whether only the closing exception admitted it.
Checks run in this order and the first failure is reported: holds, permitted universe, permitted phases (with the closing-toward-flat exception), order rate, order notional, sellable quantity, buying power, position ceiling, gross exposure ceiling.
- Template Parameters
-
| Broker | The portfolio's broker tag. |
- Parameters
-
| order | The order to check. |
| portfolio | The current positions and working orders. |
| inputs | The instant, phase, prices and currencies the checks need. |
- Returns
- The decision.
Definition at line 927 of file risk.hpp.
Referenced by check().
| void algotradelib::strategy::RiskGuard::note_sent |
( |
std::chrono::system_clock::time_point | when | ) |
|
|
inline |
Records that a request was sent, for the rate limit.
The runner calls it for each placement or cancellation the broker accepted, rejected, or may have received (unknown outcome).
- Parameters
-
| when | When the order was sent. |
Definition at line 854 of file risk.hpp.