kraken-alert-patterns
Price alerts, threshold monitoring, and notification triggers for agents.
Example driver: dip-triggered dollar-cost-averaging on a live WebSocket stream, recorded to a session.
Claude Code
$ npx -y skills add krakenfx/kraken-cli --skill recipe-playground-dca-triggered --agent claude-code
Codex
$ npx skills add krakenfx/kraken-cli --skill recipe-playground-dca-triggered -a codex -y
Cursor
$ npx skills add krakenfx/kraken-cli --skill recipe-playground-dca-triggered -a cursor -y
Gemini CLI
$ npx skills add krakenfx/kraken-cli --skill recipe-playground-dca-triggered -a gemini-cli -y
GitHub Copilot
$ npx skills add krakenfx/kraken-cli --skill recipe-playground-dca-triggered -a github-copilot -y
OpenCode
$ npx skills add krakenfx/kraken-cli --skill recipe-playground-dca-triggered -a opencode -y
Windsurf
$ npx skills add krakenfx/kraken-cli --skill recipe-playground-dca-triggered -a windsurf -y
name: recipe-playground-dca-triggered
version: 1.0.0
description: "Example driver: dip-triggered dollar-cost-averaging on a live WebSocket stream, recorded to a session."
metadata:
openclaw:
category: "recipe"
domain: "sessions"
requires:
bins: ["kraken"]
skills: ["kraken-playground", "kraken-dca-strategy", "kraken-ws-streaming"]> **PREREQUISITE:** Load `kraken-playground`, `kraken-dca-strategy`, and `kraken-ws-streaming` to run this recipe. > **This recipe is an example, not a boundary.** Adapt the steps to your hypothesis, or write your own driver (see `kraken-playground` → Driving Your Own Hypothesis).
Buy the instant price dips below a short-term average, not on a fixed clock. A WebSocket ticker stream drives the loop and every qualifying tick is a candidate buy, rate-limited so buys stay spaced. Record every buy and skip into one session for later replay and P&L.
Use this skill for:
This recipe records a session inside a paper workspace. With that workspace named on every session and order call and checked before the stream starts (see Hard Rules), it never places a live order. Paper results may overstate live performance: fees and slippage are simulated and there are no partial fills (see `kraken-paper-strategy`).
The stream is the loop, not `/loop`. A `while read` over a stream is a long-lived process that holds state (the reference average, the last-buy time) in memory across events. This is a deliberate exception to the stateless-round model (see `kraken-playground` → Running over a Window); keep the session short and the state minimal.
The stream is blind during reconnect gaps. The CLI reconnects a spot stream with exponential backoff (each delay capped at 30 seconds, plus jitter) until you stop it, and any dip inside a gap is missed. The recorder tolerates gaps; a decision loop does not.
Every number that gates a buy goes in `--strategy-params`:
Natural language:
Dollar-cost-average into Bitcoin. Watch the live price and buy $100 whenever it dips more than 0.10% below the 1-hour SMA, but no more than once every 20 minutes, up to 10 buys. Record all buys and skips. At the end, show P&L.
Work inside a paper workspace (create one once: `kraken workspace create dcatrig --capital 10000 --mode paper`). Every session and order command below names it with `--workspace dcatrig`. An exported `KRAKEN_WORKSPACE` does not reach a stream started from another shell, and without a workspace `kraken order buy` trades the real account.
kraken --workspace dcatrig session start \
--symbols BTC/USD --channels ticker,trade --to duckdb,jsonl \
--label dcatrig-btc-$(date +%Y%m%d-%H%M%S) \
--strategy recipe-playground-dca-triggered \
--strategy-params '{"dollars_per_buy":100,"dip_threshold_pct":-0.10,"min_spacing_s":1200,"max_buys":10,"sma_refresh_s":300}' \
-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 checking `kraken session show` and locating the artifacts.
Subscribe to the ticker with the BBO trigger to cut noise, and act on each tick. Hold the reference average and the last-buy time in the loop; refresh the average from REST every `sma_refresh_s`, not on the tick rate.
Bind the gating numbers to the same `--strategy-params` you recorded, so the loop runs the hypothesis you started — never hardcode them into the arithmetic:
DOLLARS_PER_BUY=100
DIP_THRESHOLD_PCT=-0.10
MIN_SPACING_S=1200
MAX_BUYS=10
SMA_REFRESH_S=300
# The buys below are simulated only while dcatrig is a paper workspace.
[ "$(kraken workspace show dcatrig -o json 2>/dev/null | jq -r '.mode')" = paper ] \
|| { echo "workspace dcatrig is missing or not paper; not streaming" >&2; exit 1; }
# True 1h SMA: last twelve 5-minute closes. (--interval 60 would average the
# whole returned window — a multi-day mean, not 1h.)
SMA=$(kraken ohlc BTCUSD --interval 5 -o json 2>/dev/null | jq '[.candles[-12:][].close] | add/length')
SMA_TS=$(date +%s)
LAST_BUY=0
BUYS=0
kraken ws ticker BTC/USD --event-trigger bbo -o json 2>/dev/null | while read -r line; do
PRICE=$(echo "$line" | jq -r '.data[0].last // empty'); [ -z "$PRICE" ] && continue
NOW=$(date +%s)
# Refresh SMA on its own cadence, not per tick
if [ $((NOW - SMA_TS)) -ge $SMA_REFRESH_S ]; then
SMA=$(kraken ohlc BTCUSD --interval 5 -o json 2>/dev/null | jq '[.candles[-12:][].close] | add/length')
SMA_TS=$NOW
fi
# Fail loud, never fabricate: a broken READ must not gate a buy or write a reason.
if [ -z "$PRICE" ] || [ -z "$SMA" ]; then
kraken --workspace dcatrig session note --kind alert --symbol BTC/USD \
--reason "tick skipped: READ failed (price='$PRICE' sma='$SMA')" -o json 2>/dev/null
continue
fi
VS_SMA=$(echo "scale=6; (($PRICE - $SMA) / $SMA) * 100" | bc -l)
# THINK: dip tripped AND rate limit satisfied?
if (( $(echo "$VS_SMA <= $DIP_THRESHOLD_PCT" | bc -l) )) && [ $((NOW - LAST_BUY)) -ge $MIN_SPACING_S ]; then
VOL=$(echo "scale=8; $DOLLARS_PER_BUY / $PRICE" | bc -l)
kraken --workspace dcatrig order buy BTC/USD "$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.
Price alerts, threshold monitoring, and notification triggers for agents.
Progress from manual trading to full agent autonomy with controlled risk at each level.
Capture the spot-futures price spread with delta-neutral basis trades.
Dollar cost averaging with scheduled buys and performance tracking.
Discover staking strategies, allocate funds, and track earn positions.
Handle order failures, network errors, and duplicate submissions safely.
Complete, populate and fill out 3-statement financial model templates (Income Statement, Balance Sheet, Cash Flow Statement) .…
Complete, populate and fill out 3-statement financial model templates (Income Statement, Balance Sheet, Cash Flow Statement) .…