Skip to content

Commit 26296bb

Browse files
luisleo526claude
andcommitted
value ownership: the two throw helpers and the closed field vocabulary (EN-132 L0)
Header-only base every EN-132 lane branches from: the source-side strategy_value_invalid throw with the closed `field` vocabulary (src/source/pine_value_admission.hpp) and the generic kernel-side engine_command_value_invalid throw with the stage vocabulary (src/engine_value_invalid.hpp). No call site yet, no behaviour change. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
1 parent 9da4c98 commit 26296bb

2 files changed

Lines changed: 155 additions & 0 deletions

File tree

‎src/engine_value_invalid.hpp‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#pragma once
2+
3+
// Engine-derived invalid execution values (revision 3 section 4): the generic
4+
// kernel-side throw for engine_command_value_invalid (engine_fault, not
5+
// retryable). A value the engine derived from its own book, equity, margin,
6+
// sizing, fee, slippage or settlement state is invalid when it is not finite
7+
// or a checked operation overflowed; the stage names where. Header only, no
8+
// durable state, no hash input. Engine-internal, not installed API.
9+
10+
#include <pineforge/run_failure.hpp>
11+
12+
#include <stdexcept>
13+
14+
namespace pineforge {
15+
16+
enum class EngineValueStage { sizing, margin, fee, slippage, relative_price, risk, settlement };
17+
enum class EngineValueReason { nonfinite, invalid_unicode, numeric_overflow };
18+
19+
inline const char* engine_value_stage_name(EngineValueStage stage) noexcept {
20+
switch (stage) {
21+
case EngineValueStage::sizing: return "sizing";
22+
case EngineValueStage::margin: return "margin";
23+
case EngineValueStage::fee: return "fee";
24+
case EngineValueStage::slippage: return "slippage";
25+
case EngineValueStage::relative_price: return "relative_price";
26+
case EngineValueStage::risk: return "risk";
27+
case EngineValueStage::settlement: return "settlement";
28+
}
29+
return "sizing";
30+
}
31+
32+
inline const char* engine_value_reason_name(EngineValueReason reason) noexcept {
33+
switch (reason) {
34+
case EngineValueReason::nonfinite: return "nonfinite";
35+
case EngineValueReason::invalid_unicode: return "invalid_unicode";
36+
case EngineValueReason::numeric_overflow: return "numeric_overflow";
37+
}
38+
return "nonfinite";
39+
}
40+
41+
/// `field` is an engine-owned literal naming the derived value (for example
42+
/// "sizing.quantity", "margin.required", "fee.commission",
43+
/// "slippage.fill_price", "relative_price.level", "risk.threshold",
44+
/// "settlement.row"); a lane that needs another name lists it in its report,
45+
/// and the ownership manifest enumerates the set.
46+
[[noreturn]] inline void throw_engine_command_value_invalid(
47+
const char* field, EngineValueStage stage, EngineValueReason reason) {
48+
throw coded<std::runtime_error>(
49+
RunFailureCode::engine_command_value_invalid,
50+
RunFailureArgs{{"field", field},
51+
{"stage", engine_value_stage_name(stage)},
52+
{"reason", engine_value_reason_name(reason)}},
53+
"the engine derived an invalid execution value");
54+
}
55+
56+
} // namespace pineforge
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#pragma once
2+
3+
// Selected-window value ownership, source side (revision 3 section 4, Appendix B).
4+
// The one place a source-owned invalid value becomes strategy_value_invalid
5+
// (class strategy). Header only: the lanes that add the admission rules put
6+
// their code in new .cpp/.hpp files of their own and call these functions.
7+
// `field` is ALWAYS one of the engine-owned literals of namespace value_field
8+
// below, never text a script computed; the ownership manifest enumerates this
9+
// list. Not installed API.
10+
11+
#include <pineforge/run_failure.hpp>
12+
13+
#include <stdexcept>
14+
15+
namespace pineforge::source {
16+
17+
enum class StrategyValueReason { nonfinite, invalid_unicode, numeric_overflow };
18+
19+
inline const char* strategy_value_reason_name(StrategyValueReason reason) noexcept {
20+
switch (reason) {
21+
case StrategyValueReason::nonfinite: return "nonfinite";
22+
case StrategyValueReason::invalid_unicode: return "invalid_unicode";
23+
case StrategyValueReason::numeric_overflow: return "numeric_overflow";
24+
}
25+
return "nonfinite";
26+
}
27+
28+
/// The coded failure of a source-owned invalid actionable value. Thrown, so the
29+
/// existing exception path classifies it (RunFailureInfo wins over the type).
30+
[[noreturn]] inline void throw_strategy_value_invalid(const char* field, StrategyValueReason reason) {
31+
throw coded<std::invalid_argument>(
32+
RunFailureCode::strategy_value_invalid,
33+
RunFailureArgs{{"field", field}, {"reason", strategy_value_reason_name(reason)}},
34+
"the strategy supplied an invalid execution value");
35+
}
36+
37+
/// The closed vocabulary of `field`: "<sink>.<argument>". One constant per
38+
/// admitted argument of each sink of revision 3 Appendix B. A lane that needs a
39+
/// name not listed here stops and reports; it does not invent one.
40+
namespace value_field {
41+
// strategy.entry
42+
inline constexpr const char* entry_id = "entry.id";
43+
inline constexpr const char* entry_limit_price = "entry.limit_price";
44+
inline constexpr const char* entry_stop_price = "entry.stop_price";
45+
inline constexpr const char* entry_qty = "entry.qty";
46+
inline constexpr const char* entry_comment = "entry.comment";
47+
inline constexpr const char* entry_oca_name = "entry.oca_name";
48+
// strategy.order
49+
inline constexpr const char* order_id = "order.id";
50+
inline constexpr const char* order_limit_price = "order.limit_price";
51+
inline constexpr const char* order_stop_price = "order.stop_price";
52+
inline constexpr const char* order_qty = "order.qty";
53+
inline constexpr const char* order_comment = "order.comment";
54+
inline constexpr const char* order_oca_name = "order.oca_name";
55+
// strategy.exit
56+
inline constexpr const char* exit_id = "exit.id";
57+
inline constexpr const char* exit_from_entry = "exit.from_entry";
58+
inline constexpr const char* exit_limit_price = "exit.limit_price";
59+
inline constexpr const char* exit_stop_price = "exit.stop_price";
60+
inline constexpr const char* exit_trail_points = "exit.trail_points";
61+
inline constexpr const char* exit_trail_offset = "exit.trail_offset";
62+
inline constexpr const char* exit_trail_price = "exit.trail_price";
63+
inline constexpr const char* exit_qty_percent = "exit.qty_percent";
64+
inline constexpr const char* exit_qty = "exit.qty";
65+
inline constexpr const char* exit_comment = "exit.comment";
66+
inline constexpr const char* exit_oca_name = "exit.oca_name";
67+
inline constexpr const char* exit_profit_ticks = "exit.profit_ticks";
68+
inline constexpr const char* exit_loss_ticks = "exit.loss_ticks";
69+
// strategy.close / close_all / cancel / cancel_all / exit_cancel_bracket
70+
inline constexpr const char* close_id = "close.id";
71+
inline constexpr const char* close_comment = "close.comment";
72+
inline constexpr const char* close_qty = "close.qty";
73+
inline constexpr const char* close_qty_percent = "close.qty_percent";
74+
inline constexpr const char* exit_cancel_bracket_exit_id = "exit_cancel_bracket.exit_id";
75+
inline constexpr const char* exit_cancel_bracket_from_entry = "exit_cancel_bracket.from_entry";
76+
inline constexpr const char* exit_cancel_bracket_comment = "exit_cancel_bracket.comment";
77+
inline constexpr const char* cancel_id = "cancel.id";
78+
// the six risk setters
79+
inline constexpr const char* risk_direction = "risk.direction";
80+
inline constexpr const char* risk_max_cons_loss_days = "risk.max_cons_loss_days";
81+
inline constexpr const char* risk_max_drawdown = "risk.max_drawdown";
82+
inline constexpr const char* risk_max_intraday_loss = "risk.max_intraday_loss";
83+
inline constexpr const char* risk_max_intraday_filled_orders = "risk.max_intraday_filled_orders";
84+
inline constexpr const char* risk_max_position_size = "risk.max_position_size";
85+
// strategy() declaration (PineStrategyConfig / StrategyOverrides)
86+
inline constexpr const char* strategy_initial_capital = "strategy.initial_capital";
87+
inline constexpr const char* strategy_default_qty_value = "strategy.default_qty_value";
88+
inline constexpr const char* strategy_commission_value = "strategy.commission_value";
89+
inline constexpr const char* strategy_margin_long = "strategy.margin_long";
90+
inline constexpr const char* strategy_margin_short = "strategy.margin_short";
91+
inline constexpr const char* strategy_default_qty_type = "strategy.default_qty_type";
92+
inline constexpr const char* strategy_commission_type = "strategy.commission_type";
93+
inline constexpr const char* strategy_pyramiding = "strategy.pyramiding";
94+
inline constexpr const char* strategy_slippage = "strategy.slippage";
95+
// a bound input value (declaration default or supplied value)
96+
inline constexpr const char* input_value = "input.value";
97+
} // namespace value_field
98+
99+
} // namespace pineforge::source

0 commit comments

Comments
 (0)