autonomous-trading

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Autonomous Trading v6

自主交易 v6

Give your agent a budget, a target, and a deadline — then let it trade. The agent creates a strategy wallet, scans for opportunities, opens positions, protects profits with DSL, and enforces risk controls.
为你的Agent设定预算、目标和期限,之后就可以让它自动开展交易。该Agent会创建策略钱包、扫描交易机会、开仓、通过DSL保护盈利,同时执行风险管控规则。

Prerequisites

前置要求

Install these companion skills first:
  1. dsl-dynamic-stop-loss — trailing stops, auto-closing, per-tier retrace
  2. opportunity-scanner — market scanning, scoring, hourly trend gate
  3. emerging-movers — SM rotation detection, IMMEDIATE_MOVER signals
Minimum budget: $500 (recommend $1k+)
请先安装以下配套skill:
  1. dsl-dynamic-stop-loss — 移动止损、自动平仓、分层回撤
  2. opportunity-scanner — 市场扫描、评分、小时级趋势关卡
  3. emerging-movers — SM轮动检测、IMMEDIATE_MOVER信号
最低预算: 500美元(推荐1000美元以上)

Known Bugs & Gotchas

已知漏洞与注意事项

See references/bugs-and-gotchas.md — critical issues from live trading including the
dryRun
bug, phantom closes, XYZ DEX margin type, Tier 1 lock misconception, and scanner leverage vs actual max.
请查看 references/bugs-and-gotchas.md — 包含实盘交易中的关键问题,包括
dryRun
漏洞、phantom平仓、XYZ DEX保证金类型、Tier 1锁仓误区,以及扫描器杠杆与实际最大杠杆的差异。

The Flow

运行流程

Step 1: Ask the User

步骤1:询问用户

Collect: budget, target, deadline, risk tolerance (conservative/moderate/aggressive), asset preferences.
收集以下信息:预算、目标、期限、风险承受能力(保守/适中/激进)、资产偏好。

Step 2: Calculate the Playbook

步骤2:计算交易方案

See references/risk-rules.md for complete risk rules by profile.
v6 Core Rules:
The #1 Rule — Hourly Trend Alignment. ALL trades must confirm with hourly candle structure. Counter-trend = hard skip, no exceptions. This single rule prevents the majority of losing trades.
Max Leverage Check. Always check
max-leverage.json
before entering. Scanner leverage is conservative, not actual max.
Concentration Over Diversification. At small account sizes ($500-$10k), 2-4 high-conviction positions beat 6 mediocre ones. Cross-margin math: 4 positions → 80.6% margin buffer, 2 positions → 89.7%.
Every Slot Must Maximize ROI. Empty slot > mediocre position. If a position isn't working, cut it and free the slot.
Speed Filter. Best moves happen FAST (XRP hit Tier 3 in 19 min, XMR Tier 2 in 37 min). Slow movers are suspects.
各风险等级对应的完整风控规则请查看 references/risk-rules.md
v6核心规则:
头号规则 — 小时级趋势对齐。 所有交易必须符合小时K线结构,逆势交易直接跳过,无例外。仅这一条规则就能避免绝大多数亏损交易。
最大杠杆校验。 开仓前必须检查
max-leverage.json
,扫描器给出的杠杆是保守值,并非实际最大可使用杠杆。
集中持仓优于分散持仓。 小资金账户(500-10000美元)下,2-4个高信心持仓优于6个表现平庸的持仓。跨保证金计算:4个持仓→80.6%保证金缓冲,2个持仓→89.7%保证金缓冲。
每个仓位都要实现ROI最大化。 空仓位好于平庸持仓。如果某一持仓表现不及预期,立即平仓释放仓位。
速度筛选。 最好的行情走势速度极快(XRP仅用19分钟就达到Tier 3,XMR37分钟达到Tier 2),走势缓慢的标的通常存在隐患。

Directional Exposure Guard

方向敞口保护

Before opening, check total LONG vs SHORT notional. Cap at 70% in one direction.
开仓前,检查多头与空头的总名义金额,单方向占比最高不能超过70%。

Position Sizing by Score

按评分确定仓位大小

Scanner ScorePosition Size
250+Up to max per-position
200-25075% of max
175-20050% of max
< 175Skip
扫描器评分仓位大小
250+最高可达到单仓位上限
200-250单仓位上限的75%
175-200单仓位上限的50%
< 175跳过

Step 3: Create the Strategy

步骤3:创建策略

strategy_create_strategy(budgetUsd, leverageType, riskLabel)
Returns
strategyId
+
walletAddress
. Fund the wallet.
strategy_create_strategy(budgetUsd, leverageType, riskLabel)
返回
strategyId
+
walletAddress
,向该钱包转入资金即可。

Step 4: Create the Playbook File

步骤4:创建交易方案文件

JSON config tracking: risk profile, position limits, score thresholds, active positions, trade journal. See references/playbook-schema.md.
JSON配置记录内容包括:风险等级、仓位限制、评分阈值、活跃持仓、交易日志。请查看 references/playbook-schema.md

Step 5: Set Up Cron Jobs

步骤5:设置定时任务

Race Condition Prevention (v6 — CRITICAL)
Multiple cron jobs (scanner, SM flip, DSL) can all try to close the same position. When ANY job closes a position:
python
undefined
竞态条件预防(v6版本 — 核心功能)
多个定时任务(扫描器、SM翻转、DSL)可能会同时尝试平仓同一个仓位。当任意任务平仓某一持仓时:
python
undefined

1. Close the position

1. Close the position

result = close_position(wallet, asset)
result = close_position(wallet, asset)

2. Immediately deactivate DSL state file

2. Immediately deactivate DSL state file

state["active"] = False save_state(state)
state["active"] = False save_state(state)

3. Disable DSL cron for this asset

3. Disable DSL cron for this asset

disable_cron(f"dsl-{asset}")

All three steps MUST happen in the same action. This prevents phantom closes.

**Cron Schedule:**

| Job | Interval | Purpose |
|---|---|---|
| Opportunity Scanner | 10-30 min (time-aware) | Find setups |
| DSL Monitor | 2-3 min per position | Trailing stops |
| SM Flip Detector | 5 min | Conviction changes |
| Portfolio Update | 15 min | Reporting |

See [references/cron-setup.md](references/cron-setup.md) for detailed cron configuration, time-aware scheduling, and SM flip detection logic.
disable_cron(f"dsl-{asset}")

以上三个步骤必须在同一个操作中完成,这样可以避免phantom平仓问题。

**定时任务计划:**

| 任务 | 执行间隔 | 用途 |
|---|---|---|
| 机会扫描器 | 10-30分钟(时间感知) | 寻找交易机会 |
| DSL监控 | 每个持仓每2-3分钟执行一次 | 移动止损 |
| SM翻转检测器 | 5分钟 | 监测持仓信心变化 |
| 投资组合更新 | 15分钟 | 数据报告 |

详细的定时任务配置、时间感知调度、SM翻转检测逻辑请查看 [references/cron-setup.md](references/cron-setup.md)。

Step 6: The Trading Loop

步骤6:交易循环

SCAN → EVALUATE → TRADE → PROTECT → REPEAT

For each scan result:
1. Check hourly trend alignment (HARD REQUIREMENT)
2. Check directional exposure guard
3. Check max leverage via max-leverage.json
4. Score ≥ 175? → Size by score tier
5. Open position → Create DSL state → Start DSL cron
6. Journal the trade (scanner snapshot at entry)
SCAN → EVALUATE → TRADE → PROTECT → REPEAT

For each scan result:
1. Check hourly trend alignment (HARD REQUIREMENT)
2. Check directional exposure guard
3. Check max leverage via max-leverage.json
4. Score ≥ 175? → Size by score tier
5. Open position → Create DSL state → Start DSL cron
6. Journal the trade (scanner snapshot at entry)

v6: Dead Weight Cutting

v6版本:无效持仓清理

ConditionAction
SM conviction drops 4→1 (e.g., 220→24 traders in 10 min)Cut immediately
Dead weight at conviction 0Cut immediately — free the slot
Position stagnant, better opportunity availableRotate
触发条件执行操作
SM持仓信心从4跌至1(例如10分钟内评分从220降至24)立即平仓
持仓信心为0的无效持仓立即平仓,释放仓位
持仓停滞,同时出现更好的交易机会调仓换股

Step 7: Safety Rails

步骤7:安全防护

Hard Stops (automatic):
  • Daily loss limit hit → stop trading for the day
  • Total drawdown hard stop → close all positions, alert user
  • DSL breach → auto-close (handled by script)
What the Agent Should NEVER Do:
  • Trade counter-trend on hourly
  • Exceed position size limits
  • Override DSL
  • Average down on a losing position
  • Ignore the directional exposure guard
硬性止损(自动执行):
  • 达到单日亏损上限 → 当日停止交易
  • 达到总回撤硬性止损线 → 平仓所有持仓,向用户发送告警
  • 触发DSL阈值 → 自动平仓(由脚本处理)
Agent绝对禁止的操作:
  • 进行小时级别的逆势交易
  • 超出仓位大小限制
  • 覆盖DSL规则
  • 对亏损持仓加仓摊薄成本
  • 忽略方向敞口保护规则

Step 8: Lessons from the Field

步骤8:实盘经验总结

See references/lessons.md for what works, what doesn't, retrace tuning, and fee awareness from live trading.
关于有效策略、无效策略、回撤参数调整、实盘交易手续费注意事项等内容,请查看 references/lessons.md

API Reference

API参考

See references/api-tools.md for the key Senpi tools used by this recipe.
本方案使用的核心Senpi工具请查看 references/api-tools.md