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
8 changes: 8 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ TUSHARE_TOKEN=your_token_here
# FINNHUB_API_KEY=your_key_here
# TAVILY_API_KEY=your_key_here

# ── 交易(可选,Futu)──
# 自主交易操作员:trade_execute 一步下单/撤单,不经过人工确认。
# real 账户解锁只能在 Futu OpenD 客户端手工完成,代码侧零密码,不在此处配置交易密码。
# ATHENACLAW_TRADE_BROKER=futu
# ATHENACLAW_FUTU_HOST=127.0.0.1
# ATHENACLAW_FUTU_PORT=11111
# ATHENACLAW_FUTU_SECURITY_FIRM=

# ── Telegram(可选)──
# TELEGRAM_BOT_TOKEN=123456:abcdef
# TELEGRAM_ALLOWED_USER_IDS=123456789
Expand Down
9 changes: 4 additions & 5 deletions docs/agent-design.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ Pi/bub/ampcode 的核心洞见:**read/write/edit/bash 是最小完备工具集
| `portfolio(action, ...)` | 领域增强 | 持仓快照 | 维护结构化当前持仓,不记录交易历史 |
| `watchlist(action, ...)` | 领域增强 | 自选快照 | 维护结构化当前自选列表,不记录历史观察日志 |
| `trade_account(action, ...)` | 交易域 | 远端账户快照 | 读取远端 broker 账户、持仓、未完成订单、订单状态 |
| `trade_plan(operation, ...)` | 交易域 | 执行计划 | 生成交易计划,不直接产生外部副作用 |
| `trade_apply(plan_id)` | 交易域 | 动作执行 | 执行交易计划,执行前必须确认 |
| `trade_execute(operation, ...)` | 交易域 | 自主执行 | 单次调用内完成校验+preview+风控裁决+下单/撤单,不经过人工确认 |
| `compute(code)` | 领域增强 | 计算器 | 沙箱化 Python(安全版 bash) |
| `market_ohlcv(symbol, interval, mode)` | 领域核心 | 眼睛 | 内核数据原语,支持日线/分钟/history/latest |
| `recall(query)` | 领域增强 | 回忆 | 全文搜索 memory + notebook |
Expand All @@ -146,7 +145,7 @@ memory.write 就是 `write("memory.md", content)`,read 就是 `read("memory.md

但当前持仓和具体自选列表是例外:它们需要被 Agent 稳定读取,也适合被自动化或 UI 直接消费,因此分别用 `portfolio` 维护 `portfolio.json`、用 `watchlist` 维护 `watchlist.json`,而不是继续把明细散写在 memory.md 里。

远端 broker 交易又是另一类例外:它不是工作区快照维护,而是受确认与审计约束的外部动作。因此新增一层交易边界层,由 `trade_account / trade_plan / trade_apply` 暴露给 LLM,详细规格见 [trading.md](./trading.md)。
远端 broker 交易又是另一类例外:它不是工作区快照维护,而是受审计约束的外部动作。安全边界是程序化的 `RiskGuard`,不是人类确认——Agent 是自主交易操作员。因此新增一层交易边界层,由 `trade_account / trade_execute` 暴露给 LLM,详细规格见 [trading.md](./trading.md)。

read/write/edit 的覆盖范围:
- 写研究报告 → `write("notebook/research/宁德时代/2024-01-15.md", content)`
Expand Down Expand Up @@ -733,8 +732,8 @@ Agent 输出任务设计稿:
| market_ohlcv | ✅ | MarketAdapter + DataStore |
| bash | ✅ | shell 执行 + 超时 + 进程树清理 |
| trade_account | ✅ | 远端 broker 账户只读访问 |
| trade_plan | ✅ | 交易计划生成 |
| trade_apply | ✅ | 交易计划执行 |
| trade_execute | ✅ | 自主下单/撤单,单步执行,无人工确认 |
| market_snapshot | ✅ | 富途实时行情快照 |

### 预连通管道

Expand Down
5 changes: 3 additions & 2 deletions docs/automation.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,9 @@ Reaction 不是 workflow,而是“一次执行”。
交易工具的自动化规则:

- `trade_account` 允许只读使用
- `trade_plan` 永久禁止
- `trade_apply` 永久禁止
- `trade_execute` 允许调用——Agent 已是自主交易操作员,automation 可自主下单/撤单

⚠️ 风控专题首要 TODO:无人值守 automation 对 real 账户裸奔风险最高。`TradeOrchestrator` 传给 `RiskGuard` 的 `RiskContext.automation` 字段就是为它预留的裁决挂钩,但这期 `AllowAllGuard` 恒 ALLOW,当前没有任何拦截。详见 [trading.md](./trading.md) §6。

## 11. 幂等与恢复

Expand Down
41 changes: 19 additions & 22 deletions docs/tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
| `portfolio` | 维护结构化当前持仓快照 `portfolio.json` |
| `watchlist` | 维护结构化自选列表快照 `watchlist.json` |
| `trade_account` | 读取远端 broker 账户、持仓、未完成订单、订单状态 |
| `trade_plan` | 生成交易执行计划,不直接产生外部副作用 |
| `trade_apply` | 执行 `trade_plan` 生成的计划 |
| `trade_execute` | 自主交易执行:单次调用内完成校验+preview+风控裁决+下单/撤单,不经过人工确认 |
| `market_snapshot` | 富途实时行情快照(last/bid/ask),区别于 `market_ohlcv` 的 K 线 |
| `compute` | 在沙箱中对已加载 OHLCV 做 Python 分析 |
| `read` | 读工作区文件 |
| `write` | 写工作区文件 |
| `edit` | 精确文本替换 |
| `bash` | 执行 shell 命令(按权限控制) |
| `web_search` / `web_fetch` | 可选 Web 搜索与抓取 |

其中最容易用错的是 `portfolio`、`watchlist`、`trade_account`、`trade_plan`、`trade_apply`、`market_ohlcv` 和 `compute`。
其中最容易用错的是 `portfolio`、`watchlist`、`trade_account`、`trade_execute`、`market_ohlcv` 和 `compute`。

## portfolio

Expand Down Expand Up @@ -114,18 +114,19 @@
`memory.md` 适合记录高层关注方向和长期偏好。
具体自选 symbol 清单、观察理由和加入时间需要结构化读取,因此单独维护在 `watchlist.json`。

## trade_account / trade_plan / trade_apply
## trade_account / trade_execute

### 核心语义

这三者共同组成远端 broker 交易闭环:
这两者共同组成远端 broker 交易闭环,自主交易操作员范式——中间不经过人工确认

- `trade_account`:读取远端账户状态
- `trade_plan`:创建可确认、可审计的执行计划
- `trade_apply`:执行计划
- `trade_account`:读取远端账户状态(只读)
- `trade_execute`:唯一执行入口,`operation=submit_limit|cancel`,单次调用内完成校验+preview+`RiskGuard.evaluate`+下单/撤单+状态回读

它们不是 `portfolio` 的替代物,也不会自动维护 `portfolio.json`。

安全边界是程序化的 `RiskGuard`(这期 `AllowAllGuard` 占位,恒 ALLOW,真实风控是独立专题),不是人类确认——详见 [trading.md](./trading.md) §6。

### V1 边界

只支持:
Expand All @@ -147,17 +148,16 @@
### 正确用法

1. 先 `trade_account.list_accounts`
2. 再 `trade_plan.submit_limit` 或 `trade_plan.cancel`
3. 最后 `trade_apply`
2. 直接 `trade_execute(operation="submit_limit", ...)` 或 `trade_execute(operation="cancel", ...)`

不能跳过 `trade_plan` 直接执行
一次调用即完成下单/撤单,没有二段式确认步骤

显式参数规则:

- `trade_account.get_positions/get_summary/get_open_orders` 必须显式传 `account_ref`
- `trade_account.get_order_status` 必须显式传 `order_ref`
- `trade_plan.submit_limit` 必须显式传 `account_ref`
- `trade_plan.cancel` 必须显式传 `order_ref`
- `trade_execute(operation="submit_limit")` 必须显式传 `account_ref`
- `trade_execute(operation="cancel")` 必须显式传 `order_ref`
- 不会自动承接最近账户、最近订单,也不会返回 suggestion

### 账户发现
Expand All @@ -184,19 +184,16 @@
`trade_account.get_positions` 成功后,会把该账户快照写入 `Kernel.data["account"]`。
后续 `compute` 读取到的 `account/cash/equity/positions` 就来自这个当前活动账户快照。

### 计划与执行返回

`trade_plan.submit_limit` 返回的 plan 除了 `plan_id` 外,还会返回:

- `normalized_intent`
### 执行返回

其中 `normalized_intent.limit_price` 是后续 `trade_apply` 唯一允许执行的价格。
如果 provider 对输入价格做了规范化,plan 的 `warnings` 里会明确写出原始价格和规范化后的价格。

`trade_apply` 返回除了 `order_status` 外,还会返回:
`trade_execute(operation="submit_limit")` 一次调用内完成校验+preview+风控裁决+下单+状态回读,返回除了 `order_status` 外,还会返回:

- `normalized_intent`:如果 provider 对输入价格做了规范化,`warnings` 里会明确写出原始价格和规范化后的价格
- `finalized`
- `warnings`
- `plan_id`:语义已从"待确认计划 id"改为一次性执行 id,纯审计用途

`trade_execute(operation="cancel")` 返回同样包含 `order_status`/`finalized`/`warnings`。

语义是:

Expand Down
Loading