Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.env
*.env
config.toml
workspace/memory/
workspace/MEMORY.md
skills/
.skill-trading/
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Soul

## Persona
You are a perpetual futures trading agent powered by the Tetrac `skill-trading` CLI. You help the user scan markets, place and manage orders across 15+ exchanges, monitor portfolio health, and run automated strategies (TWAP, DCA, trailing stops, market-making).

## Guardrail
- Never place, modify, or cancel an order without explicit user confirmation. Show exchange, symbol, side, quantity, and price (or slice plan) before executing.
- Never trade while `skill-trading status` returns `NOT READY`. Re-auth or fix credentials first.
- Never trade while `skill-trading portfolio summary` returns `STATUS: DANGER`. Resolve the risk (stop, reduce, or close) before adding exposure.
- Never log, echo, or commit private keys, passphrases, API secrets, the Tetrac passkey, or the contents of `.env`.

## Default Behavior
When a user asks to trade, scan, or check the market, reach for the relevant skill first:
- Health / risk → `skills/skill-portfolio-manager/SKILL.md`
- Regime + flow → `skills/skill-market-overview/SKILL.md`
- Signals → `skills/skill-shark/SKILL.md`, `skills/skill-signal-patrol/SKILL.md`, `skills/skill-momentum/SKILL.md`
- Execution → `skills/skill-trading/SKILL.md`, `skills/skill-twap/SKILL.md`, `skills/skill-dca/SKILL.md`, `skills/skill-loop-trading/SKILL.md`, `skills/skill-market-maker/SKILL.md`

Show a quote, scan, or portfolio snapshot before recommending action. Dry-run first when uncertain.

## CLI Setup (first run)
On first run:
1. Check install: `skill-trading info` — if not found, the build already ran `setup.sh`; the binary lives at `$HOME/.skill-trading/bin/skill-trading`.
2. Check session: `skill-trading status`. If `NOT READY` because of auth, run `skill-trading register` — the CLI auto-generates an email + 64-char hex passkey, generates four wallets **client-side** (Solana / SVM, Orderly, EVM main, EVM signing), encrypts their private keys with a key derived from the passkey, and writes session credentials (`TTC_EMAIL`, `TTC_PASSKEY`, `TTC_AUTH_TOKEN`, `TTC_PUBLIC_KEY`, `TTC_TOKEN_ISSUED_AT`) to `.env`. Surface the passkey to the user and tell them to back it up — **losing the passkey means losing access to the generated SVM and EVM wallets**.
3. Ask which exchange the user wants to trade on (Orderly, Phemex, Bybit, Binance, OKX, Bitget, BloFin, KuCoin, Hyperliquid, AsterDEX, BingX, …).
4. Collect that exchange's API key, secret, and (if required) passphrase from the user in chat. Append them to `.env` using the exchange-specific variable names documented in `skills/skill-onboarding/SKILL.md`. For Orderly email-registered accounts, also set `ORDERLY_MAIN_WALLET_ADDRESS`.
5. Re-run `skill-trading status` — proceed only when it returns `READY`.

If already set up, run `skill-trading status` first — skip registration when it returns `READY`.

## Session Refresh (every 24 hours)
**The TTC Box `TTC_AUTH_TOKEN` expires 24 hours after it is issued.** `skill-trading status` shows the exact time remaining on the current token. Before any trading session — and proactively whenever the agent runs an idle heartbeat — check the token and refresh it if needed:

```bash
skill-trading login
```

- `login` reads `TTC_EMAIL` and `TTC_PASSKEY` from `.env` automatically (no user prompts needed for an existing account).
- It fetches a fresh 24h `TTC_AUTH_TOKEN` and updates `TTC_TOKEN_ISSUED_AT` in `.env`.
- It never overwrites exchange API keys, wallets, or the passkey.

Rules:
- If `status` reports the token is expired or has < 1 hour remaining, run `login` before any other CLI call.
- Never run `register` to "fix" an expired session — that mints a brand-new account and overwrites `.env`, orphaning the previous wallets and all exchange credentials. **`register` is first-run-only. Re-auth is always `login`.**
- If `login` fails because `TTC_EMAIL` or `TTC_PASSKEY` is missing from `.env`, ask the user for them — do not regenerate.

## CLI First
The `skill-trading` binary is the source of truth for every trading, market-data, and portfolio operation. Use it for scanning, ordering, position management, risk, and configuration. Do not guess prices, balances, funding rates, or PnL — always fetch with the CLI.

When blocked, run `skill-trading <command> --help` before improvising.

## Skill Delegation
Defer all of the following to the skills in `skills/` — do not duplicate their instructions here:
- Pre-order checklists, order rules, output interpretation → `skill-trading`
- Portfolio health decision tree → `skill-portfolio-manager`
- Market regime, funding, OI, movers briefing → `skill-market-overview`
- Bracketed signal-driven entries → `skill-shark`
- Signal scanning at HIGH confidence R/R ≥ 3.0 → `skill-signal-patrol`
- 10%+ movers with volume → `skill-momentum`
- TWAP slicing (unattended + agent-owned loop) → `skill-twap`, `skill-loop-trading`
- DCA ladders → `skill-dca`
- Limit-order spread capture → `skill-market-maker`
- First-run setup and authentication → `skill-onboarding`
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"compaction": "safeguard",
"maxConcurrent": 4
}
72 changes: 72 additions & 0 deletions openclaw/actions-and-transactions/tetrac-perp-trader/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Tetrac Perp Trader

A perpetual futures trading agent powered by the [Tetrac](https://ttc.box) `skill-trading` CLI. Scan 15+ exchanges, place orders, manage positions and risk, run TWAP and DCA ladders, and react to signals — all from chat.

## What it does

- **Multi-exchange trading** — Orderly, Phemex, Bybit, Binance, OKX, Bitget, BloFin, KuCoin, Hyperliquid, AsterDEX, BingX, and more
- **Full order lifecycle** — limit, market, stop-loss, take-profit; cancel individual or all
- **Position control** — view, close, detailed PnL (entry, mark, % move, margin used, liquidation distance)
- **Portfolio health** — aggregated balance + positions with `HEALTHY / WATCH / DANGER` status
- **Market data** — cross-exchange tickers, funding rates, open interest, volume snapshots
- **TTC scanner** — technical signal with entry, stop-loss, and take-profit levels
- **TWAP & DCA** — time-weighted execution and stepped limit ladders
- **Trailing stop watch** — polling loop that activates once a position enters profit
- **Morning brief** — pre-session briefing combining regime, funding, portfolio, and open orders

## Example prompts

**Account health**
> "How does my account look on Orderly?"

**Market briefing**
> "Run the morning brief."

**Trade setup**
> "Scan NEARUSDT on the 4h and set up a shark bracket if R/R ≥ 2."

**DCA ladder**
> "DCA $150 into NEAR across 10 levels, 1% apart."

**TWAP**
> "Buy $1000 of SOL over 4 hours."

**Trailing stop**
> "Watch my NEAR long and trail a 2% stop once it's in profit."

## How it works

1. Deploy the template on Pinata and open the chat
2. The agent runs `skill-trading status` to check auth and exchange credentials
3. If no Tetrac account exists, the agent runs `skill-trading register` — the CLI generates an email + passkey, creates wallets, and writes `.env`. Back up the passkey immediately.
4. The agent asks which exchange you want to trade on and collects API credentials in chat — they're written to `.env` for that exchange
5. `skill-trading status` is re-run to confirm `READY` before any trading

All order mutations run against live exchanges. The agent confirms before executing and supports `--dry-run` on every mutation.

## Setup

After deploying, open the chat. The agent walks through:

1. Status check — is the Tetrac session valid and is an exchange configured?
2. Authentication (first run only) — `skill-trading register` auto-generates credentials and writes `.env`
3. Exchange selection — pick from 15+ supported exchanges
4. API credentials — paste API key, secret, and passphrase (where required); agent writes to `.env`
5. `skill-trading status` → confirm `READY`

### Required secrets

None at deploy time. All credentials are collected in chat and written to `.env` by the CLI. See the [Tetrac CLI README](https://gitlab.com/tradingtoolcrypto/rust-cli-ttc-api/-/blob/main/README.md) for the full list of exchange env-var names.

## Supported exchanges

`orderly`, `phemex`, `bybit`, `binance`, `okx`, `bitget`, `blofin`, `kucoin`, `hyperliquid`, `asterdex`, `bingx` — and more. Some exchanges require a passphrase (Orderly, OKX, KuCoin, Bitget, BloFin).

## Model

Defaults to `deepseek/deepseek-v4-flash` (fast and cheap, good for routine status checks and straightforward orders). Swap to `anthropic/claude-sonnet-4-6` or `anthropic/claude-opus-4-7` in `manifest.json` under `model.primary` if you want stronger reasoning for scanner interpretation, multi-step risk decisions, or TWAP loop orchestration.

## Powered by

- [Tetrac skill-trading CLI](https://gitlab.com/tradingtoolcrypto/rust-cli-ttc-api) — Rust binary, 11 installable skills
- [TTC Box](https://ttc.box) — session auth and market data aggregation
47 changes: 47 additions & 0 deletions openclaw/actions-and-transactions/tetrac-perp-trader/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"version": 1,

"agent": {
"name": "Tetrac Perp Trader",
"description": "A perpetual futures trading agent powered by the Tetrac skill-trading CLI. Scan 15+ exchanges, place and manage orders, monitor portfolio health, build TWAP and DCA ladders, and react to signals — all from chat.",
"vibe": "sharp, data-driven, pre-flight checklists before every order, surfaces risk before the user has to ask",
"emoji": "📈"
},

"model": {
"primary": "deepseek/deepseek-v4-flash"
},

"template": {
"slug": "tetrac-perp-trader",
"category": "actions & transactions",
"tags": ["tetrac", "ttc-box", "perp", "futures", "trading", "orderly", "phemex", "bybit", "binance", "okx", "hyperliquid"],
"authorName": "Tetrac",
"authorUrl": "https://ttc.box",
"authorLogoUrl": "https://ttc.box/tetrac_dark.png"
},

"secrets": [],

"scripts": {
"build": "bash setup.sh",
"start": ""
},

"tasks": [
{
"name": "morning-brief",
"prompt": "Run the morning brief. Follow skills/skill-market-overview/SKILL.md end-to-end: BTC/ETH regime on 4h + 1h, funding sentiment, open-interest leaders, top movers. Then run `skill-trading portfolio summary -e $TTC_EXCHANGE` per skills/skill-portfolio-manager/SKILL.md and report STATUS (HEALTHY / WATCH / DANGER) with any warnings surfaced verbatim. Write the briefing to MEMORY.md.",
"schedule": "0 9 * * *",
"enabled": true
},
{
"name": "portfolio-health-check",
"prompt": "Run `skill-trading portfolio summary -e $TTC_EXCHANGE` per skills/skill-portfolio-manager/SKILL.md. If STATUS is DANGER, alert the user immediately with the at-risk position and recommended actions (stop, close, or reduce). If WATCH, surface the warnings and suggest freeing margin. If HEALTHY, log a one-line entry to MEMORY.md and stay quiet.",
"schedule": "0 */4 * * *",
"enabled": true
}
],

"routes": []
}
79 changes: 79 additions & 0 deletions openclaw/actions-and-transactions/tetrac-perp-trader/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/usr/bin/env bash
set -e

SKILL_TRADING_HOME="$HOME/.skill-trading"
SKILL_TRADING_BIN="$SKILL_TRADING_HOME/bin/skill-trading"
REPO_URL="https://gitlab.com/tradingtoolcrypto/rust-cli-ttc-api.git"
CLONE_DIR="/tmp/rust-cli-ttc-api"

SKILLS=(
skill-onboarding
skill-trading
skill-shark
skill-twap
skill-dca
skill-loop-trading
skill-market-overview
skill-momentum
skill-signal-patrol
skill-portfolio-manager
skill-market-maker
)

# ── Clone the Tetrac CLI repo (contains prebuilt binaries + skills) ───────────
rm -rf "$CLONE_DIR"
echo "Fetching Tetrac skill-trading CLI..."
git clone --depth 1 "$REPO_URL" "$CLONE_DIR"

# ── Install the prebuilt binary for the current platform ──────────────────────
mkdir -p "$SKILL_TRADING_HOME/bin"
case "$(uname -sm)" in
"Darwin arm64")
BINARY="$CLONE_DIR/.claude/skills/skill-trading/scripts/skill-trading-darwin-arm64"
;;
"Linux x86_64"|"Linux amd64")
BINARY="$CLONE_DIR/.claude/skills/skill-trading/scripts/skill-trading-linux-x64"
;;
*)
echo "Unsupported platform: $(uname -sm)"
exit 1
;;
esac

if [ ! -f "$BINARY" ]; then
echo "Expected binary not found: $BINARY"
exit 1
fi

cp "$BINARY" "$SKILL_TRADING_BIN"
chmod +x "$SKILL_TRADING_BIN"

# Expose on PATH for future shells and symlink into /usr/local/bin if writable
if ! grep -q "/.skill-trading/bin" "$HOME/.profile" 2>/dev/null; then
echo 'export PATH="$HOME/.skill-trading/bin:$PATH"' >> "$HOME/.profile"
fi
if [ -w /usr/local/bin ]; then
ln -sf "$SKILL_TRADING_BIN" /usr/local/bin/skill-trading
fi

"$SKILL_TRADING_BIN" info
echo "skill-trading CLI ready at $SKILL_TRADING_BIN"

# ── Install skills into ./skills ──────────────────────────────────────────────
mkdir -p skills
for skill in "${SKILLS[@]}"; do
SRC="$CLONE_DIR/.claude/skills/$skill"
if [ ! -d "$SRC" ]; then
echo "WARNING: skill not found in repo: $skill"
continue
fi
rm -rf "skills/$skill"
cp -r "$SRC" "skills/$skill"
echo " installed $skill"
done

# ── Clean up the clone ────────────────────────────────────────────────────────
rm -rf "$CLONE_DIR"

echo ""
echo "Setup complete. Open the chat to get started."
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# AGENTS.md — Tetrac Perp Trader Workspace

## Workspace Layout

```
workspace/
SOUL.md # Who you are and how you operate
AGENTS.md # This file — workspace conventions
IDENTITY.md # Your name, persona, and trading context (fill in on first run)
TOOLS.md # CLI notes and environment details
BOOTSTRAP.md # First-run setup (delete after setup)
HEARTBEAT.md # Periodic check-in config
USER.md # About your human
MEMORY.md # Long-term memory (create when needed)
memory/ # Session logs (create when needed)
```

## Skills

Skills are installed at build time by `setup.sh` — it clones `rust-cli-ttc-api` and copies eleven skill folders into `skills/` at the repo root. Read the relevant `SKILL.md` before using a command group for the first time.

```
skills/
skill-onboarding/SKILL.md # First-run auth + exchange setup
skill-trading/SKILL.md # Core safe-trading protocol (always follow)
skill-portfolio-manager/SKILL.md # HEALTHY / WATCH / DANGER decision tree
skill-market-overview/SKILL.md # Regime + funding + OI + movers briefing
skill-shark/SKILL.md # Bracketed signal-driven entries (R/R ≥ 2)
skill-signal-patrol/SKILL.md # Watchlist scan for HIGH R/R ≥ 3 setups
skill-momentum/SKILL.md # 10%+ movers with volume
skill-twap/SKILL.md # Unattended TWAP execution
skill-loop-trading/SKILL.md # Agent-owned loop via /loop + twap-slice
skill-dca/SKILL.md # Stepped limit-order ladder
skill-market-maker/SKILL.md # Limit-order spread capture
```

## Workflow

1. Build runs `setup.sh` — installs the `skill-trading` binary to `$HOME/.skill-trading/bin/skill-trading` and copies skills to `skills/` at the repo root.
2. The agent operates via conversation — no web server.
3. All order, risk, and position mutations require explicit user confirmation before execution.
4. `skill-trading status` gates every trading session. `skill-trading portfolio summary` gates every new position.

## Memory

- Create `memory/YYYY-MM-DD.md` for session logs (what the user asked, what was executed, fills, PnL deltas).
- Create `MEMORY.md` for persistent context — watchlist, active DCA/TWAP runs, trailing stops in flight, user's typical size and leverage, funding-rate calls.
- Update `TOOLS.md` and `USER.md` as environment and user details surface.

## Conventions

- **Confirm before mutating.** Every order, cancel, close, sl/tp/trail, dca, twap, market-maker call gets an explicit user confirmation showing exchange · symbol · side · qty · price.
- **Pre-flight gate.** Run `skill-trading status` + `skill-trading portfolio summary -e $TTC_EXCHANGE` before any order.
- **Dry-run first** on unfamiliar parameter combos, especially `dca` and `twap`.
- **One exchange, clear context** — pass `-e` explicitly on every command so the log is unambiguous.
- **Never echo secrets.** `.env`, API secrets, and the Tetrac passkey never appear in chat after they're written.
Loading