Skip to content
Finance
Skill

/recipe-playground-rebalance

Example driver: drive a portfolio-rebalance hypothesis into a recorded session.

From plugin
kraken-cli
81459 skills1 MCP

Claude Code

$ npx -y skills add krakenfx/kraken-cli --skill recipe-playground-rebalance --agent claude-code

SKILL.md

recipe-playground-rebalance.SKILL.md
name: recipe-playground-rebalance
version: 1.1.0
description: "Example driver: drive a portfolio-rebalance hypothesis into a recorded session."
metadata:
  openclaw:
    category: "recipe"
    domain: "sessions"
  requires:
    bins: ["kraken"]
    skills: ["kraken-playground", "kraken-rebalancing"]

Playground: Rebalance

> **PREREQUISITE:** Load the following skills to execute this recipe: `kraken-playground`, `kraken-rebalancing`

> **This recipe is an example, not a boundary.** Adapt its steps to your hypothesis, or write your own driver — see `kraken-playground` → Driving Your Own Hypothesis.

Test a target-allocation rebalancing hypothesis on live prices with no real money, recording the market data, paper trades, and the "why" behind each adjustment into one session for later replay and P&L analysis.

Important

Paper results may overstate live performance: fees and slippage are simulated and there are no partial fills (see `kraken-paper-strategy`). This recipe records a session inside a paper workspace. With that workspace named on every session, balance and order call and checked each round (see Hard Rules), it never places a live order.

Every number that gates a trade or a skip (`targets`, `threshold_usd`, `drift_pct`) belongs in `--strategy-params` — it's what makes two sessions comparable knob-for-knob. A recurring run adds `rounds` and `interval_s` (see Schedule the Rounds). The values in the Start the Session example are placeholders: a number the operator names (band, threshold, cadence) replaces the example verbatim — params that don't match the mandate record a hypothesis nobody asked to test. Over a long window this recipe is **interventional** — one visit per `interval_s`, paced by the harness (see `kraken-playground` → Running over a Window).

Quick Start

Rebalance a portfolio toward target allocations:

Hold a portfolio 50% BTC, 35% ETH, 15% SOL over 24 hours. 
Rebalance when any asset drifts more than 5% from target AND the delta exceeds $50. 
Check every 2 hours. Report final weights and P&L.

Start the Session

Work inside a paper workspace (create one once: `kraken workspace create rebalance --capital 10000 --mode paper`). Every session, balance and order command below names it with `--workspace rebalance`. An exported `KRAKEN_WORKSPACE` does not reach a later shell, such as a `/loop` fire, and without a workspace `kraken order buy` and `kraken order sell` trade the real account.

kraken --workspace rebalance session start \
  --symbols BTC/USD,ETH/USD,SOL/USD --channels ticker --to duckdb,jsonl \
  --label rebalance-$(date +%Y%m%d-%H%M%S) \
  --strategy recipe-playground-rebalance \
  --strategy-params '{"targets":{"BTCUSD":0.50,"ETHUSD":0.35,"SOLUSD":0.15},"rounds":12,"interval_s":7200,"drift_pct":5,"threshold_usd":50}' \
  -o json 2>/dev/null &

# The session_started stdout line carries the id: {"type":"session_started","session":"s<n>",...}

Print the session id to the user right after starting, and again in the final report — it is the handle for resuming the `/loop`, checking `kraken session show`, and locating the artifacts.

Schedule the Rounds

`/loop` owns the pacing. Set its interval to `interval_s` and it fires each round on cadence (late under jitter, never early). Parse the interval from the user's request: "every 2 hours" to `2h`, "every 4 hours" to `4h`, "every day" to `24h`.

**The scheduler floor is 60 seconds** (`/loop`, cron, and `ScheduleWakeup` all clamp to a one-minute minimum). `interval_s` must be `>= 60`. If the user asks for a sub-minute cadence, clamp to `60` and tell them — never set a sub-minute `interval_s` and never let the report claim a cadence the harness cannot run.

/loop 2h "Run one rebalance round for session s<n> in workspace rebalance per recipe-playground-rebalance"

Do not re-add an elapsed-time gate inside the round. `/loop` already enforces the spacing. The round cursor lives in the session's typed state cell — a rebalance round writes one decision **per leg**, so the decision log cannot count rounds; the cursor can. Reasons stay narrative (keep "round N" in them for the story; nothing parses it). Stop once the cursor reaches `rounds`:

ROUNDS=12   # the `rounds` you set in --strategy-params

# The trades below are simulated only while rebalance is a paper workspace.
[ "$(kraken workspace show rebalance -o json 2>/dev/null | jq -r '.mode')" = paper ] \
  || { echo "workspace rebalance is missing or not paper; no round runs" >&2; exit 1; }

# A failed read must end the firing rather than restart at round 1.
STATE=$(kraken --workspace rebalance session state get --session s<n> -o json 2>/dev/null) || exit 1
LAST_ROUND=$(echo "$STATE" | jq '.cursor.round // 0')
if [ "${LAST_ROUND:-0}" -ge "$ROUNDS" ]; then
  kraken --workspace rebalance session stop -o json 2>/dev/null
  exit 0
fi
# A stopped session refuses the cursor writes below, so trading on would repeat legs.
[ "$(kraken --workspace rebalance session show --session s<n> -o json 2>/dev/null | jq -r '.status')" = recording ] \
  || { echo "session s<n> is not recording; no round runs" >&2; exit 1; }
ROUND=$((LAST_ROUND + 1))

Between legs, record progress so a crashed firing resumes at the first missing leg instead of re-trading executed ones; completing the round writes only the round (the replace drops `legs_done` automatically):

kraken --workspace rebalance session state set --round "$LAST_ROUND" --legs-done "BTC/USD" \
  --note "round $ROUND: leg 1 of 3 done" -o json 2>/dev/null || exit 1   # after each leg
kraken --workspace rebalance session state set --round "$ROUND" -o json 2>/dev/null || exit 1   # round complete

On a fresh firing, `state get`'s `legs_done` names any half-done round — but a crash can land between a leg executing and its `legs_done` write, so never trust the cursor alone before re-trading: cross-check the evidence (`kraken session decisions`, reasons mentioning the i

Read more
@krakenfx
Ships withkraken-cli

Trade on Kraken from your terminal, or let your AI agent trade for you. One install covers crypto, tokenized U.S. stocks and ETFs (for non-U.S. customers), forex, and futures. Every command can answer in JSON.

81459 skills1 MCP
Get the whole plugin

Stars on GitHub

Momentum

stars in total
814
Star history of krakenfx/kraken-cli on GitHub, a chart by star-history.com

Other skills on kraken-cli.

More skills from other plugins.

ccxt-cli

ccxt-cli

CCXT command-line interface (ccxt-cli) for interacting with 100+ cryptocurrency exchanges directly from the terminal — no code…

ccxt10d45k
@ccxt@ccxtInstall Skill

Questions about recipe-playground-rebalance.

Which coding agents can use recipe-playground-rebalance?
recipe-playground-rebalance installs in Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, OpenCode and Windsurf with the skills CLI, using each agent's flag shown on this page. Flowy's auto-invocation, which fires a skill when your prompt matches, runs in Claude Code only.