set_allocations
Set a strategy's target stock/cash ratio and per-asset weights, plus price alerts, with atomic validation to keep allocations accurate and prevent corrupt files.
Instructions
Update the strategy's target allocation: the stock/cash ratio and/or
the per-asset target weights that rebalance_plan reads, and/or the
per-asset alert lines the price sentinel watches. The stock and
cash values must sum to ≈1.0, and the per-asset weights must sum to at
most the stock target; schema validation rejects and rolls back any write
that would corrupt the strategy file. Everything in one call is validated
and written atomically — to lower the stock target below the current sum
of per-asset weights, pass the new weights in the same call.
Use when the user says e.g. "set my target to 70% stock / 30% cash" or "put 30% in 510300.SS and 20% in gold".
Args: target_allocation_stock: Stock weight in [0, 1], e.g. 0.7 (with cash). target_allocation_cash: Cash weight in [0, 1], e.g. 0.3 (with stock). target_pcts: {symbol: weight in [0, 1]} per tracked asset; null clears. alerts: {symbol: {rule: value}} alert lines per tracked asset; null clears a rule (or, for a whole symbol, all its rules).
Returns: The updated allocation and target assets, or {"status": "error", "error": ...}.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| alerts | No | Per-asset alert lines as {symbol: {rule: value}}, rule in price_above / price_below / day_drop_pct / day_rise_pct / drawdown_from_cost_pct, e.g. {'GC=F': {'price_below': 900, 'day_drop_pct': 2}}. Rules you name overwrite, a null rule value clears just that rule, rules you don't mention stay; a null for the whole symbol clears all its alerts. Symbols must already be tracked. *_pct values are percentage points (3 = 3%), unlike target_pct. Alerts are only delivered when INVEST_EVENT_ALERT=1 is set on the server. | |
| target_pcts | No | Per-asset target weights as {symbol: fraction of total assets in [0, 1]}, e.g. {'510300.SS': 0.3, 'GC=F': 0.2}. Symbols must already be tracked (see track_asset). A null value clears that asset's target (back to an equal split). The weights must sum to <= target_allocation_stock (the new one if you pass it in the same call). | |
| target_allocation_cash | No | Cash weight in [0, 1], e.g. 0.3. Pass together with target_allocation_stock; omit both to leave the split unchanged. | |
| target_allocation_stock | No | Stock weight in [0, 1], e.g. 0.7. Pass together with target_allocation_cash (they must sum to ~1.0); omit both to leave the stock/cash split unchanged. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |