Apply Strategy Patch
tt_apply_strategy_patchApply a JSON-Patch (RFC 6902) to an existing strategy.
exchange_brokers: {exchange: broker_id}. Send ONLY on the re-call after a STRATEGY_EXCHANGE_BROKER_REQUIRED refusal, with the broker the USER picked from details.missing[].brokers. Never pick one yourself. On success relay data.subscriber_broker_warning if present.
MOVING ONE VALUE EVERYWHERE IT APPEARS — use rewrite, not patch.
rewrite={"dimension": "timeframe", "from": "1m", "to": "5m"} changes
the candle timeframe at EVERY site in the strategy in one small call:
both text forms and the builder tree of every condition, plus every
tt_get_data call in the Python block. Hand-authoring that is not a
realistic ask — condition_json is a JSON-ENCODED STRING, so no pointer
reaches inside it and a three-character change means re-sending every
builder tree in the strategy. Prefer one rewrite call over per-condition
patches or splitting the work across calls. The three-representation rule below is
satisfied automatically, and the partial-edit guard proves no site was
left on the old value. from may be written any way ('1 minute', '1min',
'1m'); the canonical token is what gets written. A miss returns the
timeframes the strategy DOES hold, so the retry is exact.
rewrite and patch compose — explicit ops win on their own fields.
Underlying swaps are NOT rewritable (lot size, strike step, expiry and
the instrument id all move with the symbol); the refusal says so and
names tt_check_underlying_support.
LIVE-EDIT CONFIRM GATE: if this template is DEPLOYED, has SUBSCRIBERS, or is PUBLIC, a NON-dry-run call refuses once with LIVE_EDIT_CONFIRMATION_REQUIRED — carrying the blast radius, the live-position consequences, and a copy alternative. RELAY those to the user, ask one confirm question, and only after the user explicitly agrees re-call with the SAME arguments plus live_edit_confirmed=true. Never set it on your own initiative. dry_run=True (the default) is never gated.
A patch that removes or blanks the strategy's Universal Exit is
refused (STRATEGY_EDIT_UE_REMOVED) unless
allow_universal_exit_removal=True. When ADDING a repair condition,
insert it BEFORE the set's Exit condition (explicit index, not
"/conditions/-") — conditions evaluate in array order and a repair
after the Exit is dead code (CONDITION_ORDER_EXIT_BEFORE_REPAIR).
ANY change to a leg's underlying — INCLUDING a same-exchange swap
such as Crudeoil → NaturalGas, not only across asset classes —
requires re-deriving every dependent field in the SAME patch:
expiry, expiry_type, strike, strike_type, strike_display,
strike_json, product_type, qty_type, and the numeric instrument
id (set it to 0 to let the server resolve it — a stale non-zero id
is trusted as-is and never re-derived). Call
tt_check_underlying_support() BEFORE composing the
patch: lot size and strike step differ between underlyings
(Crudeoil 100, NaturalGas 1250), so the leg cannot carry over.
Expiry keyword families: NFO/BFO Current Week/Month Expiry · MCX
MCX Fut Expiry / MCX Option Expiry · crypto Crypto Current
Day/Week/Month Expiry (perpetual = literal 2099-12-31).
Leaving any of them stale is refused as
LEG_SYMBOL_REFERENCE_DESYNC — before that guard existed, a
same-exchange swap validated 0 errors / 0 warnings and traded the
OLD contract.
Use this for SURGICAL structural edits — adding / removing / reordering / modifying an individual set, condition, or leg without re-sending the whole strategy. The post-patch state is POSTed as the clean create-shape and round-trip-verified by content count; it FAILS LOUD (STRATEGY_PATCH_CONTENT_DROPPED) if TT drops content. For a full sets-array replacement or scalar fields, tt_update_strategy also works.
SET IDS CHANGE ON EVERY SAVE. Tradetron recreates every set row on
a write, so a non-dry-run patch, even a one-value one, gives every
set a new id (each condition's strategy_template_set_id moves with
it); condition and leg ids are kept. data.set_ids maps each set's
sent id to its stored one. Never reuse a set id read before a save.
TT INJECTS READ-SIDE SCAFFOLDS (verified against the
live API 2026-08-07): the GET/fetch response appends inert blank
envelopes — Add Repair + Exit per set, and Add Repair +
Repair Once/Overnight Protection in the last/Universal-Exit
set — so the fetched condition count EXCEEDS what was sent (e.g. 13
sent → 15 fetched). These rows are display scaffolds from TT's
read transformer, not persisted DB rows: they carry sort=None and
empty condition_json, and they are APPENDED AFTER the authored
conditions, so authored rows keep their array indices and
contiguous sorts. Consequences: (1) a higher-than-sent count in
content_counts is normal, only a DROP is a defect; (2) author
patch paths against a fresh tt_get_strategy fetch (whose indices
include the scaffolds); (3) match conditions and legs by their row
id or by type+content, never by a remembered ordinal and never by
uuid: Tradetron mints every set, condition and leg uuid fresh on
EACH read (it is not stored), so a uuid from one read appears in no
other. Condition and leg ids are stable across saves; set ids are not
(see above).
Default dry_run=True — returns a structured before/after diff
and a full validation pass WITHOUT touching TT. Set dry_run=False
only after inspecting the dry-run result.
Args: strategy_id: integer ID from a prior create or list call. patch: list of JSON-Patch ops. Each op is a dict: {"op": "add"|"remove"|"replace", "path": "/json/pointer", "value": # add/replace only} Paths are JSON-Pointer (RFC 6901). Trailing "-" on add means append to array: "/sets/-". rewrite: {"dimension": "timeframe", "from": , "to": } — move a value at EVERY site in one call. Compiles server-side into ordinary replace ops (returned in patch_summary) and passes through the same validation, desync and round-trip checks. Optional; omit for a hand-authored patch. dry_run: True (default) returns diff only; False POSTs to TT.
Supported ops in v1: add, remove, replace. (move/copy/test deferred — express move as add+remove, copy as add with value.)
Returns on success: { "ok": True, "data": { "applied": bool, # True only when dry_run=False AND POST succeeded "dry_run": bool, # echo of input "patch_summary": [...], # compact per-op view "before": {...}, # state pre-patch; BOTH are OMITTED on a "after": {...}, # rewrite-only call and whenever the two # bodies exceed the echo budget — then # "bodies_omitted" carries the reason and # patch_summary / condition_changes are the # diff. Re-read with tt_get_strategy(id). "validation": {"ok", "errors": [...]}, "tt_result": {...}, # only when applied=True "request_id": str, # log correlation } }
Error codes worth surfacing: STRATEGY_PATCH_BAD_OP — patch op malformed or path invalid STRATEGY_VALIDATION_FAILED — post-patch state fails SCHEMA_LOCK STRATEGY_TT_API_ERROR — TT rejected the POST (applied=False) STRATEGY_PATCH_CONTENT_DROPPED — TT 200 but a structural patch lost sets/conditions/legs (FAIL LOUD) STRATEGY_PATCH_PARTIAL_PERSIST — TT 200 but some touched scalar keys did not persist (see details.dropped)
Examples: # Rename via patch (equivalent to tt_update_strategy({"name": ...})) [{"op": "replace", "path": "/name", "value": "new name"}]
# Add a new Set at the end
[{"op": "add", "path": "/sets/-",
"value": {"name": "extra", "uuid": "...", "conditions": [], "list": 0}}]
# Remove the second leg from the first condition of the first set
[{"op": "remove", "path": "/sets/0/conditions/0/legs/1"}]
# Change a condition's expression.
# THREE-REPRESENTATION RULE — the single most common reason a patch
# is refused (PATCH_REP_DESYNC). condition_value (engine expr),
# condition_json (builder tree) and condition_display (builder
# string) are parallel forms of ONE field. The engine reads the
# value; the ASB builder renders the json/display. Move only one and
# the user's next save in ASB SILENTLY REVERTS the change. The same
# holds for a leg's strike / strike_json / strike_display, its
# qty / qty_json / qty_display, and a variable row's bare
# value / json / display.
#
# *** A lone condition_value replace is REFUSED. ***
# *** A lone condition_JSON replace is ACCEPTED. ***
#
# The asymmetry is real, not a quirk: the server can derive
# value + display FROM a builder tree (deterministic re-emit), and
# there is no parser the other way. So the cheapest correct edit to
# an AST-backed field is to patch the `*_json` member ALONE —
# condition_json, or a leg's strike_json / expiry_json / qty_json /
# limit_price_json / SL_trigger_json — and let the server fill the
# text members. It reports what it wrote under
# `validation.representation_repairs`.
#
# To obtain a correct json/display pair without hand-writing one,
# call tt_normalize_strategy(strategy) with the edited body, or
# tt_create_strategy(dry_run=True) with markdown for the
# condition you want and lift the generated members out of the
# returned `payload`. Copying the FETCHED json/display verbatim does
# NOT satisfy the guard — byte-identical carry-over beside a changed
# value is exactly the stale-sibling case it catches.
[{"op": "replace",
"path": "/sets/0/conditions/0/condition_value",
"value": "( tt_Time ( 'NSE' ) >= tt_Number ( '1015' ) )"},
{"op": "replace",
"path": "/sets/0/conditions/0/condition_json",
"value": "<builder tree from tt_create_strategy(dry_run=True)>"},
{"op": "replace",
"path": "/sets/0/conditions/0/condition_display",
"value": "<builder string from the same payload>"}]allow_mixed_underlyings: a patch that moves the underlying at SOME of its sites and leaves others on the old symbol is REFUSED (PARTIAL_UNDERLYING_CHANGE in validation.errors): saved, it trades a mix of two instruments. Set true only on a re-send after the USER confirms the mix is intended (a hedge or a signal on another index).
RUNTIME-VARIABLE WRITES (Set Runtime Var) are editable two ways: the
row's value at /sets//conditions//extra/variables//value,
or the stored write itself at
/sets//conditions//condition_action/ (the engine runs
condition_action; the server carries the edit into the row and
Tradetron regenerates condition_action on save). Writes stored ONLY
in condition_action are moved into rows first, with the same text;
validation.runtime_write_rows lists both. They count as underlying
sites, so an underlying move that leaves one behind is refused like
any other partial move.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"strategy_id": "<strategy_id>"
},
"name": "tt_apply_strategy_patch"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| patch | No | ||
| dry_run | No | ||
| rewrite | No | ||
| strategy_id | Yes | ||
| exchange_brokers | No | ||
| live_edit_confirmed | No | ||
| allow_mixed_underlyings | No | ||
| allow_universal_exit_removal | No |