|
| 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