Skill: ulnit/fiu-market-assistant (version 1.0.13)

--- name: fiu-market-assistant description: "FIU MCP Market Data and Trading Assistant. Use when user wants to query stock quotes, K-line, trade stocks, check positions, or analyze market data for HK/US/CN markets." user-invocable: true allowed-tools: - Read - Write - Bash metadata: openclaw: requires: env: - FIU_MCP_TOKEN binaries: - curl - jq - date - bash primaryCredential: FIU_MCP_TOKEN --- # /fiu-market-assistant — FIU Market Data & Trading Provides stock market data query and trading capabilities via FIU MCP Server. Supports HK, US, and CN stock markets with quotes, K-line, order book, capital flow, and trading operations. Arguments passed: `$ARGUMENTS` --- ## Quick Start (One Command Setup) ```bash # First time setup - configure MCP and set token /fiu-market-assistant setup YOUR_FIU_MCP_TOKEN ``` After setup, simply use natural language: ``` Query Tencent Holdings quote Show AAPL daily K-line Buy 100 shares Tencent ``` --- ## Dispatch on Arguments ### No args — show status 1. **Check FIU_MCP_TOKEN** - show if token is configured (masked) 2. **Show available markets** - list HK, US, CN, toolkit 3. **Show quick commands** - list available dispatch commands 4. **What next** - guide user: - No token → "Run `/fiu-market-assistant setup <token>` to configure" - Configured → "Ready! Ask me anything like 'Query 00700 quote'" ### `setup <token>` — quick setup (recommended) 1. Save token to config file `~/.fiu-market/config` 2. Create MCP config `.mcp.json` with all 7 FIU services 3. Test connectivity 4. Confirm and guide restart ### `test` — test connectivity 1. Check FIU_MCP_TOKEN is set 2. Test each market endpoint with tools/list 3. Show which services are working 4. Report any errors ### `discover <market>` — discover available tools List all available tools for a specific market: ``` /fiu-market-assistant discover hk_sdk /fiu-market-assistant discover cn_sdk ``` ### `quote <symbol>` — query quote Query real-time quote for a stock: ``` /fiu-market-assistant quote 00700 /fiu-market-assistant quote AAPL /fiu-market-assistant quote 600519 ``` ### `kline <symbol> [type]` — query K-line Query K-line data: ``` /fiu-market-assistant kline 00700 # daily /fiu-market-assistant kline 00700 1 # weekly /fiu-market-assistant kline AAPL 5 # 1-min for US ``` ### `search <keyword>` — search stock code Search for stock by name: ``` /fiu-market-assistant search 腾讯 /fiu-market-assistant search Apple ``` ### `trade <action> <symbol> <qty> [price]` — trade Place orders (default SIMULATE mode): ``` /fiu-market-assistant trade buy 00700 100 380 /fiu-market-assistant trade sell AAPL 50 150 /fiu-market-assistant trade buy 600519 1000 200 ``` ### `positions` — query positions ``` /fiu-market-assistant positions ``` ### `cash` — query cash ``` /fiu-market-assistant cash ``` ### `orders` — query orders ``` /fiu-market-assistant orders ``` ### `capflow <symbol>` — capital flow ``` /fiu-market-assistant capflow 00700 ``` --- ## MCP Servers Reference ### Market Endpoints | Service | Market | URL | |---------|--------|-----| | stockHkF10 | HK F10 | https://ai.szfiu.com/stock_hk_f10/ | | stockUsF10 | US F10 | https://ai.szfiu.com/stock_us_f10/ | | stockCnF10 | CN F10 | https://ai.szfiu.com/stock_cn_f10/ | | stockHkSdk | HK SDK | https://ai.szfiu.com/stock_hk_sdk/ | | stockUsSdk | US SDK | https://ai.szfiu.com/stock_us_sdk/ | | stockCnSdk | CN SDK | https://ai.szfiu.com/stock_cn_sdk/ | | szfiuToolkit | Search | https://ai.szfiu.com/toolkit/ | ### Feature Support by Market | Feature | HK (港股) | US (美股) | CN (A股) | |---------|-----------|-----------|----------| | Quote | ✅ | ✅ | ✅ | | K-line | ✅ | ✅ | ✅ | | Order Book | ✅ | ✅ | ✅ | | Tick Data | ✅ | ✅ | ✅ | | Intraday | ✅ | ✅ | ✅ | | Capital Flow | ✅ | ✅ | ✅ | | Capital Distribution | ✅ | ✅ | ✅ | | Sector List | ✅ | ✅ | ✅ | | Stock Filter | ✅ | ✅ | ✅ | | Market Ranking | ✅ | ✅ | ✅ | | F10 Data | ✅ | ✅ | ✅ | | Trading | ✅ | ✅ | ✅ | | Search | ✅ | ✅ | ✅ | --- ## Usage Tips 1. **Use search first** to find correct stock code 2. **Default mode is SIMULATE** - use "REAL" for real trading 3. **HK stocks**: use format `00700.HK` or just `00700` 4. **US stocks**: use format `AAPL` or `AAPL.US` 5. **CN stocks**: use format `600519.SZ` or `000001.SZ` 6. **Rate limit**: 15 orders per 30 seconds 7. **Get token**: https://ai.szfiu.com/auth/login ## Important Notes - Trading defaults to SIMULATE mode for safety - Real trading requires explicit "REAL" confirmation - Always check market status before trading - The setup command will create/overwrite ~/.mcp.json (standard MCP config file) - Backup is created automatically before overwriting - Config files are stored with restricted permissions (600) - only owner can read - This skill adds 7 FIU MCP entries to your MCP configuration - Other MCP-enabled tools may also use ~/.mcp.json - review after setup if needed

path: install.sh
content: #!/bin/bash
# fiu-market-assistant Quick Setup Script

set -e

echo "🚀 FIU Market Assistant 快速配置"
echo "================================"
echo ""

# Check if token provided
if [ -z "$1" ]; then
    echo "用法: $0 <FIU_MCP_TOKEN>"
    echo ""
    echo "示例: $0 eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9..."
    echo ""
    echo "获取 [REDACTED_SECRET]"
    exit 1
fi

TOKEN="$1"
CONFIG_DIR="$HOME/.fiu-market"
CONFIG_FILE="$CONFIG_DIR/config"

# Create config directory
mkdir -p "$CONFIG_DIR"

# Save token
echo "export FIU_MCP_TOKEN=\"$TOKEN\"" > "$CONFIG_FILE"
echo "✅ Token 已保存到 $CONFIG_FILE"

# Create .mcp.json for Claude Code
MCP_FILE="$HOME/.mcp.json"

# Check if .mcp.json exists
if [ -f "$MCP_FILE" ]; then
    echo "📝 检测到已有 .mcp.json，将更新..."
    # Backup
    cp "$MCP_FILE" "$MCP_FILE.bak"
fi

# Create MCP config
cat > "$MCP_FILE" << 'MCPEOF'
{
  "mcpServers": {
    "stockHkF10": {
      "description": "港股市场F10数据",
      "transport": "streamable_http",
      "url": "https://ai.szfiu.com/stock_hk_f10/",
      "headers": {
        "Authorization": "Bearer TOKEN_PLACEHOLDER"
      }
    },
    "stockUsF10": {
      "description": "美股市场F10数据",
      "transport": "streamable_http",
      "url": "https://ai.szfiu.com/stock_us_f10/",
      "headers": {
        "Authorization": "Bearer TOKEN_PLACEHOLDER"
      }
    },
    "stockCnF10": {
      "description": "A股市场F10数据",
      "transport": "streamable_http",
      "url": "https://ai.szfiu.com/stock_cn_f10/",
      "headers": {
        "Authorization": "Bearer TOKEN_PLACEHOLDER"
      }
    },
    "stockHkSdk": {
      "description": "港股市场SDK数据",
      "transport": "streamable_http",
      "url": "https://ai.szfiu.com/stock_hk_sdk/",
      "headers": {
        "Authorization": "Bearer TOKEN_PLACEHOLDER"
      }
    },
    "stockUsSdk": {
      "description": "美股市场SDK数据",
      "transport": "streamable_http",
      "url": "https://ai.szfiu.com/stock_us_sdk/",
      "headers": {
        "Authorization": "Bearer TOKEN_PLACEHOLDER"
      }
    },
    "stockCnSdk": {
      "description": "A股市场SDK数据",
      "transport": "streamable_http",
      "url": "https://ai.szfiu.com/stock_cn_sdk/",
      "headers": {
        "Authorization": "Bearer TOKEN_PLACEHOLDER"
      }
    },
    "szfiuToolkit": {
      "description": "FIU检索证券代码服务",
      "transport": "streamable_http",
      "url": "https://ai.szfiu.com/toolkit/"
    }
  }
}
MCPEOF

# Replace placeholder with actual token
sed -i "s/TOKEN_PLACEHOLDER/$TOKEN/g" "$MCP_FILE"

echo "✅ MCP 配置已保存到 $MCP_FILE"

# Test connectivity
echo ""
echo "🧪 测试连接..."

TEST_RESPONSE=$(curl -s -X POST "https://ai.szfiu.com/toolkit/" \
    -H "Content-Type: application/json" \
    -H "Accept: application/json, text/event-stream" \
    -d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}')

if echo "$TEST_RESPONSE" | grep -q "tools"; then
    echo "✅ 连接测试成功!"
else
    echo "⚠️  连接测试失败，请检查 Token 是否有效"
fi

echo ""
echo "================================"
echo "🎉 配置完成!"
echo ""
echo "请执行以下操作:"
echo "1. 重启 Claude Code / OpenClaw"
echo "2. 使用自然语言查询，如:"
echo "   - 查询腾讯控股行情"
echo "   - 显示苹果日K线"
echo "   - 搜索腾讯"
echo ""
echo "或使用命令:"
echo "   /fiu-market-assistant quote 00700"
echo "   /fiu-market-assistant search 腾讯"

path: skill.json
content: {
  "name": "fiu-market-assistant",
  "version": "1.0.7",
  "description": "FIU MCP Market Data and Trading Assistant",
  "homepage": "https://github.com/fiu-ai/openclaw-skills",
  "source": "https://github.com/fiu-ai/openclaw-skills",
  "author": "@ulnit",
  "license": "MIT-0",
  "requiredEnvVars": [
    {
      "name": "FIU_MCP_TOKEN",
      "description": "JWT token for FIU MCP Server authentication. Get your token from https://ai.szfiu.com/auth/login",
      "required": true,
      "sensitive": true
    }
  ],
  "requiredBinaries": [
    "curl",
    "jq",
    "date",
    "bash"
  ],
  "primaryCredential": "FIU_MCP_TOKEN",
  "capabilities": [
    "market_data_query",
    "trading"
  ],
  "trading": {
    "mode": "both",
    "defaultMode": "SIMULATE",
    "requiresConfirmation": true
  },
  "user-invocable": true,
  "allowed-tools": [
    "Read",
    "Write",
    "Bash"
  ]
}

path: SKILL_CN.md
content: ---
name: fiu-market-assistant
description: "FIU MCP 行情交易助手。当用户想要查询股票行情、K线、交易股票、查看持仓或分析港股/美股/A股市场数据时使用。"
user-invocable: true
allowed-tools:
  - Read
  - Write
  - Bash
metadata:
  openclaw:
    requires:
      env:
        - FIU_MCP_TOKEN
      binaries:
        - curl
        - jq
        - date
        - bash
      primaryCredential: FIU_MCP_TOKEN
---

# /fiu-market-assistant — FIU 行情交易助手

通过 FIU MCP Server 提供股票市场数据查询和交易功能。支持港股、美股、A股的行情、K线、买卖盘、资金流向和交易操作。

参数传递: `$ARGUMENTS`

---

## 快速开始（一步配置）

```bash
# 首次配置 - 设置 MCP 和 Token
/fiu-market-assistant setup 你的_FIU_MCP_TOKEN
```

配置完成后，直接用自然语言提问：
```
查询腾讯控股行情
显示苹果日K线
买入100股腾讯
```

---

## 命令 dispatch

### 无参数 — 显示状态

1. **检查 FIU_MCP_TOKEN** - 显示是否已配置（脱敏）
2. **显示可用市场** - 列出 HK, US, CN, toolkit
3. **显示快速命令** - 列出可用的 dispatch 命令
4. **下一步** - 引导用户：
   - 未配置 → "运行 `/fiu-market-assistant setup <token>` 进行配置"
   - 已配置 → "就绪! 可以提问如 '查询00700行情'"

### `setup <token>` — 快速配置（推荐）

1. 保存 token 到配置文件 `~/.fiu-market/config`
2. 创建 MCP 配置文件 `.mcp.json`，包含全部 7 个 FIU 服务
3. 测试连接
4. 确认并引导重启

### `test` — 测试连接

1. 检查 FIU_MCP_TOKEN 是否已设置
2. 用 tools/list 测试每个市场端点
3. 显示哪些服务可用
4. 报告错误

### `discover <market>` — 发现可用工具

列出特定市场的所有可用工具：

```
/fiu-market-assistant discover hk_sdk
/fiu-market-assistant discover cn_sdk
```

### `quote <股票代码>` — 查询行情

查询股票实时行情：

```
/fiu-market-assistant quote 00700
/fiu-market-assistant quote AAPL
/fiu-market-assistant quote 600519
```

### `kline <股票代码> [类型]` — 查询K线

查询K线数据：

```
/fiu-market-assistant kline 00700        # 日K
/fiu-market-assistant kline 00700 1      # 周K
/fiu-market-assistant kline AAPL 5       # 美股1分钟K
```

### `search <关键词>` — 搜索股票代码

按名称搜索股票：

```
/fiu-market-assistant search 腾讯
/fiu-market-assistant search Apple
```

### `trade <操作> <股票代码> <数量> [价格]` — 交易

下单（默认模拟模式）：

```
/fiu-market-assistant trade buy 00700 100 380
/fiu-market-assistant trade sell AAPL 50 150
/fiu-market-assistant trade buy 600519 1000 200
```

### `positions` — 查询持仓

```
/fiu-market-assistant positions
```

### `cash` — 查询资金

```
/fiu-market-assistant cash
```

### `orders` — 查询订单

```
/fiu-market-assistant orders
```

### `capflow <股票代码>` — 资金流向

```
/fiu-market-assistant capflow 00700
```

---

## MCP 服务器参考

### 市场端点

| 服务 | 市场 | URL |
|------|------|-----|
| stockHkF10 | 港股F10 | https://ai.szfiu.com/stock_hk_f10/ |
| stockUsF10 | 美股F10 | https://ai.szfiu.com/stock_us_f10/ |
| stockCnF10 | A股F10 | https://ai.szfiu.com/stock_cn_f10/ |
| stockHkSdk | 港股SDK | https://ai.szfiu.com/stock_hk_sdk/ |
| stockUsSdk | 美股SDK | https://ai.szfiu.com/stock_us_sdk/ |
| stockCnSdk | A股SDK | https://ai.szfiu.com/stock_cn_sdk/ |
| szfiuToolkit | 代码检索 | https://ai.szfiu.com/toolkit/ |

### 各市场功能支持

| 功能 | 港股 | 美股 | A股 |
|------|------|------|-----|
| 行情 | ✅ | ✅ | ✅ |
| K线 | ✅ | ✅ | ✅ |
| 买卖盘 | ✅ | ✅ | ✅ |
| 逐笔成交 | ✅ | ✅ | ✅ |
| 分时数据 | ✅ | ✅ | ✅ |
| 资金流向 | ✅ | ✅ | ✅ |
| 资金分布 | ✅ | ✅ | ✅ |
| 板块列表 | ✅ | ✅ | ✅ |
| 条件选股 | ✅ | ✅ | ✅ |
| 市场排行榜 | ✅ | ✅ | ✅ |
| F10数据 | ✅ | ✅ | ✅ |
| 交易功能 | ✅ | ✅ | ✅ |
| 代码搜索 | ✅ | ✅ | ✅ |

---

## 使用技巧

1. **先用 search** 找到正确的股票代码
2. **默认模式是模拟交易** - 使用 "REAL" 进行实盘
3. **港股**: 使用格式 `00700.HK` 或直接 `00700`
4. **美股**: 使用格式 `AAPL` 或 `AAPL.US`
5. **A股**: 使用格式 `600519.SZ` 或 `000001.SZ`
6. **限频**: 30秒内最多15笔订单
7. **获取Token**: https://ai.szfiu.com/auth/login

## 重要提示

- 交易默认使用模拟模式，安全第一
- 实盘交易需要明确确认 "REAL"
- 交易前请先检查市场是否开市
- setup 命令会创建/覆盖 ~/.mcp.json（标准 MCP 配置文件）
- 覆盖前会自动创建备份
- 配置文件权限设置为 600，仅所有者可读
- 此技能会向您的 MCP 配置添加 7 个 FIU MCP 条目
- 其他 MCP 工具也可能使用 ~/.mcp.json，如需要请在设置后检查

path: scripts/cli.sh
content: #!/bin/bash
# fiu-market-assistant - Main dispatch script
# Handles: setup, test, discover, quote, kline, search, trade, positions, cash, orders, capflow

set -e

# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'

# Config
CONFIG_FILE="$HOME/.fiu-market/config"
MCP_FILE="$HOME/.mcp.json"

# Load token
load_token() {
    if [ -f "$CONFIG_FILE" ]; then
        source "$CONFIG_FILE"
    fi
    if [ -z "$FIU_MCP_TOKEN" ]; then
        echo -e "${RED}错误: 请先配置 FIU_MCP_TOKEN${NC}"
        echo "运行: /fiu-market-assistant setup <token>"
        exit 1
    fi
}

# Show status
cmd_status() {
    load_token
    echo "📊 FIU Market Assistant 状态"
    echo "============================"
    echo ""

    # Check token
    if [ -n "$FIU_MCP_TOKEN" ]; then
        MASKED="${FIU_MCP_TOKEN:0:15}..."
        echo "✅ [REDACTED_SECRET]"
    else
        echo "❌ Token: 未配置"
    fi

    echo ""
    echo "📡 MCP 服务:"
    echo "   - stockHkF10  (港股F10)"
    echo "   - stockUsF10  (美股F10)"
    echo "   - stockCnF10  (A股F10)"
    echo "   - stockHkSdk  (港股SDK)"
    echo "   - stockUsSdk  (美股SDK)"
    echo "   - stockCnSdk  (A股SDK)"
    echo "   - szfiuToolkit (代码检索)"

    echo ""
    echo "📝 可用命令:"
    echo "   setup <token>    - 快速配置"
    echo "   test             - 测试连接"
    echo "   discover <市场>  - 发现可用工具"
    echo "   quote <代码>     - 查询行情"
    echo "   kline <代码>     - 查询K线"
    echo "   search <关键词>  - 搜索股票"
    echo "   trade <操作> <代码> <数量> [价格] - 交易"
    echo "   positions        - 查询持仓"
    echo "   cash             - 查询资金"
    echo "   orders           - 查询订单"
    echo "   capflow <代码>   - 资金流向"
}

# Quick setup
cmd_setup() {
    TOKEN="$1"
    if [ -z "$TOKEN" ]; then
        echo "用法: setup <FIU_MCP_TOKEN>"
        echo "获取[REDACTED_SECRET]"
        exit 1
    fi

    # Warn about ~/.mcp.json
    if [ -f "$MCP_FILE" ]; then
        echo -e "${YELLOW}⚠️  警告: ~/.mcp.json 已存在，将被覆盖!${NC}"
        echo "现有配置将备份为 ~/.mcp.json.bak"
        cp "$MCP_FILE" "$MCP_FILE.bak"
    fi

    # Save config with secure permissions
    mkdir -p "$HOME/.fiu-market"
    echo "export FIU_MCP_TOKEN=\"$TOKEN\"" > "$CONFIG_FILE"
    chmod 600 "$CONFIG_FILE"  # Secure: only owner can read

    # Create MCP config - warn users to merge if they have existing config
    cat > "$MCP_FILE" << MCPEOF
{
  "mcpServers": {
    "stockHkF10": {"transport":"streamable_http","url":"https://ai.szfiu.com/stock_hk_f10/","headers":{"Authorization":"Bearer $TOKEN"}},
    "stockUsF10": {"transport":"streamable_http","url":"https://ai.szfiu.com/stock_us_f10/","headers":{"Authorization":"Bearer $TOKEN"}},
    "stockCnF10": {"transport":"streamable_http","url":"https://ai.szfiu.com/stock_cn_f10/","headers":{"Authorization":"Bearer $TOKEN"}},
    "stockHkSdk": {"transport":"streamable_http","url":"https://ai.szfiu.com/stock_hk_sdk/","headers":{"Authorization":"Bearer $TOKEN"}},
    "stockUsSdk": {"transport":"streamable_http","url":"https://ai.szfiu.com/stock_us_sdk/","headers":{"Authorization":"Bearer $TOKEN"}},
    "stockCnSdk": {"transport":"streamable_http","url":"https://ai.szfiu.com/stock_cn_sdk/","headers":{"Authorization":"Bearer $TOKEN"}},
    "szfiuToolkit": {"transport":"streamable_http","url":"https://ai.szfiu.com/toolkit/"}
  }
}
MCPEOF

    echo -e "${GREEN}✅ 配置完成!${NC}"
    echo "Token 已保存，MCP 配置已创建到 ~/.mcp.json"
    echo ""
    if [ -f "$MCP_FILE.bak" ]; then
        echo "💾 备份文件: ~/.mcp.json.bak"
    fi
    echo "请重启 Claude Code / OpenClaw"
}

# Test connectivity
cmd_test() {
    load_token

    echo "🧪 测试各市场连接..."
    echo ""

    # Test toolkit (no auth needed)
    echo "1. 测试 szfiuToolkit..."
    RESP=$(curl -s -X POST "https://ai.szfiu.com/toolkit/" \
        -H "Content-Type: application/json" \
        -d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}')
    if echo "$RESP" | grep -q "tools"; then
        echo "   ✅ szfiuToolkit OK"
    else
        echo "   ❌ szfiuToolkit 失败"
    fi

    # Test HK SDK
    echo "2. 测试 stockHkSdk..."
    RESP=$(curl -s -X POST "https://ai.szfiu.com/stock_hk_sdk/" \
        -H "Authorization: Bearer $FIU_MCP_TOKEN" \
        -H "Content-Type: application/json" \
        -d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}')
    if echo "$RESP" | grep -q "tools"; then
        echo "   ✅ stockHkSdk OK"
    else
        echo "   ❌ stockHkSdk 失败"
    fi

    # Test CN SDK
    echo "3. 测试 stockCnSdk..."
    RESP=$(curl -s -X POST "https://ai.szfiu.com/stock_cn_sdk/" \
        -H "Authorization: Bearer $FIU_MCP_TOKEN" \
        -H "Content-Type: application/json" \
        -d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}')
    if echo "$RESP" | grep -q "tools"; then
        echo "   ✅ stockCnSdk OK"
    else
        echo "   ❌ stockCnSdk 失败"
    fi
}

# Discover tools
cmd_discover() {
    load_token
    MARKET="$1"

    if [ -z "$MARKET" ]; then
        echo "用法: discover <market>"
        echo "市场: hk_sdk, us_sdk, cn_sdk, hk_f10, us_f10, cn_f10, toolkit"
        exit 1
    fi

    declare -A ENDPOINTS=(
        ["hk_f10"]="https://ai.szfiu.com/stock_hk_f10/"
        ["us_f10"]="https://ai.szfiu.com/stock_us_f10/"
        ["cn_f10"]="https://ai.szfiu.com/stock_cn_f10/"
        ["hk_sdk"]="https://ai.szfiu.com/stock_hk_sdk/"
        ["us_sdk"]="https://ai.szfiu.com/stock_us_sdk/"
        ["cn_sdk"]="https://ai.szfiu.com/stock_cn_sdk/"
        ["toolkit"]="https://ai.szfiu.com/toolkit/"
    )

    ENDPOINT="${ENDPOINTS[$MARKET]}"
    if [ -z "$ENDPOINT" ]; then
        echo "错误: 未知市场 $MARKET"
        exit 1
    fi

    echo "🔍 发现 $MARKET 可用工具..."
    echo ""

    if [ "$MARKET" == "toolkit" ]; then
        RESP=$(curl -s -X POST "$ENDPOINT" \
            -H "Content-Type: application/json" \
            -d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}')
    else
        RESP=$(curl -s -X POST "$ENDPOINT" \
            -H "Authorization: Bearer $FIU_MCP_TOKEN" \
            -H "Content-Type: application/json" \
            -d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}')
    fi

    echo "$RESP" | grep -o '"name":"[^"]*"' | sed 's/"name":"//;s/"//' | while read -r tool; do
        echo "  - $tool"
    done
}

# Quote
cmd_quote() {
    load_token
    SYMBOL="$1"

    if [ -z "$SYMBOL" ]; then
        echo "用法: quote <股票代码>"
        echo "示例: quote 00700"
        exit 1
    fi

    # Add suffix if needed
    if [[ ! "$SYMBOL" =~ \. ]] && [ ${#SYMBOL} -eq 5 ]; then
        SYMBOL="${SYMBOL}.HK"
    elif [[ ! "$SYMBOL" =~ \. ]] && [ ${#SYMBOL} -eq 6 ]; then
        SYMBOL="${SYMBOL}.SZ"
    fi

    echo "📊 查询 $SYMBOL 行情..."

    RESP=$(curl -s -X POST "https://ai.szfiu.com/stock_hk_sdk/" \
        -H "Authorization: Bearer $FIU_MCP_TOKEN" \
        -H "Content-Type: application/json" \
        -d "{
            \"jsonrpc\": \"2.0\",
            \"id\": 1,
            \"method\": \"tools/call\",
            \"params\": {
                \"name\": \"post_v3_stock_quote\",
                \"arguments\": {\"fields\": [\"snapshot\"], \"symbols\": [\"$SYMBOL\"]}
            }
        }")

    DATA=$(echo "$RESP" | grep "^data:" | sed 's/^data: //')
    TEXT=$(echo "$DATA" | jq -r '.result.content[0].text' 2>/dev/null)

    if [ -n "$TEXT" ] && [ "$TEXT" != "null" ]; then
        echo "$TEXT" | jq .
    else
        echo "$DATA" | jq .
    fi
}

# Search
cmd_search() {
    load_token
    KEYWORD="$1"

    if [ -z "$KEYWORD" ]; then
        echo "用法: search <关键词>"
        echo "示例: search 腾讯"
        exit 1
    fi

    echo "🔍 搜索 $KEYWORD ..."

    RESP=$(curl -s -X POST "https://ai.szfiu.com/toolkit/" \
        -H "Content-Type: application/json" \
        -d "{
            \"jsonrpc\": \"2.0\",
            \"id\": 1,
            \"method\": \"tools/call\",
            \"params\": {
                \"name\": \"search\",
                \"arguments\": {\"key\": \"$KEYWORD\"}
            }
        }")

    DATA=$(echo "$RESP" | grep "^data:" | sed 's/^data: //')
    TEXT=$(echo "$DATA" | jq -r '.result.content[0].text' 2>/dev/null)

    if [ -n "$TEXT" ] && [ "$TEXT" != "null" ]; then
        echo "$TEXT" | jq .
    else
        echo "$DATA" | jq .
    fi
}

# Dispatch
CMD="$1"
shift

case "$CMD" in
    setup)    cmd_setup "$@" ;;
    test)     cmd_test ;;
    discover) cmd_discover "$@" ;;
    quote)    cmd_quote "$@" ;;
    search)   cmd_search "$@" ;;
    status)   cmd_status ;;
    *)
        echo "用法: $0 <command> [args]"
        echo ""
        echo "命令:"
        echo "  setup <token>    - 快速配置"
        echo "  test             - 测试连接"
        echo "  discover <市场>  - 发现可用工具"
        echo "  quote <代码>     - 查询行情"
        echo "  search <关键词>  - 搜索股票"
        echo "  status           - 显示状态"
        ;;
esac

path: scripts/orderbook.sh
content: #!/bin/bash
# FIU MCP - 买卖盘口查询
# 获取实时买卖盘口挂单数据

set -e

SYMBOL="${1:-}"

if [ -z "$SYMBOL" ]; then
    echo "用法：orderbook.sh <股票代码>"
    echo "示例：orderbook.sh 00700.HK"
    exit 1
fi

[REDACTED_SECRET]"
if [ -z "$TOKEN" ]; then
    echo "错误：请设置 FIU_MCP_TOKEN 环境变量"
    exit 1
fi

RESPONSE=$(curl -s -X POST "https://ai.szfiu.com/stock_hk_sdk/" \
    -H "Authorization: Bearer $TOKEN" \
    -H "Content-Type: application/json" \
    -H "Accept: application/json, text/event-stream" \
    -d "{
        \"jsonrpc\": \"2.0\",
        \"id\": 1,
        \"method\": \"tools/call\",
        \"params\": {
            \"name\": \"post_v3_order_latest\",
            \"arguments\": {
                \"symbol\": \"$SYMBOL\"
            }
        }
    }")

DATA=$(echo "$RESPONSE" | grep "^data:" | sed 's/^data: //')
TEXT=$(echo "$DATA" | jq -r '.result.content[0].text' 2>/dev/null)

if [ -n "$TEXT" ]; then
    echo "$TEXT" | jq .
else
    echo "$DATA" | jq .
fi


path: scripts/search.sh
content: #!/bin/bash
# FIU MCP - 证券代码检索
# 检索证券代码服务

set -e

KEYWORD="${1:-}"

if [ -z "$KEYWORD" ]; then
    echo "用法：search.sh <关键词>"
    echo "示例：search.sh 腾讯"
    echo "       search.sh AAPL"
    exit 1
fi

[REDACTED_SECRET]"
if [ -z "$TOKEN" ]; then
    echo "错误：请设置 FIU_MCP_TOKEN 环境变量"
    exit 1
fi

# 使用港股码表查询
RESPONSE=$(curl -s -X POST "https://ai.szfiu.com/stock_hk_sdk/" \
    -H "Authorization: Bearer $TOKEN" \
    -H "Content-Type: application/json" \
    -H "Accept: application/json, text/event-stream" \
    -d "{
        \"jsonrpc\": \"2.0\",
        \"id\": 1,
        \"method\": \"tools/call\",
        \"params\": {
            \"name\": \"post_v3_stock_list\",
            \"arguments\": {
                \"keyword\": \"$KEYWORD\",
                \"market\": \"MAIN\",
                \"type\": \"EQTY\",
                \"typeMode\": 1
            }
        }
    }")

DATA=$(echo "$RESPONSE" | grep "^data:" | sed 's/^data: //')
TEXT=$(echo "$DATA" | jq -r '.result.content[0].text' 2>/dev/null)

if [ -n "$TEXT" ]; then
    echo "$TEXT" | jq .
else
    echo "$DATA" | jq .
fi


path: scripts/kline.sh
content: #!/bin/bash
# FIU MCP - K 线数据查询
# 获取日 K、周 K、分钟 K 等历史和实时 K 线

set -e

SYMBOL="${1:-}"
TYPE="${2:-0}"      # 0=日 K, 1=周 K, 2=月 K, 3=季 K, 4=年 K, 5=1 分，6=5 分，7=15 分，8=30 分，9=60 分
CANDLE_MODE="${3:-0}"  # 0=不复权，1=前复权，2=后复权
COUNT="${4:-100}"
TIME_MODE="${5:-0}"    # 0=实时，1=延时

if [ -z "$SYMBOL" ]; then
    echo "用法：kline.sh <股票代码> [K 线类型] [复权模式] [数量] [时间模式]"
    echo "K 线类型：0=日 K, 1=周 K, 2=月 K, 3=季 K, 4=年 K, 5=1 分，6=5 分，7=15 分，8=30 分，9=60 分"
    echo "复权模式：0=不复权，1=前复权，2=后复权"
    echo "示例：kline.sh 00700.HK 0 0 100 0"
    exit 1
fi

# 获取当前日期
DATE=$(date +%Y-%m-%d)
if [ "$TYPE" -ge 5 ]; then
    DATE=$(date +"%Y-%m-%d %H:%M:%S")
fi

[REDACTED_SECRET]"
if [ -z "$TOKEN" ]; then
    echo "错误：请设置 FIU_MCP_TOKEN 环境变量"
    exit 1
fi

# 计算页码
PAGE_SIZE=100
PAGE_NUM=$(( (COUNT + PAGE_SIZE - 1) / PAGE_SIZE ))

RESPONSE=$(curl -s -X POST "https://ai.szfiu.com/stock_hk_sdk/" \
    -H "Authorization: Bearer $TOKEN" \
    -H "Content-Type: application/json" \
    -H "Accept: application/json, text/event-stream" \
    -d "{
        \"jsonrpc\": \"2.0\",
        \"id\": 1,
        \"method\": \"tools/call\",
        \"params\": {
            \"name\": \"post_v3_chart_kline_list\",
            \"arguments\": {
                \"candleMode\": $CANDLE_MODE,
                \"timeMode\": $TIME_MODE,
                \"type\": $TYPE,
                \"date\": \"$DATE\",
                \"symbol\": \"$SYMBOL\",
                \"pageNum\": 1,
                \"pageSize\": $COUNT
            }
        }
    }")

DATA=$(echo "$RESPONSE" | grep "^data:" | sed 's/^data: //')
TEXT=$(echo "$DATA" | jq -r '.result.content[0].text' 2>/dev/null)

if [ -n "$TEXT" ]; then
    echo "$TEXT" | jq .
else
    echo "$DATA" | jq .
fi


path: scripts/market_status.sh
content: #!/bin/bash
# FIU MCP - 市场状态查询
# 查询各市场开盘/休市状态

set -e

MARKET="${1:-ALL}"  # ALL/HK/US/CN

[REDACTED_SECRET]"
if [ -z "$TOKEN" ]; then
    echo "错误：请设置 FIU_MCP_TOKEN 环境变量"
    exit 1
fi

curl -s -X POST "https://ai.szfiu.com/toolkit/" \
    -H "Authorization: Bearer $TOKEN" \
    -H "Content-Type: application/json" \
    -d "{
        \"tool\": \"market_status\",
        \"params\": {
            \"market\": \"$MARKET\"
        }
    }" | jq .


path: scripts/capital.sh
content: #!/bin/bash
# FIU MCP - 资金流向查询
# 获取个股资金流入流出及大单、中单、小单分布

set -e

SYMBOL="${1:-}"

if [ -z "$SYMBOL" ]; then
    echo "用法：capital.sh <股票代码>"
    echo "示例：capital.sh 00700.HK"
    exit 1
fi

[REDACTED_SECRET]"
if [ -z "$TOKEN" ]; then
    echo "错误：请设置 FIU_MCP_TOKEN 环境变量"
    exit 1
fi

RESPONSE=$(curl -s -X POST "https://ai.szfiu.com/stock_hk_sdk/" \
    -H "Authorization: Bearer $TOKEN" \
    -H "Content-Type: application/json" \
    -H "Accept: application/json, text/event-stream" \
    -d "{
        \"jsonrpc\": \"2.0\",
        \"id\": 1,
        \"method\": \"tools/call\",
        \"params\": {
            \"name\": \"post_v3_capital_flow\",
            \"arguments\": {
                \"symbol\": \"$SYMBOL\"
            }
        }
    }")

DATA=$(echo "$RESPONSE" | grep "^data:" | sed 's/^data: //')
TEXT=$(echo "$DATA" | jq -r '.result.content[0].text' 2>/dev/null)

if [ -n "$TEXT" ]; then
    echo "$TEXT" | jq .
else
    echo "$DATA" | jq .
fi


path: scripts/cash.sh
content: #!/bin/bash
# FIU MCP - 资金查询
# 查询账户可用资金

set -e

ENV="${1:-SIMULATE}"

[REDACTED_SECRET]"
if [ -z "$TOKEN" ]; then
    echo "错误：请设置 FIU_MCP_TOKEN 环境变量"
    exit 1
fi

curl -s -X POST "https://ai.szfiu.com/stock_hk_sdk/" \
    -H "Authorization: Bearer $TOKEN" \
    -H "Content-Type: application/json" \
    -d "{
        \"tool\": \"cash\",
        \"params\": {
            \"environment\": \"$ENV\"
        }
    }" | jq .


path: scripts/trade.sh
content: #!/bin/bash
# FIU MCP - 交易下单
# 证券/期货下单（默认模拟环境）
# Uses jq for safe JSON construction to prevent injection

set -e

ACTION="${1:-}"  # buy/sell
SYMBOL="${2:-}"
QTY="${3:-}"
PRICE="${4:-}"
ENV="${5:-SIMULATE}"  # SIMULATE/REAL

if [ -z "$ACTION" ] || [ -z "$SYMBOL" ] || [ -z "$QTY" ]; then
    echo "用法：trade.sh <buy|sell> <股票代码> <数量> [价格] [环境 SIMULATE|REAL]"
    echo "示例：trade.sh buy 00700.HK 100 350.5 SIMULATE"
    exit 1
fi

# Validate inputs to prevent injection
if [[ ! "$ACTION" =~ ^(buy|sell)$ ]]; then
    echo "错误: action 必须是 buy 或 sell"
    exit 1
fi

if [[ ! "$QTY" =~ ^[0-9]+$ ]]; then
    echo "错误: qty 必须是数字"
    exit 1
fi

if [ -n "$PRICE" ] && [[ ! "$PRICE" =~ ^[0-9]+\.?[0-9]*$ ]]; then
    echo "错误: price 必须是数字"
    exit 1
fi

if [[ ! "$ENV" =~ ^(SIMULATE|REAL)$ ]]; then
    echo "错误: environment 必须是 SIMULATE 或 REAL"
    exit 1
fi

# 实盘交易需要二次确认
if [ "$ENV" = "REAL" ]; then
    echo "⚠️  警告：您正在使用 REAL 实盘环境！"
    read -p "确认继续？(yes/no): " confirm
    if [ "$confirm" != "yes" ]; then
        echo "已取消"
        exit 0
    fi
fi

[REDACTED_SECRET]"
if [ -z "$TOKEN" ]; then
    echo "错误：请设置 FIU_MCP_TOKEN 环境变量"
    exit 1
fi

# Build order type
ORDER_TYPE="NORMAL"
if [ -z "$PRICE" ]; then
    ORDER_TYPE="MARKET"
    PRICE="0"
fi

# Use jq to safely construct JSON payload
JSON_payload=$(jq -n \
    --arg tool "place_order" \
    --arg symbol "$SYMBOL" \
    --arg action "$ACTION" \
    --argjson qty "$QTY" \
    --argjson price "$PRICE" \
    --arg order_type "$ORDER_TYPE" \
    --arg environment "$ENV" \
    '{
        tool: $tool,
        params: {
            symbol: $symbol,
            action: $action,
            qty: $qty,
            price: $price,
            order_type: $order_type,
            environment: $environment
        }
    }')

curl -s -X POST "https://ai.szfiu.com/stock_hk_sdk/" \
    -H "Authorization: Bearer $TOKEN" \
    -H "Content-Type: application/json" \
    -d "$JSON_payload" | jq .

path: scripts/mcp_router.sh
content: #!/bin/bash
# FIU MCP Router - 通用 MCP 接口调用工具
# 根据参数调用任意 FIU MCP Server API

set -e

# 颜色输出
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color

# 用法说明
usage() {
    cat << EOF
FIU MCP Router - 通用 MCP 接口调用工具

用法:
  $0 <市场> <tool_name> [参数...]
  $0 --list-tools <市场>       # 列出该市场所有可用工具

市场选项:
  hk_f10   - 港股 F10 数据
  us_f10   - 美股 F10 数据
  cn_f10   - A 股 F10 数据
  hk_sdk   - 港股 SDK 数据
  us_sdk   - 美股 SDK 数据
  cn_sdk   - A 股 SDK 数据
  toolkit  - 代码检索服务

参数格式: key=value
  例如: symbol=00700.HK fields=snapshot,quote

示例:
  $0 hk_sdk post_v3_stock_quote fields=snapshot
  $0 hk_sdk post_v3_chart_kline_list symbol=00700.HK type=0
  $0 hk_f10 financials symbol=00700.HK
  $0 toolkit search keyword=腾讯
  $0 --list-tools cn_sdk
EOF
    exit 1
}

# MCP Server 端点映射
declare -A ENDPOINTS=(
    ["hk_f10"]="https://ai.szfiu.com/stock_hk_f10/"
    ["us_f10"]="https://ai.szfiu.com/stock_us_f10/"
    ["cn_f10"]="https://ai.szfiu.com/stock_cn_f10/"
    ["hk_sdk"]="https://ai.szfiu.com/stock_hk_sdk/"
    ["us_sdk"]="https://ai.szfiu.com/stock_us_sdk/"
    ["cn_sdk"]="https://ai.szfiu.com/stock_cn_sdk/"
    ["toolkit"]="https://ai.szfiu.com/toolkit/"
)

# 检查参数
if [ $# -lt 2 ]; then
    usage
fi

MARKET="$1"
TOOL_NAME="$2"

# 支持 --list-tools 列出所有可用工具
if [ "$MARKET" == "--list-tools" ] || [ "$MARKET" == "-l" ]; then
    MARKET="$TOOL_NAME"
    ENDPOINT="${ENDPOINTS[$MARKET]:-}"
    if [ -z "$ENDPOINT" ]; then
        echo "错误: 未知市场 '$MARKET'"
        usage
    fi
    [REDACTED_SECRET]"
    if [ "$MARKET" != "toolkit" ] && [ -z "$TOKEN" ]; then
        echo "错误: 请设置 FIU_MCP_TOKEN 环境变量"
        exit 1
    fi
    RESPONSE=$(curl -s -X POST "$ENDPOINT" \
        $([ "$MARKET" != "toolkit" ] && echo "-H \"Authorization: Bearer $TOKEN\"") \
        -H "Content-Type: application/json" \
        -H "Accept: application/json, text/event-stream" \
        -d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}')
    DATA=$(echo "$RESPONSE" | grep "^data:" | sed 's/^data: //')
    echo "$DATA" | jq '.result.tools[] | {name: .name, description: .description}' 2>/dev/null || echo "$DATA"
    exit 0
fi

shift 2

# 解析参数
ARGS_JSON="{}"
while [ $# -gt 0 ]; do
    KEY=$(echo "$1" | cut -d= -f1)
    VALUE=$(echo "$1" | cut -d= -f2-)
    # 尝试解析 JSON 数组格式 [a,b,c]
    if [[ "$VALUE" == \[*\] ]]; then
        ARGS_JSON=$(echo "$ARGS_JSON" | jq --arg k "$KEY" --argjson v "$VALUE" '. + {($k): $v}')
    else
        ARGS_JSON=$(echo "$ARGS_JSON" | jq --arg k "$KEY" --arg v "$VALUE" '. + {($k): $v}')
    fi
    shift
done

# 验证市场
if [ -z "${ENDPOINTS[$MARKET]}" ]; then
    echo -e "${RED}错误: 未知市场 '$MARKET'${NC}"
    usage
fi

ENDPOINT="${ENDPOINTS[$MARKET]}"

# 获取 Token (toolkit 不需要认证)
[REDACTED_SECRET]"
if [ "$MARKET" != "toolkit" ] && [ -z "$TOKEN" ]; then
    echo -e "${RED}错误: 请设置 FIU_MCP_TOKEN 环境变量${NC}"
    exit 1
fi

# 构建请求
if [ "$MARKET" == "toolkit" ]; then
    # toolkit 不需要 Authorization header
    REQUEST_JSON=$(jq -n \
        --jsonrpc "2.0" \
        --id 1 \
        --method "tools/call" \
        --name "$TOOL_NAME" \
        --arguments "$ARGS_JSON" \
        '{
            "jsonrpc": .jsonrpc,
            "id": .id,
            "method": .method,
            "params": {
                "name": .name,
                "arguments": .arguments
            }
        }')
else
    REQUEST_JSON=$(jq -n \
        --jsonrpc "2.0" \
        --id 1 \
        --method "tools/call" \
        --name "$TOOL_NAME" \
        --arguments "$ARGS_JSON" \
        '{
            "jsonrpc": .jsonrpc,
            "id": .id,
            "method": .method,
            "params": {
                "name": .name,
                "arguments": .arguments
            }
        }')
fi

# 调用 API
if [ "$MARKET" == "toolkit" ]; then
    RESPONSE=$(curl -s -X POST "$ENDPOINT" \
        -H "Content-Type: application/json" \
        -H "Accept: application/json, text/event-stream" \
        -d "$REQUEST_JSON")
else
    RESPONSE=$(curl -s -X POST "$ENDPOINT" \
        -H "Authorization: Bearer $TOKEN" \
        -H "Content-Type: application/json" \
        -H "Accept: application/json, text/event-stream" \
        -d "$REQUEST_JSON")
fi

# 解析响应
if echo "$RESPONSE" | grep -q "^data:"; then
    # SSE 响应格式
    DATA=$(echo "$RESPONSE" | grep "^data:" | sed 's/^data: //')
    TEXT=$(echo "$DATA" | jq -r '.result.content[0].text' 2>/dev/null)

    if [ -n "$TEXT" ] && [ "$TEXT" != "null" ]; then
        echo "$TEXT" | jq . 2>/dev/null || echo "$TEXT"
    else
        echo "$DATA" | jq . 2>/dev/null || echo "$DATA"
    fi
else
    # 普通 JSON 响应
    echo "$RESPONSE" | jq .
fi

path: scripts/quote.sh
content: #!/bin/bash
# FIU MCP - 市场快照查询
# 获取股票最新报价、涨跌幅、成交量等

set -e

SYMBOL="${1:-}"
MARKET="${2:-HK}"
TIME_MODE="${3:-0}"  # 0=实时，1=延时

if [ -z "$SYMBOL" ]; then
    echo "用法：quote.sh <股票代码> [市场 HK|US|CN] [时间模式 0|1]"
    echo "示例：quote.sh 00700.HK HK 0"
    exit 1
fi

# 根据市场选择端点和方法名
case "$MARKET" in
    HK)
        ENDPOINT="https://ai.szfiu.com/stock_hk_sdk/"
        METHOD="post_v3_stock_quote"
        ;;
    US)
        ENDPOINT="https://ai.szfiu.com/stock_us_sdk/"
        METHOD="post_v1_stock_quote"
        ;;
    CN)
        ENDPOINT="https://ai.szfiu.com/stock_cn_sdk/"
        METHOD="post_v1_stock_quote"
        ;;
    *)
        echo "错误：市场参数必须是 HK、US 或 CN"
        exit 1
        ;;
esac

# 获取 Token
[REDACTED_SECRET]"
if [ -z "$TOKEN" ]; then
    echo "错误：请设置 FIU_MCP_TOKEN 环境变量"
    exit 1
fi

# 调用 API (JSON-RPC 2.0 格式)
# 美股和 A 股需要 sessionId 参数，港股不需要
case "$MARKET" in
    US|CN)
        RESPONSE=$(curl -s -X POST "$ENDPOINT" \
            -H "Authorization: Bearer $TOKEN" \
            -H "Content-Type: application/json" \
            -H "Accept: application/json, text/event-stream" \
            -d "{
                \"jsonrpc\": \"2.0\",
                \"id\": 1,
                \"method\": \"tools/call\",
                \"params\": {
                    \"name\": \"$METHOD\",
                    \"arguments\": {
                        \"fields\": [\"snapshot\"],
                        \"symbols\": [\"$SYMBOL\"],
                        \"timeMode\": $TIME_MODE,
                        \"sessionId\": \"1\"
                    }
                }
            }")
        ;;
    HK)
        RESPONSE=$(curl -s -X POST "$ENDPOINT" \
            -H "Authorization: Bearer $TOKEN" \
            -H "Content-Type: application/json" \
            -H "Accept: application/json, text/event-stream" \
            -d "{
                \"jsonrpc\": \"2.0\",
                \"id\": 1,
                \"method\": \"tools/call\",
                \"params\": {
                    \"name\": \"$METHOD\",
                    \"arguments\": {
                        \"fields\": [\"snapshot\"],
                        \"symbols\": [\"$SYMBOL\"],
                        \"timeMode\": $TIME_MODE
                    }
                }
            }")
        ;;
esac

# 解析 SSE 响应
DATA=$(echo "$RESPONSE" | grep "^data:" | sed 's/^data: //')
TEXT=$(echo "$DATA" | jq -r '.result.content[0].text' 2>/dev/null)

if [ -n "$TEXT" ]; then
    echo "$TEXT" | jq .
else
    echo "$DATA" | jq .
fi


path: scripts/positions.sh
content: #!/bin/bash
# FIU MCP - 持仓查询
# 查询账户持仓

set -e

ENV="${1:-SIMULATE}"

[REDACTED_SECRET]"
if [ -z "$TOKEN" ]; then
    echo "错误：请设置 FIU_MCP_TOKEN 环境变量"
    exit 1
fi

curl -s -X POST "https://ai.szfiu.com/stock_hk_sdk/" \
    -H "Authorization: Bearer $TOKEN" \
    -H "Content-Type: application/json" \
    -d "{
        \"tool\": \"positions\",
        \"params\": {
            \"environment\": \"$ENV\"
        }
    }" | jq .


path: docs/MCP_TOOLS.md
content: # FIU MCP Tools Reference

## Known Tool Mappings

Tool names may differ between markets. Below are the confirmed tool names.

### F10 Markets (hk_f10, us_f10, cn_f10)

| Tool | HK | US | CN |
|------|----|----|----|
| company_info | `companyInfo` | `companyInfo` | `companyInfo` |
| financials | `financials` | `financials` | `financials` |
| dividend | `dividend` | `dividend` | `dividend` |
| split_history | `splitHistory` | `splitHistory` | `splitHistory` |
| holders | `holders` | `holders` | `holders` |
| news | `news` | `news` | `news` |
| industry | `industry` | `industry` | `industry` |
| prospectus | - | - | `prospectus` |
| public_listing | - | - | `publicListing` |

### SDK Markets (hk_sdk, us_sdk, cn_sdk)

| Tool | HK | US | CN |
|------|----|----|----|
| Quote | `post_v3_stock_quote` | `post_v1_stock_quote` | `post_v1_stock_quote` |
| K-Line | `post_v3_chart_kline_list` | *check API* | *check API* |
| Order Book | `post_v3_order_book` | *check API* | *check API* |
| Tick | `post_v3_tick_trade` | *check API* | *check API* |
| Intraday | `post_v3_intraday` | *check API* | *check API* |
| Capital | `post_v3_capital_flow` | *check API* | *check API* |
| Capital Dist | `post_v3_capital_distribution` | *check API* | *check API* |
| Sector List | `post_v3_sector_list` | *check API* | *check API* |
| Sector Stocks | `post_v3_sector_stocks` | *check API* | *check API* |
| Stock Sector | `post_v3_stock_sector` | *check API* | *check API* |
| Stock Filter | `post_v3_stock_filter` | *check API* | *check API* |
| Ranking | `post_v3_market_ranking` | *check API* | *check API* |
| Trade | `trade` | `trade` | `trade` |
| Cancel | `cancel_order` | `cancel_order` | `cancel_order` |
| Modify | `modify_order` | `modify_order` | `modify_order` |
| Query Cash | `query_cash` | `query_cash` | `query_cash` |
| Query Pos | `query_positions` | `query_positions` | `query_positions` |
| Query Orders | `query_orders` | `query_orders` | `query_orders` |
| Futures | `futures_trade` | `futures_trade` | `futures_trade` |

### Toolkit (toolkit)

| Tool | Description |
|------|-------------|
| `search` | Securities code search |
| `stock_info` | Stock basic info |

## Discover Available Tools

Use this command to list all available tools for a market:

```bash
curl -s -X POST https://ai.szfiu.com/stock_hk_sdk/ \
  -H "Authorization: Bearer $FIU_MCP_TOKEN" \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}' | grep "^data:" | sed 's/^data: //' | jq
```

Replace the endpoint URL for other markets:
- `https://ai.szfiu.com/stock_us_sdk/`
- `https://ai.szfiu.com/stock_cn_sdk/`
- `https://ai.szfiu.com/stock_hk_f10/`
- `https://ai.szfiu.com/stock_us_f10/`
- `https://ai.szfiu.com/stock_cn_f10/`
- `https://ai.szfiu.com/toolkit/`

## Usage Examples

### Quote
```bash
mcp_router.sh hk_sdk post_v3_stock_quote fields=snapshot
mcp_router.sh us_sdk post_v1_stock_quote symbol=AAPL fields=snapshot sessionId=1
mcp_router.sh cn_sdk post_v1_stock_quote symbol=600519 fields=snapshot sessionId=1
```

### K-Line
```bash
mcp_router.sh hk_sdk post_v3_chart_kline_list symbol=00700.HK type=0 count=100
# For CN/US, discover the correct tool name first
```

### Trade
```bash
mcp_router.sh hk_sdk trade action=buy symbol=00700.HK qty=100 price=380
```

### Search
```bash
mcp_router.sh toolkit search keyword=腾讯
```


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