add_ruleSave a condition, append a rule, or reuse a saved definition.
Area
Strategy Builder
Group
Authoring
Access
Write
Risk
May change server state
▸Details
Full description
Details
Create a condition and optionally append a rule, or reuse definition_id.
Condition and value accept model objects or formulas: condition="rsi(14) < 30", value="close - 2 * atr(14)". get_strategy returns formulas beside the models. Formulas use comparisons, chained ranges, and/or/not, + - * /, abs/min/max, close/open/high/low, volume, numbers, True/False, lists and saved names. Functions are model kinds and indicator names: required fields are positional, other fields keyword-only, and literals take strings. Nested records use string-keyed braces, for example sequence([{'condition': setup}]).
Supply exactly one of condition, value or definition_id. A value saves a strategy-local expression with an explicit name; it cannot have a role or rule fields. Use {kind: named_value, value_id: name_or_id} wherever a full per-symbol value operand is accepted. Names resolve on write to stable ids. Edit /values/<id>/source or /name; delete with null only after removing references. Definitions compose but cannot form cycles. There are no function arguments; research varies each definition's source parameters once. Consumer restrictions apply after expansion. Omit role to save a new condition for reuse without activating it. Reuse creates only a rule. Names must be unique snake_case labels in this strategy. Compose inline with condition_ref children. Protective stop/target policies belong directly on exit rules and cannot sit under combinators. Entry requires direction; exit accepts size_frac. Returns server-issued ids and the new version; call add_rule and edit_strategy one at a time, passing that returned version as the next expected_version (parallel calls conflict). Read builder_discover(action='quickstart') and author from it. Fetch details only when information is missing or a refusal asks for them. Returns readiness (ready|incomplete|refused, blockers, warnings) of the stored document; a run starts only when it is ready.
Capabilities
Bounded options and operating modes surfaced above the full JSON schema.
Required Inputs
strategy_idstringStrategy IDOptional Inputs
conditionanyOf (3 variants)Condition object with a "kind" discriminator or formula, e.g. "rsi(14) < 30". Read builder_discover(action='quickstart') and author from its formulas. Fetch details only when information is missing or a refusal asks for them. Combinators may hold inline conditions or condition_ref children.definition_idanyOf (2 variants)Existing condition definition in this strategy to reuse; requires roledirectionanyOf (2 variants)Entry role: required ('long' or 'short'). Exit role: optionally scope the exit to that position direction; None means BOTH long and short. Not used for gates.event_study_result_idanyOf (2 variants)Optional evidence link: the event_study_result_id of the one-symbol result (a row of get_run(kind='event_study')) that validated this condition.expected_versionanyOf (2 variants)Refuse unless the stored version equals this value; use the latest returned version or read get_strategynameanyOf (2 variants)Optional strategy-scoped definition name (snake_case, at most 48 chars, leading letter, unique within the strategy; excludes entry/exit/gate/overlay and c_<8 hex chars>). Auto-generated if omitted.remainder_unprotectedanyOf (2 variants)Exit role: explicit consent to leave a partial stop's remainder unprotected. Otherwise another exit must cover the remainder.roleanyOf (2 variants)Rule role: entry, exit, or gate. Every gate must be true to permit an entry; false or unknown blocks entries. Gates do not close positions.size_fracanyOf (2 variants)Exit role: fraction to close, greater than 0 through 1. None = full close.thenanyOf (2 variants)Entry role: the order it places, {"order": "market"} or a resting stop, limit or stop_limit with its prices; omit to use the strategy's execution.valueanyOf (3 variants)Reusable per-symbol value object or formula, e.g. 'close - 2 * atr(14)'; requires name and forbids rule fields. Reference with kind=named_value and value_id=name or id.whenanyOf (2 variants)Entry or exit role: when the rule decides; omit to decide at each bar close. With when, condition may be omitted: the rule then acts at each occurrence.