dsl-dynamic-stop-loss by senpi-ai/senpi-skills
npx skills add https://github.com/senpi-ai/senpi-skills --skill dsl-dynamic-stop-loss适用范围 — 仅 DSL。 此技能仅处理动态/追踪止损 (DSL),而非普通(静态)止损。如果用户只说“止损”而没有明确指 DSL 或静态止损,请询问(例如:“您想要一个随利润上移的追踪止损,还是一个固定价格的止损?”)。
面向用户的表述。 使用通俗的术语(“追踪止损”、“利润保护”)。不要提及状态路径、cron ID、脚本名称或 DSL_* 环境变量,除非用户询问技术细节。
所有新仓位都应使用高水位线模式 (lockMode: "pct_of_high_water")。这是每个 Senpi 技能推荐的默认设置。追踪底线是峰值 ROE 的一个百分比,每次行情更新时重新计算,没有上限。一个 ROE 为 +50% 且锁定比例为 85% 的交易,其底线在 +42.5%。一个 ROE 为 +200% 的交易,其底线在 +170%。几何关系是恒定的——交易始终保留其最佳时刻的 85%。
完整规范请参见 dsl-high-water-spec 1.0.md,各技能层级配置请参见 dsl-high-water-adoption-guide.md。
创建 DSL 状态文件时,必须始终包含:
{
"lockMode": "pct_of_high_water",
"tiers": [
{"triggerPct": 7, "lockHwPct": 40, "consecutiveBreachesRequired": 3},
{"triggerPct": 12, "lockHwPct": 55, "consecutiveBreachesRequired": 2},
{"triggerPct": 15, "lockHwPct": 75, "consecutiveBreachesRequired": 2},
{"triggerPct": 20, "lockHwPct": 85, "consecutiveBreachesRequired": 1}
]
}
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
使用 dsl-high-water-adoption-guide.md 中各技能的层级配置——不同技能有不同的层级宽度。以上是标准动量策略的默认配置(FOX, HAWK, DIRE WOLF)。
旧版模式 (lockMode: "fixed_roe" 或省略) 对现有仓位仍然有效。lockPct 层级锁定的是入场价→高水位线价格范围的一个固定比例。没有每次行情更新的重新计算——底线仅在层级变更时更新。
用于 Hyperliquid 永续合约(主网 + xyz)的追踪止损。默认:高水位线模式——底线作为峰值 ROE 的一个百分比进行追踪,每次行情更新时重新计算,没有上限。Cron 每 3–5 分钟运行一次 dsl-v5.py;该脚本通过 Senpi 的 edit_position 将当前底线同步到 Hyperliquid,这样即使 cron 进程停止,HL 也能执行止损。第一阶段:宽幅回撤,带有绝对底线限制。第二阶段:分层的高水位线锁定,随利润递增且永不回落。参见 references/tier-examples.md 和 references/state-schema.md。
文件: scripts/dsl-v5.py(监控/平仓,ndjson 输出),scripts/dsl-cleanup.py(策略目录清理),scripts/dsl-cli.py(生命周期管理——用于所有设置)。配置:dsl-profile.json(此技能的默认配置)。状态:{DSL_STATE_DIR}/{strategyId}/{asset}.json;策略配置:references/strategy-schema.md。清理:references/cleanup.md。输出模式:references/output-schema.md。
调度器: OpenClaw cron(每个策略一个,每 3–5 分钟)。没有针对每个仓位的 cron——脚本从 MCP 清算所和状态文件发现仓位。
Cron 运行器: dsl-v5.py —— 接受 --strategy-id<uuid> 和 --state-dir<path>(CLI 参数优先;环境变量 DSL_STRATEGY_ID、DSL_STATE_DIR 作为后备)。优先使用 CLI 参数以避免代理在环境中错误输入 UUID。检查策略是否活跃(MCP strategy_get);将状态文件与清算所对账(归档孤儿状态);对于每个活跃仓位:获取价格,更新高水位线和层级,通过 edit_position 将止损同步到 Hyperliquid,检测突破,突破时调用 close_position 并归档状态。每个仓位打印一行 JSON(ndjson)。
生命周期管理: dsl-cli.py 仅创建/更新策略配置和仓位状态文件(它不下达止损单)。Cron 运行器通过 edit_position 将底线同步到 Hyperliquid,并在状态中设置 slOrderId。当为没有 cron 的策略添加 DSL 时,CLI 输出 cron_needed、cron_job_id、cron_env、cron_schedule。代理使用该 ID 创建或移除 OpenClaw cron。
清理: 当策略不活跃或无剩余仓位时,代理运行 dsl-cleanup.py 以移除策略目录。止损同步和平仓使用 Senpi (mcporter);调度仅使用 OpenClaw。
┌─────────────────────────────────────────────────────────────────┐ │ OpenClaw cron (per strategy) → dsl-v5.py │ │ MCP: strategy_get, clearinghouse, prices, edit_position, │ │ close_position, execution_get_order_status │ │ Output: ndjson (one line per position or strategy-level) │ ├─────────────────────────────────────────────────────────────────┤ │ Agent: create/remove cron from CLI output; run dsl-cleanup; │ │ alert on closed / strategy_inactive / pending_close │ └─────────────────────────────────────────────────────────────────┘
所有生命周期操作都使用 scripts/dsl-cli.py。全局选项:--state-dir(默认:$DSL_STATE_DIR 或 /data/workspace/dsl)。配置必须是带有 @ 前缀的文件路径(例如 @dsl-profile.json)或内联 JSON。
| 命令 | 用法 | 备注 |
|---|---|---|
| add-dsl | add-dsl <strategy-id> [asset dex] --skill <skill-name> --configuration @<path> | 创建策略配置和仓位状态文件。省略 asset/dex 则应用于所有仓位。可选 --entry-price。当需要创建 cron 时,输出:cron_needed、cron_job_id、cron_env、cron_schedule。 |
| update-dsl | update-dsl <strategy-id> [asset dex] --configuration <json-or-@path> | 策略范围或单个仓位的配置补丁(例如 '{"phase1":{"retraceThreshold":0.05}}' 或 @override.json)。 |
| pause-dsl | pause-dsl <strategy-id> [asset dex] | 暂停监控;cron 继续运行,状态保留。 |
| resume-dsl | resume-dsl <strategy-id> [asset dex] | 恢复监控。 |
| delete-dsl | delete-dsl <strategy-id> [asset dex] | 归档状态并拆除。当代理必须移除 OpenClaw cron 时,输出:cron_to_remove。 |
| status-dsl | status-dsl <strategy-id> [asset dex] | 报告当前状态。 |
| count-dsl | count-dsl <strategy-id> | 聚合计数。 |
| validate | validate --configuration @<path> | 验证 DSL 配置文件(例如 @dsl-profile.json)。 |
示例(此技能):--skill dsl-dynamic-stop-loss --configuration @<path-to-this-skill>/dsl-profile.json。其他技能:使用相同的 CLI,但 --skill <their-skill> 和 --configuration @<their-dsl-profile.json>。完整详情:references/cli-usage.md。
当用户要求追踪/动态止损时,使用 scripts/dsl-cli.py 进行所有生命周期操作(除非 CLI 不可用,否则不要手动编辑状态文件)。
python3 scripts/dsl-cli.py add-dsl <strategy-id> [asset dex] --skill dsl-dynamic-stop-loss --configuration @<path-to-this-skill>/dsl-profile.jsoncron_needed: true,则使用输出的 cron_job_id、cron_env 和 cron_schedule 创建 OpenClaw cron(计划基于 cronIntervalMinutes 派生,默认为 3;每个策略一个 cron)。--skill 和 --configuration)。代理职责: 当 closed=true 时 → 提醒用户。当 strategy_inactive 时 → 移除 cron,运行 dsl-cleanup.py。当 pending_close=true 时 → 提醒(脚本会重试)。当 delete-dsl 输出 cron_to_remove 时 → 移除该 cron。当 update-dsl 输出 cron_schedule_changed: true 时 → 移除现有的 cron(使用 cron_to_remove.cron_job_id),并使用相同的 cron_job_id 和新的 cron_schedule 创建一个新的 cron(间隔可通过 cronIntervalMinutes 配置;默认为 3 分钟)。
完整集成指南: references/integration-guide.md —— 适用于任何技能的分步指南(路径、add/delete-dsl、cron、清理、检查清单)。
任何技能(例如 wolf-strategy、dsl-tight)都可以通过调用相同的 CLI 并指定其自己的配置文件和技能名称,为其策略添加 DSL。
dsl-cli.py(例如 dsl-dynamic-stop-loss/scripts/dsl-cli.py)和您技能的 dsl-profile.json(在您的技能目录中)。在运行时解析路径。python3 <path>/dsl-cli.py add-dsl <strategy-id> [asset dex] --skill <your-skill-name> --configuration @<path-to-your-dsl-profile.json>@,以便 CLI 读取文件(没有 @ 则将其视为内联 JSON)。cron_needed: true,则同时包含 cron_job_id、cron_env、cron_schedule。使用该 ID 和 env/schedule 创建 OpenClaw cron(每个策略一个 cron)。--skill 和 --configuration)。示例请参见 references/cli-usage.md。closed=true 时提醒用户;当 strategy_inactive 时移除 cron 并运行 dsl-cleanup.py;当 cron_to_remove 时移除该 OpenClaw cron。示例(其他技能,单个仓位):
python3 /path/to/dsl-dynamic-stop-loss/scripts/dsl-cli.py add-dsl <strategy-id> ETH main \
--skill wolf-strategy \
--configuration @/path/to/wolf-strategy/dsl-profile.json
完整命令参考和配置合并规则:references/cli-usage.md。
| 主题 | 参考 |
|---|---|
| 将其他技能与 DSL 集成 | references/integration-guide.md |
| CLI 命令和跨技能使用 | references/cli-usage.md |
| 状态和策略模式 | references/state-schema.md, references/strategy-schema.md |
| 输出 (ndjson) 和代理操作 | references/output-schema.md |
| 清理(策略目录、cron 移除) | references/cleanup.md |
| 层级计算,LONG/SHORT | references/tier-examples.md |
| 配置调优 | references/customization.md |
| 仅 Cron → HL 止损迁移 | references/migration.md |
| 基于 ROE → 高水位线迁移(推荐用于现有状态) | references/migration.md |
API: 策略/仓位/价格/平仓和止损同步通过 Senpi (mcporter)。不要使用 strategy_close_strategy 来平单个仓位——使用 close_position。
| 版本 | 日期 | 变更 |
|---|---|---|
| v5.3.1 | 2026-03-13 | 高水位线:无限追踪,底线移动时同步止损;规范检查清单测试 |
| v5.3 | 2026-03-12 | 高水位线模式:lockMode: "pct_of_high_water",每层级的 lockHwPct |
| v5.2 | 2026-03-01 | CLI 生命周期管理器,多技能集成,止损单验证,对账归档类型,cronIntervalMinutes,配置验证 |
| v5.0 | — | 两阶段追踪止损,交易所止损同步 |
每周安装量
280
代码仓库
GitHub 星标
53
首次出现
2026年2月27日
安全审计
安装于
openclaw276
opencode216
gemini-cli216
github-copilot216
codex216
kimi-cli216
Scope — DSL only. This skill handles only dynamic/trailing stop loss (DSL), not normal (static) stop loss. If the user says "stop loss" without clearly meaning DSL or static, ask (e.g. "Do you want a trailing stop that moves up with profit, or a fixed price stop loss?").
User-facing language. Use plain terms ("trailing stop", "profit protection"). Do not mention state paths, cron IDs, script names, or DSL_* env unless the user asks for technical details.
All new positions should use High Water Mode (lockMode: "pct_of_high_water"). This is the recommended default for every Senpi skill. The trailing floor is a percentage of the peak ROE, recalculated on every tick, with no ceiling. A trade at +50% ROE with 85% lock has its floor at +42.5%. A trade at +200% ROE has its floor at +170%. The geometry is constant — the trade always keeps 85% of its best moment.
See dsl-high-water-spec 1.0.md for the full spec and dsl-high-water-adoption-guide.md for per-skill tier configurations.
When creating DSL state files, ALWAYS include:
{
"lockMode": "pct_of_high_water",
"tiers": [
{"triggerPct": 7, "lockHwPct": 40, "consecutiveBreachesRequired": 3},
{"triggerPct": 12, "lockHwPct": 55, "consecutiveBreachesRequired": 2},
{"triggerPct": 15, "lockHwPct": 75, "consecutiveBreachesRequired": 2},
{"triggerPct": 20, "lockHwPct": 85, "consecutiveBreachesRequired": 1}
]
}
Use the per-skill tiers from dsl-high-water-adoption-guide.md — different skills have different tier widths. The above is the standard momentum default (FOX, HAWK, DIRE WOLF).
Legacy mode (lockMode: "fixed_roe" or omitted) still works for existing positions. lockPct tiers lock a fixed fraction of the entry→HW price range. No per-tick recalculation — floor only updates on tier changes.
Trailing stop for Hyperliquid perps (main + xyz). Default: High Water Mode — floor trails the peak ROE as a percentage, recalculated every tick, no ceiling. Cron runs dsl-v5.py every 3–5 min; the script syncs the current floor to Hyperliquid via Senpi edit_position so HL can execute the SL even if the cron process goes down. Phase 1: wide retrace with absolute floor cap. Phase 2: tiered High Water locks that ratchet up with profit and never come back down. See references/tier-examples.md and references/state-schema.md.
Files: scripts/dsl-v5.py (monitor/close, ndjson output), scripts/dsl-cleanup.py (strategy dir cleanup), scripts/dsl-cli.py (lifecycle — use for all setup). Config: dsl-profile.json (this skill’s default). State: {DSL_STATE_DIR}/{strategyId}/{asset}.json; strategy config: references/strategy-schema.md. Cleanup: references/cleanup.md. Output schema: references/output-schema.md.
Scheduler: OpenClaw cron (one per strategy, every 3–5 min). No per-position cron — the script discovers positions from MCP clearinghouse and state files.
Cron runner: dsl-v5.py — accepts --strategy-id<uuid> and --state-dir<path> (CLI args take precedence; env vars DSL_STRATEGY_ID, DSL_STATE_DIR are fallbacks). Prefer CLI args to avoid agent mistyping UUID in env. Checks strategy active (MCP strategy_get); reconciles state files with clearinghouse (archives orphans); for each active position: fetch price, update high water and tiers, sync SL to Hyperliquid via edit_position, detect breach, on breach call close_position and archive state. Prints one JSON line per position (ndjson).
All lifecycle operations use scripts/dsl-cli.py. Global option: --state-dir (default: $DSL_STATE_DIR or /data/workspace/dsl). Config must be a file path with @ prefix (e.g. @dsl-profile.json) or inline JSON.
| Command | Usage | Notes |
|---|---|---|
| add-dsl | add-dsl <strategy-id> [asset dex] --skill <skill-name> --configuration @<path> | Creates strategy config and position state files. Omit asset/dex for all positions. Optional --entry-price. Output: cron_needed, cron_job_id, cron_env, cron_schedule when cron must be created. |
| update-dsl | update-dsl <strategy-id> [asset dex] --configuration <json-or-@path> |
Examples (this skill): --skill dsl-dynamic-stop-loss --configuration @<path-to-this-skill>/dsl-profile.json. Other skills: same CLI with --skill <their-skill> and --configuration @<their-dsl-profile.json>. Full details: references/cli-usage.md.
When the user asks for trailing/dynamic stop loss, use scripts/dsl-cli.py for all lifecycle operations (do not edit state files by hand unless CLI is unavailable).
python3 scripts/dsl-cli.py add-dsl <strategy-id> [asset dex] --skill dsl-dynamic-stop-loss --configuration @<path-to-this-skill>/dsl-profile.jsoncron_needed: true, create the OpenClaw cron with the output cron_job_id, cron_env, and cron_schedule (schedule is derived from cronIntervalMinutes, default 3; one cron per strategy).--skill and --configuration as for add).Agent: On closed=true → alert user. On strategy_inactive → remove cron, run dsl-cleanup.py. On pending_close=true → alert (script retries). On delete-dsl output cron_to_remove → remove that cron. On update-dsl output cron_schedule_changed: true → remove the existing cron (using cron_to_remove.cron_job_id) and create a new one with the same cron_job_id and the new cron_schedule (interval is configurable via ; default 3 min).
Full integration guide: references/integration-guide.md — step-by-step for any skill (paths, add/delete-dsl, cron, cleanup, checklist).
Any skill (e.g. wolf-strategy, dsl-tight) can add DSL for its strategies by calling the same CLI with its own profile and skill name.
dsl-cli.py (e.g. dsl-dynamic-stop-loss/scripts/dsl-cli.py) and your skill’s dsl-profile.json (in your skill directory). Resolve paths at runtime.python3 <path>/dsl-cli.py add-dsl <strategy-id> [asset dex] --skill <your-skill-name> --configuration @<path-to-your-dsl-profile.json>@ before the config path so the CLI reads the file (without @ it treats the value as inline JSON).cron_needed: true, it also includes cron_job_id, cron_env, cron_schedule. Create the cron with that ID and env/schedule (one cron per strategy).Example (other skill, single position):
python3 /path/to/dsl-dynamic-stop-loss/scripts/dsl-cli.py add-dsl <strategy-id> ETH main \
--skill wolf-strategy \
--configuration @/path/to/wolf-strategy/dsl-profile.json
Full command reference and configuration merge rules: references/cli-usage.md.
| Topic | Reference |
|---|---|
| Integrating another skill with DSL | references/integration-guide.md |
| CLI commands and inter-skill usage | references/cli-usage.md |
| State and strategy schema | references/state-schema.md, references/strategy-schema.md |
| Output (ndjson) and agent actions | references/output-schema.md |
| Cleanup (strategy dir, cron removal) | references/cleanup.md |
| Tier math, LONG/SHORT | references/tier-examples.md |
API: Strategy/positions/price/close and SL sync via Senpi (mcporter). Do not use strategy_close_strategy for a single position — use close_position.
| Version | Date | Changes |
|---|---|---|
| v5.3.1 | 2026-03-13 | High Water: infinite trail, SL sync when floor moves; spec checklist tests |
| v5.3 | 2026-03-12 | High Water Mode: lockMode: "pct_of_high_water", lockHwPct per tier |
| v5.2 | 2026-03-01 | CLI lifecycle manager, multi-skill integration, SL order verification, reconciliation archive types, cronIntervalMinutes, config validation |
| v5.0 | — | Two-phase trailing stop, exchange SL sync |
Weekly Installs
280
Repository
GitHub Stars
53
First Seen
Feb 27, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykWarn
Installed on
openclaw276
opencode216
gemini-cli216
github-copilot216
codex216
kimi-cli216
xdrop 文件传输脚本:Bun 环境下安全上传下载工具,支持加密分享
20,700 周安装
Lifecycle: dsl-cli.py creates/updates strategy config and position state files only (it does not place the SL order). The cron runner syncs the floor to Hyperliquid via edit_position and sets slOrderId in state. When adding DSL for a strategy with no cron, CLI outputs cron_needed, cron_job_id, cron_env, cron_schedule. Agent creates or removes the OpenClaw cron using that ID.
Cleanup: On strategy inactive or no positions left, agent runs dsl-cleanup.py to remove the strategy directory. SL sync and close use Senpi (mcporter); scheduling is OpenClaw only.
┌─────────────────────────────────────────────────────────────────┐ │ OpenClaw cron (per strategy) → dsl-v5.py │ │ MCP: strategy_get, clearinghouse, prices, edit_position, │ │ close_position, execution_get_order_status │ │ Output: ndjson (one line per position or strategy-level) │ ├─────────────────────────────────────────────────────────────────┤ │ Agent: create/remove cron from CLI output; run dsl-cleanup; │ │ alert on closed / strategy_inactive / pending_close │ └─────────────────────────────────────────────────────────────────┘
Strategy-wide or per-position config patch (e.g. '{"phase1":{"retraceThreshold":0.05}}' or @override.json). |
| pause-dsl | pause-dsl <strategy-id> [asset dex] | Pause monitoring; cron keeps running, state preserved. |
| resume-dsl | resume-dsl <strategy-id> [asset dex] | Resume monitoring. |
| delete-dsl | delete-dsl <strategy-id> [asset dex] | Archive state and tear down. Output: cron_to_remove when agent must remove OpenClaw cron. |
| status-dsl | status-dsl <strategy-id> [asset dex] | Report current status. |
| count-dsl | count-dsl <strategy-id> | Aggregate counts. |
| validate | validate --configuration @<path> | Validate a DSL config file (e.g. @dsl-profile.json). |
cronIntervalMinutes--skill and --configuration as for add). See references/cli-usage.md for examples.closed=true alert user; on strategy_inactive remove cron and run dsl-cleanup.py; on cron_to_remove remove that OpenClaw cron.| Config tuning | references/customization.md |
| Cron-only → HL SL migration | references/migration.md |
| ROE-based → High Water migration (recommended for existing state) | references/migration.md |