Rebalance from drift
Goal: each morning, find portfolios past their bands and bring them back to target. Scopes: read, plus
advise (advisory mandates: a proposal) or trade (discretionary mandates: orders).
- Your job to IDEALX API: GET /v1/firms/{firmId}/strategies/{strategyId}
- IDEALX API to Your job: followers with driftBp, outside
- Your job to IDEALX API: GET /v1/accounts/{id}/strategies
- IDEALX API to Your job: lines and rebalancing trades
- Your job to IDEALX API: POST /v1/firms/{firmId}/proposals/check
- Your job to IDEALX API: Advisory: POST …/proposals (send)
- Client (app) to IDEALX API: Accepts the proposal
- Your job to IDEALX API: Discretionary: POST /v1/accounts/{id}/orders
- IDEALX API to Your job: Webhook order.updated
1. Find drifted portfolios
Section titled “1. Find drifted portfolios”For each strategy, GET /v1/firms/{firmId}/strategies/{strategyId} lists its
followers with driftBp (how much of the portfolio is away from target, in basis points) and outside (some line
is past its band). Pick the followers with outside: true.
"followers": [ { "assignmentId": "sta_01937f11b2c3d4e5f6a7b8c9d0e1f2a3", "accountId": "acc_01937f00f1e2d3c4b5a6978877665544", "portfolioId": "ptf_01937f00f1e2d3c4b5a69788776655a2", "account": "Morgan Family Trust", "version": 2, "total": { "amount": "184220.15", "currency": "AUD" }, "driftBp": 420, "outside": true }]2. Read the trades
Section titled “2. Read the trades”/v1/accounts/{id}/strategiesThe strategies this account's portfolios follow, and how close they are
curl "$IDEALX_API/v1/accounts/acc_01937f00f1e2d3c4b5a6978877665544/strategies" -H "Authorization: Bearer $IDEALX_API_KEY"{ "strategies": [ { "assignmentId": "sta_01937f11b2c3d4e5f6a7b8c9d0e1f2a3", "accountId": "acc_01937f00f1e2d3c4b5a6978877665544", "portfolioId": "ptf_01937f00f1e2d3c4b5a69788776655a2", "strategy": { "id": "stg_01937f10a1b2c3d4e5f6a7b8c9d0e1f2", "name": "Balanced 60/40", "version": 2, "currentVersion": 2, "riskLevel": 4 }, "currency": "AUD", "approximate": true, "total": { "amount": "184220.15", "currency": "AUD" }, "driftBp": 420, "outside": true, "lines": [ { "kind": "instrument", "refId": "XASX:EXW", "name": "EXW · Example World Shares ETF", "detail": "etf", "targetBp": 2500, "currentBp": 2920, "driftBp": 420, "bandBp": 300, "outside": true, "extra": false, "value": { "amount": "53792.28", "currency": "AUD" }, "change": { "amount": "7737.24", "currency": "AUD" }, "direction": "sell" }, { "kind": "instrument", "refId": "XASX:EXB", "name": "EXB · Example Bond Fund", "detail": "etf", "targetBp": 3500, "currentBp": 3080, "driftBp": -420, "bandBp": 300, "outside": true, "extra": false, "value": { "amount": "56739.81", "currency": "AUD" }, "change": { "amount": "7737.24", "currency": "AUD" }, "direction": "buy" } ], "trades": [ { "instrumentId": "XASX:EXW", "name": "EXW · Example World Shares ETF", "side": "sell", "quantity": "55", "approxValue": { "amount": "7653.25", "currency": "AUD" } }, { "instrumentId": "XASX:EXB", "name": "EXB · Example Bond Fund", "side": "buy", "quantity": "155", "approxValue": { "amount": "7725.20", "currency": "AUD" } } ], "checks": [], "capped": [], "objective": "Long-term growth with moderate swings, for clients with a five-year horizon.", "notes": null, "benchmark": "XASX:EXS", "rebalance": { "kind": "drift" }, "firmId": "frm_01937a1b2c3d4e5f6a7b8c9d0e1f2a3b", "lastRebalancedAt": "2026-08-14T01:00:00.000Z" } ]}trades are worked out at today’s prices, whole units where the listing needs them, and trimmed so no saved check
of the strategy is pushed past (capped names the line and the check that held a buy back). Sells never exceed
what is held.
3. Check them
Section titled “3. Check them”/v1/firms/{firmId}/proposals/checkDry run: costs, tax estimate and checks for trades, and whether a second approval applies
Send the trades as items, sells first (their proceeds pay for the buys). Use purpose: "trade" for a
discretionary trade, "proposal" (the default) for a proposal.
{ "accountId": "acc_01937f00f1e2d3c4b5a6978877665544", "portfolioId": "ptf_01937f00f1e2d3c4b5a69788776655a2", "purpose": "trade", "items": [ { "kind": "order", "instrumentId": "XASX:EXW", "side": "sell", "type": "market", "quantity": "55" }, { "kind": "order", "instrumentId": "XASX:EXB", "side": "buy", "type": "market", "quantity": "155" } ]}4a. Advisory mandate: propose
Section titled “4a. Advisory mandate: propose”Create the proposal with send: true (or draft and submit), with a title such as Rebalance to Balanced 60/40
(version 2) and the rationale. Second approval applies as for any proposal. Full walkthrough:
Draft, check, send and track a proposal.
4b. Discretionary mandate: trade
Section titled “4b. Discretionary mandate: trade”Place each order with a reason (required for a firm’s own trade, at most 200 characters) and its own
Idempotency-Key, sells first:
curl -X POST "$IDEALX_API/v1/accounts/acc_01937f00f1e2d3c4b5a6978877665544/orders" \ -H "Authorization: Bearer $IDEALX_API_KEY" -H "Content-Type: application/json" \ -H "Idempotency-Key: rebal-sta_01937f11-2026-11-25-sell-EXW" \ -d '{ "portfolioId": "ptf_01937f00f1e2d3c4b5a69788776655a2", "instrumentId": "XASX:EXW", "side": "sell", "type": "market", "quantity": "55", "reason": "Rebalance to Balanced 60/40 v2: world shares 4.2 points above target" }'for (const t of [...trades.filter((t) => t.side === "sell"), ...trades.filter((t) => t.side === "buy")]) { await fetch(`${process.env.IDEALX_API}/v1/accounts/${accountId}/orders`, { method: "POST", headers: { ...headers, "Content-Type": "application/json", // Stable per assignment, day and line: a rerun of the job never trades twice. "Idempotency-Key": `rebal-${assignmentId}-${today}-${t.side}-${t.instrumentId.replace(":", "_")}`, }, body: JSON.stringify({ portfolioId, instrumentId: t.instrumentId, side: t.side, type: "market", quantity: t.quantity, reason: `Rebalance to ${strategy.name} v${strategy.version}`, }), });}Orders outside the mandate’s limits (asset classes, amount per instruction or per day) are refused with 403; the
check in step 3 shows them first as a mandate block.
Checklist
Section titled “Checklist”- Only act on
outside: true; inside the bands, leave the portfolio alone. - Re-read
GET /v1/accounts/{id}/strategiesjust before acting: prices move. - Check first, sells before buys, one idempotency key per line per day.
- Advisory: propose and track. Discretionary: trade with a
reasonand followorder.updated.