Skill: seandong/poly-cli (version 0.1.5)

--- name: polymarket-cli description: "Operate Polymarket from terminal with the `polymarket` Rust CLI (v0.1.5). Covers market/event/tag/series discovery, CLOB order book queries (single & batch), wallet & approval management, order placement/cancelation (GTC/FOK/GTD/FAK), portfolio & on-chain data, CTF operations, rewards/earnings, bridge deposits, sports metadata, API key management, and JSON output for automation." --- # Polymarket CLI 使用本技能时，按用户目标直接执行对应命令；默认先收集必要参数并返回可复现结果。 ## 快速决策 1. 先判断请求类型： - **只读**：市场浏览、价格、盘口、持仓查询、历史数据、tags/series/comments、sports、rewards 查询。 - **写操作**：下单、撤单、approve、split/merge/redeem、API key 管理、bridge deposit、wallet reset。 2. 只读请求可直接执行。 3. 写操作先做预检（余额/参数/网络），然后执行并回读结果。 ## 环境检查与安装 按顺序执行： ```bash polymarket --version ``` 若未安装，优先一键脚本： ```bash curl -sSL https://raw.githubusercontent.com/Polymarket/polymarket-cli/main/install.sh | sh ``` 或 Homebrew： ```bash brew tap Polymarket/polymarket-cli https://github.com/Polymarket/polymarket-cli brew install polymarket ``` 无法使用以上方式时，回退源码安装： ```bash git clone https://github.com/Polymarket/polymarket-cli cd polymarket-cli cargo install --path . ``` ## 标准执行流程 ### 1) 读取需求并标准化参数 最少明确： - 市场标识（slug / market id / condition id / token id） - 方向与数量（buy/sell, amount/size） - 价格类型（limit/market） - 输出格式（table/json） 如要脚本集成，统一使用：`-o json`。 ### 2) 只读查询模式（默认） 常用命令： ```bash polymarket markets search "bitcoin" --limit 5 polymarket markets get <slug-or-id> polymarket clob book <TOKEN_ID> polymarket clob midpoint <TOKEN_ID> polymarket clob spread <TOKEN_ID> polymarket -o json clob price-history <TOKEN_ID> --interval 1d # 批量查询 polymarket clob batch-prices <TOKEN_ID1>,<TOKEN_ID2> polymarket clob books <TOKEN_ID1>,<TOKEN_ID2> # 元数据 polymarket tags list polymarket series list polymarket comments list --event <EVENT_ID> ``` ### 3) 交易前预检 全局选项（所有子命令均可用）： - `--private-key <KEY>` — 覆盖环境变量/配置文件中的私钥 - `--signature-type <TYPE>` — 签名类型：`eoa`（默认）、`proxy`、`gnosis-safe` 执行： ```bash polymarket wallet show polymarket approve check polymarket clob balance --asset-type collateral polymarket clob account-status ``` 核对点： - 钱包地址是否符合预期 - 是否完成 approvals - 是否有足够 USDC / MATIC（链上写操作 gas） - 签名类型是否匹配（proxy 钱包需要 `--signature-type proxy`） ### 4) 写操作执行 示例： ```bash # 限价单 polymarket clob create-order --token <TOKEN_ID> --side buy --price 0.50 --size 10 # 指定 order type polymarket clob create-order --token <TOKEN_ID> --side buy --price 0.50 --size 10 --order-type FOK # 仅挂单 polymarket clob create-order --token <TOKEN_ID> --side sell --price 0.60 --size 5 --post-only # 市价单 polymarket clob market-order --token <TOKEN_ID> --side buy --amount 5 # 批量下单 polymarket clob post-orders <JSON_FILE> # 撤单 polymarket clob cancel <ORDER_ID> polymarket clob cancel-orders <ORDER_ID1>,<ORDER_ID2> # 授权 polymarket approve set # Bridge 充值 polymarket bridge deposit ``` 执行后立即回读验证： ```bash polymarket clob orders polymarket clob order <ORDER_ID> polymarket clob trades ``` ## 输出约定 - 给人看：table（默认） - 给程序：json（`-o json`） - 失败时：记录命令、stderr、退出码；不要静默吞错。 ## 参考资料 - 命令速查：`references/commands.md` - 故障排查：`references/troubleshooting.md`

path: references/commands.md
content: # Polymarket CLI 命令速查 (v0.1.5)

## 0) 全局选项

```bash
polymarket --help
polymarket --version
polymarket -o json <subcommand>        # JSON 输出
polymarket --private-key <KEY> <cmd>   # 覆盖环境变量/配置文件私钥
polymarket --signature-type <TYPE> <cmd>  # eoa | proxy | gnosis-safe
```

## 1) 市场与事件（只读）

```bash
polymarket markets list --limit 10
polymarket markets search "election"
polymarket markets get <slug-or-id>
polymarket markets tags <market_id>

polymarket events list --tag politics --active true
polymarket events get <event_id>
```

## 2) CLOB 只读查询

```bash
# 健康检查
polymarket clob ok
polymarket clob time                     # 服务器时间
polymarket clob geoblock                 # 地理封锁检查

# 单 token 查询
polymarket clob price <TOKEN_ID> --side buy
polymarket clob midpoint <TOKEN_ID>
polymarket clob spread <TOKEN_ID>
polymarket clob book <TOKEN_ID>
polymarket clob last-trade <TOKEN_ID>
polymarket clob tick-size <TOKEN_ID>
polymarket clob fee-rate <TOKEN_ID>
polymarket clob neg-risk <TOKEN_ID>
polymarket clob price-history <TOKEN_ID> --interval 1d --fidelity 30

# 批量查询（逗号分隔多个 token ID）
polymarket clob batch-prices <TOKEN_IDS>
polymarket clob midpoints <TOKEN_IDS>
polymarket clob spreads <TOKEN_IDS>
polymarket clob books <TOKEN_IDS>
polymarket clob last-trades <TOKEN_IDS>

# 市场列表
polymarket clob market <CONDITION_ID>        # 按 condition ID 查单个市场
polymarket clob markets                      # 列出 CLOB 市场
polymarket clob sampling-markets             # 奖励资格市场
polymarket clob simplified-markets           # 精简详情
polymarket clob sampling-simp-markets        # 精简奖励资格市场
```

## 3) 钱包与授权（有写操作）

```bash
polymarket wallet create
polymarket wallet import <private_key>
polymarket wallet show
polymarket wallet address                # 仅显示地址
polymarket wallet reset                  # 删除所有配置和密钥（慎用）

polymarket approve check
polymarket approve set
```

## 4) 下单撤单（写操作）

```bash
# 创建订单
polymarket clob create-order --token <TOKEN_ID> --side buy --price 0.50 --size 10
polymarket clob create-order --token <TOKEN_ID> --side buy --price 0.50 --size 10 --order-type FOK
polymarket clob create-order --token <TOKEN_ID> --side sell --price 0.60 --size 5 --post-only

# Order types: GTC (默认), FOK (全部成交或取消), GTD (指定过期时间), FAK (尽量成交剩余取消)
# --post-only: 仅挂单，不吃单

# 市价单
polymarket clob market-order --token <TOKEN_ID> --side buy --amount 5

# 批量下单
polymarket clob post-orders <JSON_FILE>

# 撤单
polymarket clob cancel <ORDER_ID>
polymarket clob cancel-orders <ORDER_ID1>,<ORDER_ID2>
polymarket clob cancel-market <CONDITION_ID>   # 撤销某市场全部订单
polymarket clob cancel-all

# 查询
polymarket clob orders                         # 所有挂单
polymarket clob order <ORDER_ID>               # 单个订单详情
polymarket clob trades                         # 成交记录
polymarket clob balance --asset-type collateral
polymarket clob update-balance                 # 刷新链上余额授权
polymarket clob account-status                 # 账户状态
```

## 5) 链上数据（只读）

```bash
polymarket data positions <WALLET_ADDRESS>
polymarket data closed-positions <WALLET_ADDRESS>
polymarket data value <WALLET_ADDRESS>
polymarket data activity <WALLET_ADDRESS>
polymarket data traded <WALLET_ADDRESS>          # 参与过的市场数
polymarket data trades <WALLET_ADDRESS> --limit 50
polymarket data holders <MARKET_ID>              # token 持有人排行
polymarket data open-interest <MARKET_ID>
polymarket data volume <EVENT_ID>                # 事件实时交易量
polymarket data leaderboard --period month --order-by pnl --limit 10
polymarket data builder-leaderboard
polymarket data builder-volume
```

## 6) CTF（写操作）

```bash
polymarket ctf split --condition <CONDITION_ID> --amount 10
polymarket ctf split --condition <CONDITION_ID> --amount 10 --collateral <ADDRESS> --partition "1,2" --parent-collection <COLLECTION_ID>
polymarket ctf merge --condition <CONDITION_ID> --amount 10
polymarket ctf redeem --condition <CONDITION_ID>
polymarket ctf redeem-neg-risk --condition <CONDITION_ID>

# 辅助计算
polymarket ctf condition-id --oracle <ADDR> --question <ID> --outcomes <COUNT>
polymarket ctf collection-id --condition <CONDITION_ID> --index-set <SET>
polymarket ctf position-id --collateral <ADDR> --collection <COLLECTION_ID>
```

## 7) 奖励与 API 密钥（认证）

```bash
# 奖励查询
polymarket clob rewards
polymarket clob earnings --date 2026-03-15
polymarket clob earnings-markets
polymarket clob reward-percentages
polymarket clob current-rewards
polymarket clob market-reward <CONDITION_ID>
polymarket clob order-scoring <ORDER_ID>
polymarket clob orders-scoring <ORDER_ID1>,<ORDER_ID2>

# API 密钥管理
polymarket clob api-keys
polymarket clob create-api-key
polymarket clob delete-api-key

# 通知
polymarket clob notifications
polymarket clob delete-notifications <ID1>,<ID2>
```

## 8) Bridge

```bash
polymarket bridge deposit                      # 获取充值地址（EVM/Solana/Bitcoin）
polymarket bridge supported-assets             # 支持的链和代币
polymarket bridge status <ADDRESS>             # 查询充值交易状态
```

## 9) 元数据（只读）

```bash
# Tags
polymarket tags list
polymarket tags get <TAG_ID_OR_SLUG>
polymarket tags related <TAG_ID>
polymarket tags related-tags <TAG_ID>

# Series
polymarket series list
polymarket series get <SERIES_ID>

# Comments
polymarket comments list --event <EVENT_ID>
polymarket comments get <COMMENT_ID>
polymarket comments by-user <WALLET_ADDRESS>

# Profiles
polymarket profiles get <WALLET_ADDRESS>

# Sports
polymarket sports list
polymarket sports market-types
polymarket sports teams
```

## 10) 工具命令

```bash
polymarket status       # API 健康检查
polymarket setup        # 引导式首次设置（钱包、代理、授权）
polymarket upgrade      # 更新到最新版本
polymarket shell        # 启动交互式 shell
```


path: references/troubleshooting.md
content: # Polymarket CLI 故障排查

## 1) `command not found: polymarket`

- 确认安装：`brew install polymarket` 或 `curl -sSL ... | sh`
- 确认 PATH：`which polymarket`

## 2) 钱包相关失败 / 无法签名

- 检查配置：`polymarket wallet show`
- 检查私钥来源优先级：
  1. `--private-key`
  2. `POLYMARKET_PRIVATE_KEY`
  3. `~/.config/polymarket/config.json`

## 3) 下单失败（认证/余额/授权）

依次检查：

```bash
polymarket clob account-status
polymarket clob balance --asset-type collateral
polymarket clob update-balance               # 刷新链上余额授权
polymarket approve check
```

若未授权，执行 `polymarket approve set`（会产生链上交易，需要 MATIC gas）。

## 4) 网络或 API 异常

```bash
polymarket status
polymarket clob ok
```

若 API 短时故障：重试只读命令；写操作必须等状态恢复后再继续。

## 5) JSON 脚本解析失败

- 强制 JSON 输出：`-o json`
- 检查 stderr 与退出码，不要只解析 stdout。

## 6) 风控建议

- 先小额验证再放量。
- 写操作执行前再次回显参数（token、side、price/amount、size）。
- 完成后立即 `clob orders` / `clob trades` 回读校验。

## 7) 签名类型不匹配

症状：交易签名失败、返回 invalid signature 或 unauthorized 错误。

排查：
- `polymarket wallet show` 查看当前钱包类型
- 如果使用 proxy 钱包，需要加 `--signature-type proxy`
- 如果使用 Gnosis Safe 多签，需要加 `--signature-type gnosis-safe`
- 默认为 `eoa`（Externally Owned Account）

```bash
# 示例：proxy 钱包下单
polymarket --signature-type proxy clob create-order --token <TOKEN_ID> --side buy --price 0.50 --size 10
```

## 8) Bridge 充值问题

排查步骤：

```bash
polymarket bridge supported-assets         # 确认支持的链和代币
polymarket bridge deposit                  # 获取充值地址
polymarket bridge status <ADDRESS>         # 查询充值状态
```

常见问题：
- 充值未到账：用 `bridge status` 检查交易确认数
- 不支持的资产：先用 `supported-assets` 确认
- 地址错误：每次充值前重新获取地址确认


Security scan verdicts — ClawScan: suspicious | static analysis: clean | VirusTotal: clean | SkillSpector: suspicious (HIGH)