aicoin
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseAiCoin
AiCoin
Crypto data & trading toolkit powered by AiCoin Open API.
基于AiCoin Open API构建的加密货币数据与交易工具包。
Setup Checklist
设置清单
Scripts auto-load files from these locations (earlier paths take priority):
.env- Current working directory ()
.env ~/.openclaw/workspace/.env~/.openclaw/.env
Before asking the user for ANY credentials, first check if already exists:
.envbash
grep -c "AICOIN_ACCESS_KEY_ID" ~/.openclaw/workspace/.env 2>/dev/null || echo "0"- If output is or more →
1has AiCoin key configured. Skip setup, just run scripts directly..env - If output is → No AiCoin key, but the built-in free key works automatically. Just run scripts.
0
Only ask setup questions when the user explicitly requests features that need configuration:
- Exchange trading (Binance, OKX, etc.) → needs exchange API keys + for ccxt
cd <skill-dir>/aicoin && npm install - Freqtrade bot → run (auto-configures everything, needs Python 3 + exchange keys in .env)
ft-deploy.mjs deploy - Proxy access → needs
PROXY_URL
Do NOT block the user from running commands. The skill works out of the box with the built-in free key.
脚本会自动从以下位置加载文件(路径越靠前优先级越高):
.env- 当前工作目录()
.env ~/.openclaw/workspace/.env~/.openclaw/.env
在向用户索要任何凭证之前,请先检查文件是否已存在:
.envbash
grep -c "AICOIN_ACCESS_KEY_ID" ~/.openclaw/workspace/.env 2>/dev/null || echo "0"- 如果输出为或更大数值 →
1中已配置AiCoin密钥,跳过设置步骤,直接运行脚本即可。.env - 如果输出为→ 无AiCoin密钥,但内置免费密钥可自动生效,直接运行脚本即可。
0
仅当用户明确请求需要配置的功能时,才询问设置相关问题:
- 交易所交易(Binance、OKX等)→ 需要交易所API密钥 + 执行安装ccxt
cd <skill-dir>/aicoin && npm install - Freqtrade机器人 → 运行(自动完成所有配置,需要Python 3 + .env中的交易所密钥)
ft-deploy.mjs deploy - 代理访问 → 需要配置
PROXY_URL
请勿阻止用户运行命令。本Skill使用内置免费密钥即可开箱即用。
How to Configure Environment Variables
如何配置环境变量
The file location is . When adding new variables:
.env~/.openclaw/workspace/.env-
Check ifalready exists:
.envbashtest -f ~/.openclaw/workspace/.env && echo "EXISTS" || echo "NOT_FOUND" -
If EXISTS → append (do NOT overwrite):bash
echo 'PROXY_URL=socks5://127.0.0.1:7890' >> ~/.openclaw/workspace/.env -
If NOT_FOUND → create:bash
echo 'PROXY_URL=socks5://127.0.0.1:7890' > ~/.openclaw/workspace/.env -
If a key already exists and needs updating, replace the specific line:bash
sed -i '' 's|^PROXY_URL=.*|PROXY_URL=socks5://127.0.0.1:7890|' ~/.openclaw/workspace/.env
NEVER overwrite the entire file — it may contain other credentials the user has already configured.
.env.env~/.openclaw/workspace/.env-
检查是否已存在:
.envbashtest -f ~/.openclaw/workspace/.env && echo "EXISTS" || echo "NOT_FOUND" -
如果已存在 → 追加内容(请勿覆盖原有内容):bash
echo 'PROXY_URL=socks5://127.0.0.1:7890' >> ~/.openclaw/workspace/.env -
如果不存在 → 创建文件:bash
echo 'PROXY_URL=socks5://127.0.0.1:7890' > ~/.openclaw/workspace/.env -
如果密钥已存在且需要更新,替换指定行:bash
sed -i '' 's|^PROXY_URL=.*|PROXY_URL=socks5://127.0.0.1:7890|' ~/.openclaw/workspace/.env
绝对不要覆盖整个文件 —— 其中可能包含用户已配置的其他凭证。
.envSECURITY: How to Run Scripts
安全须知:如何运行脚本
Scripts auto-load — NEVER pass credentials inline. Just run:
.envbash
node scripts/coin.mjs coin_ticker '{"coin_list":"bitcoin"}'NEVER do this — it exposes secrets in conversation logs:
bash
undefined脚本会自动加载中的密钥 —— 绝对不要在命令行中直接传入凭证,只需运行:
.envbash
node scripts/coin.mjs coin_ticker '{"coin_list":"bitcoin"}'绝对不要这样做 —— 会在对话日志中暴露机密信息:
bash
undefinedWRONG! DO NOT DO THIS!
错误示例!请勿执行!
AICOIN_ACCESS_KEY_ID=xxx node scripts/coin.mjs coin_ticker '{"coin_list":"bitcoin"}'
If a script fails due to missing env vars, guide the user to update their `.env` file instead of injecting variables into the command.AICOIN_ACCESS_KEY_ID=xxx node scripts/coin.mjs coin_ticker '{"coin_list":"bitcoin"}'
如果脚本因缺少环境变量而失败,请引导用户更新`.env`文件,而非在命令中注入变量。Environment Variables
环境变量说明
Create a file in the OpenClaw workspace directory (recommended):
.envbash
undefined在OpenClaw工作目录中创建文件(推荐):
.envbash
undefinedAiCoin API (optional — built-in free key works with IP rate limits)
AiCoin API(可选 —— 内置免费密钥可正常使用,但有IP调用频率限制)
Mapping: AiCoin website "API Key" → AICOIN_ACCESS_KEY_ID
对应关系:AiCoin网站的「API Key」 → AICOIN_ACCESS_KEY_ID
AiCoin website "API Secret" → AICOIN_ACCESS_SECRET
AiCoin网站的「API Secret」 → AICOIN_ACCESS_SECRET
AICOIN_ACCESS_KEY_ID=your-api-key
AICOIN_ACCESS_SECRET=your-api-secret
AICOIN_ACCESS_KEY_ID=your-api-key
AICOIN_ACCESS_SECRET=your-api-secret
Exchange trading — only if needed (requires: npm install -g ccxt)
交易所交易 —— 仅在需要时配置(需先执行:npm install -g ccxt)
BINANCE_API_KEY=xxx
BINANCE_API_SECRET=xxx
BINANCE_API_KEY=xxx
BINANCE_API_SECRET=xxx
Supported: BINANCE, OKX, BYBIT, BITGET, GATE, HTX, KUCOIN, MEXC, COINBASE
支持的交易所:BINANCE、OKX、BYBIT、BITGET、GATE、HTX、KUCOIN、MEXC、COINBASE
For OKX also set OKX_PASSWORD=xxx
若使用OKX,还需设置OKX_PASSWORD=xxx
Proxy for exchange access — only if needed
交易所访问代理 —— 仅在需要时配置
Supports http, https, socks5, socks4
支持http、https、socks5、socks4
PROXY_URL=socks5://127.0.0.1:7890
PROXY_URL=socks5://127.0.0.1:7890
Or standard env vars: HTTPS_PROXY=http://127.0.0.1:7890
或使用标准环境变量:HTTPS_PROXY=http://127.0.0.1:7890
Freqtrade — auto-configured by ft-deploy.mjs, no manual setup needed
Freqtrade —— 由ft-deploy.mjs自动配置,无需手动设置
FREQTRADE_URL=http://localhost:8080
FREQTRADE_URL=http://localhost:8080
FREQTRADE_USERNAME=freqtrader
FREQTRADE_USERNAME=freqtrader
FREQTRADE_PASSWORD=auto-generated
FREQTRADE_PASSWORD=auto-generated
**IMPORTANT — AiCoin API Key Configuration:**
1. The user may provide two values without labels (just two strings copied from the AiCoin website). **Do NOT guess which is which.** Ask the user to confirm: "哪个是 API Key,哪个是 API Secret?" Or look for the labels in the user's message.
2. **After writing keys to `.env`, ALWAYS verify by running a test call:**
```bash
node scripts/coin.mjs coin_ticker '{"coin_list":"bitcoin"}'- If the test returns error code (signature verification failed), the keys are swapped. Fix by swapping them:
1001Then re-run the test to confirm it works.bash# Read current values, swap them OLD_KEY=$(grep '^AICOIN_ACCESS_KEY_ID=' ~/.openclaw/workspace/.env | cut -d= -f2) OLD_SECRET=$(grep '^AICOIN_ACCESS_SECRET=' ~/.openclaw/workspace/.env | cut -d= -f2) sed -i '' "s|^AICOIN_ACCESS_KEY_ID=.*|AICOIN_ACCESS_KEY_ID=${OLD_SECRET}|" ~/.openclaw/workspace/.env sed -i '' "s|^AICOIN_ACCESS_SECRET=.*|AICOIN_ACCESS_SECRET=${OLD_KEY}|" ~/.openclaw/workspace/.env
Or configure in :
~/.openclaw/openclaw.jsonjson
{
"skills": {
"entries": {
"aicoin": {
"enabled": true,
"apiKey": "your-aicoin-access-key-id",
"env": {
"AICOIN_ACCESS_SECRET": "your-secret"
}
}
}
}
}
**重要提示 —— AiCoin API密钥配置注意事项:**
1. 用户可能会提供两个未标注的值(直接从AiCoin网站复制的两个字符串)。**请勿猜测哪个是哪个**,请让用户确认:“哪个是 API Key,哪个是 API Secret?”或者从用户的消息中查找标注。
2. **将密钥写入`.env`后,必须通过测试调用验证配置是否正确:**
```bash
node scripts/coin.mjs coin_ticker '{"coin_list":"bitcoin"}'- 如果测试返回错误码(签名验证失败),说明密钥顺序颠倒,请交换两者:
1001然后重新运行测试以确认配置生效。bash# 读取当前值并交换 OLD_KEY=$(grep '^AICOIN_ACCESS_KEY_ID=' ~/.openclaw/workspace/.env | cut -d= -f2) OLD_SECRET=$(grep '^AICOIN_ACCESS_SECRET=' ~/.openclaw/workspace/.env | cut -d= -f2) sed -i '' "s|^AICOIN_ACCESS_KEY_ID=.*|AICOIN_ACCESS_KEY_ID=${OLD_SECRET}|" ~/.openclaw/workspace/.env sed -i '' "s|^AICOIN_ACCESS_SECRET=.*|AICOIN_ACCESS_SECRET=${OLD_KEY}|" ~/.openclaw/workspace/.env
也可在中配置:
~/.openclaw/openclaw.jsonjson
{
"skills": {
"entries": {
"aicoin": {
"enabled": true,
"apiKey": "your-aicoin-access-key-id",
"env": {
"AICOIN_ACCESS_SECRET": "your-secret"
}
}
}
}
}Prerequisites
前置依赖
- Node.js — required for all scripts
- ccxt — required only for exchange trading:
cd <skill-dir>/aicoin && npm install
- Node.js —— 所有脚本的运行依赖
- ccxt —— 仅交易所交易功能需要:执行安装
cd <skill-dir>/aicoin && npm install
Scripts
脚本说明
All scripts follow:
node scripts/<name>.mjs <action> [json-params]所有脚本遵循格式:
node scripts/<name>.mjs <action> [json-params]scripts/coin.mjs — Coin Data
scripts/coin.mjs — 币种数据
| Action | Description | Params |
|---|---|---|
| List all coins | None |
| Real-time prices | |
| Coin profile | |
| AI analysis & prediction | |
| Funding rate | |
| Liquidation heatmap | |
| Liquidation history | |
| Estimated liquidation | |
| Open interest | |
| Historical depth | |
| Large order depth (>$10k) | |
| Trade data | |
| 操作 | 描述 | 参数 |
|---|---|---|
| 获取所有币种列表 | 无 |
| 获取实时价格 | |
| 获取币种详情 | |
| AI分析与预测 | |
| 获取资金费率 | |
| 获取爆仓热力图 | |
| 获取爆仓历史数据 | |
| 获取预估爆仓数据 | |
| 获取持仓量 | |
| 获取历史盘口数据 | |
| 获取大额委托盘口(>$10k) | |
| 获取交易数据 | |
scripts/market.mjs — Market Data
scripts/market.mjs — 市场数据
Market Info
市场信息
| Action | Description | Params |
|---|---|---|
| Exchange list | None |
| Exchange tickers | |
| Trending coins | |
| Futures OI ranking | |
| 操作 | 描述 | 参数 |
|---|---|---|
| 获取支持的交易所列表 | 无 |
| 获取交易所行情 | |
| 获取热门币种 | |
| 获取期货持仓量排名 | |
K-Line
K线数据
| Action | Description | Params |
|---|---|---|
| Standard K-line | |
| Indicator K-line | |
| Indicator available pairs | |
| 操作 | 描述 | 参数 |
|---|---|---|
| 获取标准K线 | |
| 获取带指标的K线 | |
| 获取指标支持的交易对 | |
Index
指数数据
| Action | Description | Params |
|---|---|---|
| Index list | None |
| Index price | |
| Index details | |
| 操作 | 描述 | 参数 |
|---|---|---|
| 获取指数列表 | 无 |
| 获取指数价格 | |
| 获取指数详情 | |
Crypto Stocks
加密货币概念股
| Action | Description | Params |
|---|---|---|
| Stock quotes | |
| Top gainers | |
| Company details | |
| 操作 | 描述 | 参数 |
|---|---|---|
| 获取概念股行情 | |
| 获取涨幅榜 | |
| 获取公司详情 | |
Treasury (Corporate Holdings)
机构持仓
| Action | Description | Params |
|---|---|---|
| Holding entities | |
| Transaction history | |
| Accumulated holdings | |
| Latest entities | |
| Latest history | |
| Holdings overview | |
| 操作 | 描述 | 参数 |
|---|---|---|
| 获取持仓机构列表 | |
| 获取持仓交易历史 | |
| 获取累计持仓数据 | |
| 获取最新持仓机构 | |
| 获取最新持仓交易 | |
| 获取持仓概况 | |
Order Book Depth
订单簿深度
| Action | Description | Params |
|---|---|---|
| Real-time snapshot | |
| Full order book | |
| Grouped depth | |
| 操作 | 描述 | 参数 |
|---|---|---|
| 获取实时盘口快照 | |
| 获取完整订单簿 | |
| 获取分组盘口 | |
scripts/news.mjs — News & Content
scripts/news.mjs — 资讯与内容
| Action | Description | Params |
|---|---|---|
| News list | |
| News detail | |
| RSS news | |
| AiCoin flash news | |
| Industry flash news | |
| Exchange listing announcements | |
| 操作 | 描述 | 参数 |
|---|---|---|
| 获取资讯列表 | |
| 获取资讯详情 | |
| 获取RSS资讯 | |
| 获取AiCoin闪电快讯 | |
| 获取行业闪电快讯 | |
| 获取交易所上线公告 | |
scripts/twitter.mjs — Twitter/X Crypto Tweets
scripts/twitter.mjs — Twitter/X加密货币推文
| Action | Description | Params |
|---|---|---|
| Latest crypto tweets (cursor-paginated) | |
| Search tweets by keyword | |
| Search Twitter KOL/users | |
| Tweet engagement stats | |
| 操作 | 描述 | 参数 |
|---|---|---|
| 获取最新加密货币推文(游标分页) | |
| 按关键词搜索推文 | |
| 搜索Twitter KOL/用户 | |
| 获取推文互动数据 | |
scripts/newsflash.mjs — Newsflash (OpenData)
scripts/newsflash.mjs — 闪电快讯(OpenData)
| Action | Description | Params |
|---|---|---|
| Search newsflash by keyword | |
| Newsflash list with filters | |
| Newsflash full content | |
| 操作 | 描述 | 参数 |
|---|---|---|
| 按关键词搜索闪电快讯 | |
| 带筛选条件的闪电快讯列表 | |
| 获取闪电快讯完整内容 | |
scripts/features.mjs — Features & Signals
scripts/features.mjs — 特色功能与信号
Market Overview
市场概况
| Action | Description | Params |
|---|---|---|
| Market navigation | |
| Long/short ratio | None |
| Liquidation data | |
| Grayscale trust | None |
| Grayscale holdings | |
| Crypto stocks | None |
| 操作 | 描述 | 参数 |
|---|---|---|
| 获取市场导航数据 | |
| 获取多空比 | 无 |
| 获取爆仓数据 | |
| 获取灰度信托数据 | 无 |
| 获取灰度持仓数据 | |
| 获取加密货币概念股数据 | 无 |
Whale Order Tracking
鲸鱼订单追踪
| Action | Description | Params |
|---|---|---|
| Large/whale orders | |
| Aggregated large trades | |
| 操作 | 描述 | 参数 |
|---|---|---|
| 获取大额/鲸鱼订单 | |
| 获取大额成交汇总 | |
Trading Pairs
交易对
| Action | Description | Params |
|---|---|---|
| Pair ticker | |
| Pairs by exchange | |
| Pair list | |
| 操作 | 描述 | 参数 |
|---|---|---|
| 获取交易对行情 | |
| 获取交易所支持的交易对 | |
| 获取交易对列表 | |
Signals
信号
| Action | Description | Params |
|---|---|---|
| Strategy signal | |
| Signal alerts | None |
| Alert config | |
| Alert list | None |
| Anomaly signal | |
| Delete alert | |
| 操作 | 描述 | 参数 |
|---|---|---|
| 获取策略信号 | |
| 获取信号预警 | 无 |
| 获取预警配置 | |
| 获取预警列表 | 无 |
| 获取异常信号 | |
| 删除预警 | |
scripts/hl-market.mjs — Hyperliquid Market
scripts/hl-market.mjs — Hyperliquid市场数据
Tickers
行情
| Action | Description | Params |
|---|---|---|
| All tickers | None |
| Single coin ticker | |
| 操作 | 描述 | 参数 |
|---|---|---|
| 获取所有行情 | 无 |
| 获取单个币种行情 | |
Whales
鲸鱼数据
| Action | Description | Params |
|---|---|---|
| Whale positions | |
| Whale events | |
| Long/short direction | |
| Historical long ratio | |
| 操作 | 描述 | 参数 |
|---|---|---|
| 获取鲸鱼仓位 | |
| 获取鲸鱼交易事件 | |
| 获取鲸鱼多空方向 | |
| 获取历史多空比 | |
Liquidations
爆仓数据
| Action | Description | Params |
|---|---|---|
| Liquidation history | |
| Liquidation stats | None |
| Stats by coin | |
| Large liquidations | |
| 操作 | 描述 | 参数 |
|---|---|---|
| 获取爆仓历史 | |
| 获取爆仓统计数据 | 无 |
| 按币种统计爆仓数据 | |
| 获取大额爆仓数据 | |
Open Interest
持仓量
| Action | Description | Params |
|---|---|---|
| OI overview | None |
| OI ranking | |
| OI history | |
| 操作 | 描述 | 参数 |
|---|---|---|
| 获取持仓量概况 | 无 |
| 获取持仓量排名 | |
| 获取持仓量历史数据 | |
Taker
taker数据
| Action | Description | Params |
|---|---|---|
| Taker delta | |
| Taker K-lines | |
| 操作 | 描述 | 参数 |
|---|---|---|
| 获取Taker Delta | |
| 获取Taker K线 | |
scripts/hl-trader.mjs — Hyperliquid Trader
scripts/hl-trader.mjs — Hyperliquid交易者分析
Trader Analytics
交易者统计
| Action | Description | Params |
|---|---|---|
| Trader statistics | |
| Best trades | |
| Performance by coin | |
| Completed trades | |
| Batch accounts | |
| Batch statistics | |
| 操作 | 描述 | 参数 |
|---|---|---|
| 获取交易者统计数据 | |
| 获取最佳交易记录 | |
| 按币种统计交易表现 | |
| 获取已完成交易 | |
| 批量获取账户数据 | |
| 批量获取统计数据 | |
Fills
成交记录
| Action | Description | Params |
|---|---|---|
| Address fills | |
| By order ID | |
| By TWAP ID | |
| Large trades | |
| 操作 | 描述 | 参数 |
|---|---|---|
| 获取地址成交记录 | |
| 按订单ID获取成交记录 | |
| 按TWAP ID获取成交记录 | |
| 获取大额成交记录 | |
Orders
订单
| Action | Description | Params |
|---|---|---|
| Latest orders | |
| By order ID | |
| Filled orders | |
| Filled by ID | |
| Large open orders | |
| Active stats | |
| TWAP states | |
| 操作 | 描述 | 参数 |
|---|---|---|
| 获取最新订单 | |
| 按订单ID获取订单 | |
| 获取已成交订单 | |
| 按订单ID获取已成交订单 | |
| 获取大额挂单 | |
| 获取活跃订单统计 | |
| 获取TWAP订单状态 | |
Positions
仓位
| Action | Description | Params |
|---|---|---|
| Current position history | |
| Closed position history | |
| Current PnL | |
| Closed PnL | |
| Current executions | |
| Closed executions | |
| 操作 | 描述 | 参数 |
|---|---|---|
| 获取当前仓位历史 | |
| 获取已平仓历史 | |
| 获取当前盈亏 | |
| 获取已平仓盈亏 | |
| 获取当前执行记录 | |
| 获取已平仓执行记录 | |
Portfolio
投资组合
| Action | Description | Params |
|---|---|---|
| Account curve | |
| PnL curve | |
| Max drawdown | |
| Net flow | |
| 操作 | 描述 | 参数 |
|---|---|---|
| 获取账户资金曲线 | |
| 获取盈亏曲线 | |
| 获取最大回撤 | |
| 获取资金净流入 | |
Advanced
高级功能
| Action | Description | Params |
|---|---|---|
| Info API | |
| Smart money discovery | |
| Trader discovery | |
| 操作 | 描述 | 参数 |
|---|---|---|
| 获取Info API数据 | |
| 智能资金发现 | |
| 交易者发现 | |
scripts/exchange.mjs — Exchange Trading (CCXT)
scripts/exchange.mjs — 交易所交易(基于CCXT)
⚠️ MANDATORY: All exchange operations MUST go through .
exchange.mjs- NEVER write custom CCXT/Python code to interact with exchanges. Always use .
node scripts/exchange.mjs <action> '<params>' - NEVER import ccxt directly in custom scripts. The exchange.mjs wrapper handles broker attribution, proxy config, and API key management.
- automatically sets AiCoin broker tags for order attribution. Custom CCXT code will NOT have these tags, causing orders to be mis-attributed.
exchange.mjs - For automated trading workflows, use which wraps
auto-trade.mjswith risk management.exchange.mjs
Requires and exchange API keys.
npm install ccxt⚠️ 强制要求:所有交易所操作必须通过执行。
exchange.mjs- 绝对不要编写自定义CCXT/Python代码与交易所交互,必须使用格式。
node scripts/exchange.mjs <action> '<params>' - 绝对不要在自定义脚本中直接导入ccxt,封装器会处理经纪商归因、代理配置和API密钥管理。
exchange.mjs - 会自动设置AiCoin经纪商标签用于订单归因,自定义CCXT代码不会包含这些标签,会导致订单归因错误。
exchange.mjs - 对于自动化交易工作流,请使用,它基于
auto-trade.mjs封装了风险管理功能。exchange.mjs
需要先执行并配置交易所API密钥。
npm install ccxtPublic (no API key required)
公开接口(无需API密钥)
| Action | Description | Params |
|---|---|---|
| Supported exchanges | None |
| Market list | |
| Real-time ticker | |
| Order book | |
| Recent trades | |
| OHLCV candles | |
| 操作 | 描述 | 参数 |
|---|---|---|
| 获取支持的交易所列表 | 无 |
| 获取市场列表 | |
| 获取实时行情 | |
| 获取订单簿 | |
| 获取近期成交 | |
| 获取K线数据 | |
Account (API key required)
账户接口(需要API密钥)
| Action | Description | Params |
|---|---|---|
| Account balance | |
| Open positions | |
| Open orders | |
| 操作 | 描述 | 参数 |
|---|---|---|
| 获取账户余额 | |
| 获取当前持仓 | |
| 获取当前挂单 | |
Trading (API key required)
交易接口(需要API密钥)
🚨 SAFETY RULES — MANDATORY for ALL trading operations:
- NEVER execute a buy/sell/trade without explicit user confirmation. Always show the order details and ask "确认下单?" BEFORE calling .
create_order - NEVER sell or close the user's existing positions unless the user specifically asks to sell/close.
- NEVER write custom CCXT, Python, or curl code to interact with exchanges. ALL exchange operations MUST go through .
exchange.mjs
⚠️ CRITICAL — units differ between spot and futures:
amount- Spot: is in base currency (e.g.,
amount= 0.01 BTC)amount: 0.01 - Futures/Swap: is in contracts (e.g.,
amount= 1 contract). Getamount: 1fromcontractSizeto convert.markets
User intent → conversion (you MUST get this right):
amount| User says | Spot | Swap |
|---|---|---|
| "0.01 BTC" / "0.01个BTC" | | |
| "1张合约" / "1 contract" | N/A | |
| "0.01张" | N/A | |
| "100U" / "100 USDT" | | |
NEVER pass the user's number directly as without checking the unit context!
amountBefore placing any order, you MUST:
- Run to get the trading pair's
markets(minimum order size) andlimits.amount.min— do NOT guess or assume minimumscontractSize - Run to check available funds
balance - Convert user's quantity to the correct unit using the table above
- For futures/swap: calculate actual buying power = balance × leverage
- Verify: buying power ≥ order value
- Confirm with user: "You want to buy X contracts (= Y BTC ≈ Z USDT), correct?" before placing the order
Example pre-trade check for BTC/USDT perpetual on OKX:
bash
undefined🚨 安全规则 —— 所有交易操作必须遵守:
- 绝对不要在未获得用户明确确认的情况下执行买/卖/交易操作。必须先展示订单详情并询问“确认下单?”,再调用。
create_order - 绝对不要卖出或平仓用户的现有仓位,除非用户明确要求卖出/平仓。
- 绝对不要编写自定义CCXT、Python或curl代码与交易所交互,所有交易所操作必须通过执行。
exchange.mjs
⚠️ 关键注意事项 —— 参数在现货和期货中的单位不同:
amount- 现货:的单位是基础币种(例如:
amount= 0.01 BTC)amount: 0.01 - 期货/永续合约:的单位是合约张数(例如:
amount= 1张合约)。可通过amount: 1获取markets进行转换。contractSize
用户意图 → 参数转换(必须确保转换正确):
amount| 用户表述 | 现货 | 永续合约 |
|---|---|---|
| "0.01 BTC" / "0.01个BTC" | | |
| "1张合约" / "1 contract" | 不适用 | |
| "0.01张" | 不适用 | |
| "100U" / "100 USDT" | | |
绝对不要在未确认单位上下文的情况下,直接将用户提供的数字作为参数传入!
amount下单前必须执行以下步骤:
- 调用获取交易对的
markets(最小下单量)和limits.amount.min—— 不要猜测或假设最小下单量contractSize - 调用检查可用资金
balance - 根据上表将用户的数量转换为正确的单位
- 对于期货/永续合约:计算实际购买力 = 余额 × 杠杆
- 验证:购买力 ≥ 订单价值
- 与用户确认:“你要买入X张合约(= Y BTC ≈ Z USDT),对吗?”之后再下单
OKX BTC/USDT永续合约下单前检查示例:
bash
undefinedStep 1: Check minimum order size AND contract size
步骤1:检查最小下单量和合约大小
node scripts/exchange.mjs markets '{"exchange":"okx","market_type":"swap","base":"BTC"}'
node scripts/exchange.mjs markets '{"exchange":"okx","market_type":"swap","base":"BTC"}'
→ look for limits.amount.min (e.g. 1 contract) and contractSize (e.g. 0.01 BTC)
→ 查找limits.amount.min(例如1张合约)和contractSize(例如0.01 BTC)
→ This means: 1 contract = 0.01 BTC, min order = 1 contract = 0.01 BTC
→ 意味着:1张合约 = 0.01 BTC,最小下单量 = 1张合约 = 0.01 BTC
Step 2: Check balance
步骤2:检查余额
node scripts/exchange.mjs balance '{"exchange":"okx"}'
node scripts/exchange.mjs balance '{"exchange":"okx"}'
→ e.g. 7 USDT free
→ 例如:可用7 USDT
Step 3: Calculate — 7 USDT × 10x = 70 USDT ÷ $68000 ≈ 0.001 BTC ÷ 0.01 = 0.1 contracts → below min 1 contract → cannot trade
步骤3:计算 —— 7 USDT × 10倍杠杆 = 70 USDT ÷ $68000 ≈ 0.001 BTC ÷ 0.01 = 0.1张合约 → 低于最小1张合约 → 无法交易
With more capital: 100 USDT × 10x = 1000 ÷ $68000 ≈ 0.0147 BTC ÷ 0.01 = 1.47 → round to 1 contract → OK
若资金充足:100 USDT ×10倍杠杆=1000 ÷ $68000≈0.0147 BTC ÷0.01=1.47 → 取整为1张合约 → 可交易
| Action | Description | Params |
|--------|-------------|--------|
| `create_order` | Place order | Spot: `{"exchange":"okx","symbol":"BTC/USDT","type":"market","side":"buy","amount":0.001}` (amount in BTC). Swap: `{"exchange":"okx","symbol":"BTC/USDT:USDT","type":"market","side":"buy","amount":1,"market_type":"swap"}` (amount in contracts) |
| `cancel_order` | Cancel order | `{"exchange":"okx","symbol":"BTC/USDT","order_id":"xxx"}` |
| `set_leverage` | Set leverage | `{"exchange":"okx","symbol":"BTC/USDT:USDT","leverage":10,"market_type":"swap"}` |
| `set_margin_mode` | Margin mode | `{"exchange":"okx","symbol":"BTC/USDT:USDT","margin_mode":"cross","market_type":"swap"}` |
| `transfer` | Transfer funds | `{"exchange":"binance","code":"USDT","amount":100,"from_account":"spot","to_account":"future"}` |
**Notes on `transfer`:**
- **OKX unified account (重要)**: OKX uses a **unified trading account** — spot and derivatives share the SAME balance. **Do NOT ask the user to transfer funds between accounts.** If transfer returns error 58123, tell the user: "你的 OKX 是统一账户,现货和合约共用同一个余额,不需要划转。" Do NOT suggest manual transfer in the app.
- **Binance**: Requires explicit transfer between spot/futures accounts.
---
| 操作 | 描述 | 参数 |
|--------|-------------|--------|
| `create_order` | 下单 | 现货:`{"exchange":"okx","symbol":"BTC/USDT","type":"market","side":"buy","amount":0.001}`(amount单位为BTC)。永续合约:`{"exchange":"okx","symbol":"BTC/USDT:USDT","type":"market","side":"buy","amount":1,"market_type":"swap"}`(amount单位为合约张数) |
| `cancel_order` | 撤单 | `{"exchange":"okx","symbol":"BTC/USDT","order_id":"xxx"}` |
| `set_leverage` | 设置杠杆 | `{"exchange":"okx","symbol":"BTC/USDT:USDT","leverage":10,"market_type":"swap"}` |
| `set_margin_mode` | 设置保证金模式 | `{"exchange":"okx","symbol":"BTC/USDT:USDT","margin_mode":"cross","market_type":"swap"}` |
| `transfer` | 资金划转 | `{"exchange":"binance","code":"USDT","amount":100,"from_account":"spot","to_account":"future"}` |
**`transfer`接口注意事项:**
- **OKX统一账户(重要)**:OKX采用统一交易账户 —— 现货和衍生品共用同一余额。**请勿要求用户在账户间划转资金**。如果transfer接口返回错误码58123,请告知用户:“你的OKX是统一账户,现货和合约共用同一个余额,不需要划转。” 不要建议用户在APP中手动划转。
- **Binance**:需要在现货/期货账户间明确划转资金。
---scripts/ft.mjs — Freqtrade Bot Control
scripts/ft.mjs — Freqtrade机器人控制
| Action | Description | Params |
|---|---|---|
| Health check | None |
| Start trading | None |
| Stop trading | None |
| Reload config | None |
| View config | None |
| Version info | None |
| System info | None |
| Health status | None |
| View logs | |
| Account balance | None |
| Open trades | None |
| Trade count | None |
| Trade by ID | |
| Trade history | |
| Manual entry | |
| Manual exit | |
| Cancel order | |
| Delete record | |
| Profit summary | None |
| Profit per pair | None |
| Daily report | |
| Weekly report | |
| Monthly report | |
| Statistics | None |
| 操作 | 描述 | 参数 |
|---|---|---|
| 健康检查 | 无 |
| 启动交易 | 无 |
| 停止交易 | 无 |
| 重载配置 | 无 |
| 查看配置 | 无 |
| 版本信息 | 无 |
| 系统信息 | 无 |
| 健康状态 | 无 |
| 查看日志 | |
| 账户余额 | 无 |
| 当前持仓 | 无 |
| 交易次数 | 无 |
| 按ID查看交易 | |
| 交易历史 | |
| 手动开仓 | |
| 手动平仓 | |
| 撤单 | |
| 删除交易记录 | |
| 盈亏汇总 | 无 |
| 按交易对统计盈亏 | 无 |
| 每日报告 | |
| 每周报告 | |
| 每月报告 | |
| 统计数据 | 无 |
scripts/ft-dev.mjs — Freqtrade Dev Tools
scripts/ft-dev.mjs — Freqtrade开发工具
| Action | Description | Params |
|---|---|---|
| Start backtest | |
| Backtest status | None |
| Abort backtest | None |
| Backtest history | None |
| History result | |
| Live candles | |
| Candles with indicators | |
| Available pairs | None |
| Whitelist | None |
| Blacklist | None |
| Add to blacklist | |
| Trade locks | None |
| Strategy list | None |
| Strategy detail | |
| 操作 | 描述 | 参数 |
|---|---|---|
| 启动回测 | |
| 回测状态 | 无 |
| 终止回测 | 无 |
| 回测历史 | 无 |
| 回测历史结果 | |
| 实时K线 | |
| 带指标的K线 | |
| 可用交易对 | 无 |
| 白名单 | 无 |
| 黑名单 | 无 |
| 添加到黑名单 | |
| 交易锁 | 无 |
| 策略列表 | 无 |
| 策略详情 | |
scripts/auto-trade.mjs — Automated Trading
scripts/auto-trade.mjs — 自动化交易
Config + execution helper. The AI agent makes all strategy decisions — this script only handles config, risk management, and order execution.
Config is stored at .
~/.openclaw/workspace/aicoin-trade-config.json| Action | Description | Params |
|---|---|---|
| Save trading config | |
| Show config + balance + positions + open orders | |
| Open a position (agent decides direction) | |
| Close current position + cancel orders | |
The action automatically:
open- Checks balance and market minimums
- Calculates position size from config (capital_pct × balance × leverage)
- Sets leverage
- Places market order
- Places stop-loss and take-profit limit orders
配置+执行辅助工具。AI Agent负责所有策略决策 —— 本脚本仅处理配置、风险管理和订单执行。
配置文件存储于。
~/.openclaw/workspace/aicoin-trade-config.json| 操作 | 描述 | 参数 |
|---|---|---|
| 保存交易配置 | |
| 查看配置+余额+仓位+挂单 | |
| 开仓(Agent决定方向) | |
| 平仓+撤单 | |
open- 检查余额和市场最小下单量
- 根据配置计算仓位大小(capital_pct × 余额 × 杠杆)
- 设置杠杆
- 下市价单
- 下止损和止盈限价单
scripts/ft-deploy.mjs — Freqtrade Deployment
scripts/ft-deploy.mjs — Freqtrade部署
One-click Freqtrade deployment via + official (no Docker). Clones the Freqtrade repo, runs to install all dependencies (including TA-Lib), generates config from exchange keys, starts as background process, auto-writes vars to .
git clonesetup.shsetup.sh -i.envFREQTRADE_*.env| Action | Description | Params |
|---|---|---|
| Check prerequisites (Python 3.11+, git, exchange keys) | None |
| Deploy Freqtrade (clone, setup.sh, config, start) | |
| Run backtest (no running process needed) | |
| Update Freqtrade to latest version | None |
| Process status | None |
| Start stopped process | None |
| Stop process | None |
| View process logs | |
| Remove process (preserves config) | None |
Deploy defaults to dry-run mode (simulated trading, no real money). Pass for live trading.
{"dry_run":false}IMPORTANT: NEVER use Docker for Freqtrade. The deploy script uses + (official Freqtrade installation method). Do NOT fall back to Docker, do NOT write custom install scripts, do NOT try directly. Just run — it handles everything.
git clonesetup.sh -ipip install freqtradenode scripts/ft-deploy.mjs deployIMPORTANT: Do NOT manually edit Freqtrade config files, do NOT manually run commands, do NOT manually . Always use actions. If deploy fails, check logs with and report the error — do NOT attempt manual workarounds.
freqtrade tradesource .venv/bin/activateft-deploy.mjsft-deploy.mjs logs通过 + 官方一键部署Freqtrade(无需Docker)。克隆Freqtrade仓库,运行安装所有依赖(包括TA-Lib),从.env中的交易所密钥生成配置,作为后台进程启动,自动将变量写入.env。
git clonesetup.shsetup.sh -iFREQTRADE_*| 操作 | 描述 | 参数 |
|---|---|---|
| 检查前置依赖(Python 3.11+、git、交易所密钥) | 无 |
| 部署Freqtrade(克隆、setup.sh、配置、启动) | |
| 运行回测 | |
| 更新Freqtrade到最新版本 | 无 |
| 进程状态 | 无 |
| 启动已停止的进程 | 无 |
| 停止进程 | 无 |
| 查看进程日志 | |
| 删除进程(保留配置) | 无 |
部署默认使用dry-run模式(模拟交易,无真实资金)。传入切换到实盘交易。
{"dry_run":false}重要提示:绝对不要使用Docker部署Freqtrade。部署脚本使用 + (Freqtrade官方推荐安装方式)。不要使用Docker,不要编写自定义安装脚本,不要直接执行。只需运行 —— 它会处理所有步骤。
git clonesetup.sh -ipip install freqtradenode scripts/ft-deploy.mjs deploy重要提示:不要手动编辑Freqtrade配置文件,不要手动运行命令,不要手动执行。必须始终使用的操作。如果部署失败,使用查看日志并报告错误 —— 不要尝试手动解决。
freqtrade tradesource .venv/bin/activateft-deploy.mjsft-deploy.mjs logsAutomated Trading Guide
自动化交易指南
When the user asks to set up automated trading, follow this workflow. Do NOT write custom scripts.
当用户询问如何设置自动化交易时,请遵循以下工作流。不要编写自定义脚本。
How It Works
工作原理
The AI agent is the strategist. On each cycle:
- Fetch data using existing scripts: (funding, OI, liquidation),
coin.mjs(klines, volume),market.mjs(whale orders, long/short ratio),features.mjs(Hyperliquid data)hl-market.mjs - Analyze the data — trend, momentum, risk signals. Use your own judgment.
- Decide: open long, open short, close position, or hold
- Execute via — handles position sizing, leverage, stop-loss/take-profit automatically
auto-trade.mjs open '{"direction":"long"}'
AI Agent担任策略师角色,在每个周期执行以下步骤:
- 获取数据:使用现有脚本(资金费率、持仓量、爆仓)、
coin.mjs(K线、成交量)、market.mjs(鲸鱼订单、多空比)、features.mjs(Hyperliquid数据)hl-market.mjs - 分析数据:趋势、动量、风险信号,使用自身判断
- 决策:开多、开空、平仓或持有
- 执行:通过—— 自动处理仓位大小、杠杆、止损/止盈
auto-trade.mjs open '{"direction":"long"}'
Quick Setup
快速设置
bash
undefinedbash
undefined1. Configure risk params
1. 配置风险参数
node scripts/auto-trade.mjs setup '{"exchange":"okx","symbol":"BTC/USDT:USDT","leverage":10,"capital_pct":0.5}'
node scripts/auto-trade.mjs setup '{"exchange":"okx","symbol":"BTC/USDT:USDT","leverage":10,"capital_pct":0.5}'
2. Check status
2. 查看状态
node scripts/auto-trade.mjs status
undefinednode scripts/auto-trade.mjs status
undefinedOpenClaw Cron (Recommended)
推荐使用OpenClaw Cron
Use OpenClaw's built-in cron, NOT system crontab. This gives the user visibility in the web UI.
bash
openclaw cron add \
--name "BTC auto trade" \
--every 10m \
--session isolated \
--message "You are a crypto trader. Use the aicoin skill to: 1) Fetch BTC market data (price, funding rate, OI, whale orders, liquidation). 2) Analyze the data and decide: open long, open short, close, or hold. 3) If trading, run: node scripts/auto-trade.mjs open '{\"direction\":\"long\"}'. 4) Report your analysis briefly."使用OpenClaw内置的Cron,不要使用系统crontab。这样用户可以在Web UI中查看任务状态。
bash
openclaw cron add \
--name "BTC auto trade" \
--every 10m \
--session isolated \
--message "你是一名加密货币交易员,使用aicoin skill执行以下操作:1) 获取BTC市场数据(价格、资金费率、持仓量、鲸鱼订单、爆仓)。2) 分析数据并决策:开多、开空、平仓或持有。3) 若需要交易,运行:node scripts/auto-trade.mjs open '{\"direction\":\"long\"}'。4) 简要报告分析结果。"When User Asks "帮我自动交易"
当用户询问“帮我自动交易”时
- Ask: which exchange? which coin? how much capital? what leverage?
- Run with their params
auto-trade.mjs setup - Run to verify exchange connection
auto-trade.mjs status - Set up OpenClaw cron with their preferred interval
- Done — tell them they can check status anytime via
auto-trade.mjs status
- 询问:哪个交易所?哪个币种?使用多少资金?杠杆倍数?
- 使用用户提供的参数运行
auto-trade.mjs setup - 运行验证交易所连接
auto-trade.mjs status - 使用用户偏好的时间间隔设置OpenClaw Cron
- 完成设置 —— 告知用户可随时通过查看状态
auto-trade.mjs status
Freqtrade Guide
Freqtrade指南
When the user asks about backtesting, professional strategies, quantitative trading, or deploying a trading bot, guide them to Freqtrade.
Freqtrade vs auto-trade.mjs:
- auto-trade.mjs = simple AI-driven, good for testing, small capital
- Freqtrade = professional, backtestable, risk-managed, production-grade
当用户询问回测、专业策略、量化交易或部署交易机器人时,引导其使用Freqtrade。
Freqtrade vs auto-trade.mjs:
- auto-trade.mjs = 简单AI驱动,适合测试、小额资金
- Freqtrade = 专业级,支持回测,具备风险管理,适合生产环境
Deployment (One Command)
部署(一键命令)
bash
undefinedbash
undefinedCheck prerequisites first
先检查前置依赖
node scripts/ft-deploy.mjs check
node scripts/ft-deploy.mjs check
Deploy (dry-run mode by default — safe)
部署(默认dry-run模式,安全无风险)
node scripts/ft-deploy.mjs deploy '{"pairs":["BTC/USDT:USDT","ETH/USDT:USDT"]}'
This automatically:
1. Ensures Python 3.11+ is available (auto-installs via brew if needed on macOS)
2. Clones Freqtrade repo to `~/.freqtrade/source/`
3. Runs official `setup.sh -i` (installs TA-Lib, creates venv, installs all dependencies)
4. Creates config from exchange keys in `.env`
5. Includes a sample RSI+EMA strategy (pure pandas, no TA-Lib import needed)
6. Starts Freqtrade as a background process with API server
7. Writes `FREQTRADE_URL`, `FREQTRADE_USERNAME`, `FREQTRADE_PASSWORD` to `.env`
8. Ready to use via `ft.mjs` and `ft-dev.mjs`
**Prerequisites:** Python 3.11+ and git. Exchange API keys must be in `.env`. Everything else is auto-installed — do NOT install manually or use Docker.node scripts/ft-deploy.mjs deploy '{"pairs":["BTC/USDT:USDT","ETH/USDT:USDT"]}'
该命令会自动执行以下步骤:
1. 确保Python 3.11+可用(macOS上若缺失会通过brew自动安装)
2. 将Freqtrade仓库克隆到`~/.freqtrade/source/`
3. 运行官方`setup.sh -i`(安装TA-Lib、创建虚拟环境、安装所有依赖)
4. 从.env中的交易所密钥生成配置
5. 包含一个示例RSI+EMA策略(纯pandas实现,无需导入TA-Lib)
6. 启动Freqtrade后台进程并开启API服务
7. 将`FREQTRADE_URL`、`FREQTRADE_USERNAME`、`FREQTRADE_PASSWORD`写入.env
8. 可通过`ft.mjs`和`ft-dev.mjs`使用
**前置依赖:** Python 3.11+ 和 git。交易所API密钥必须已在.env中配置。其他所有依赖会自动安装 —— 不要手动安装或使用Docker。User Journey
用户操作流程示例
"帮我部署Freqtrade"
→ node scripts/ft-deploy.mjs deploy
→ "已部署,dry-run模式,用模拟资金运行"
"帮我回测BTC策略"
→ node scripts/ft-deploy.mjs backtest '{"strategy":"SampleStrategy","timeframe":"1h","timerange":"20250101-20260301"}'
→ "回测结果: 胜率62%, 最大回撤-8%, 总收益+45%"
"不错,上实盘"
→ node scripts/ft-deploy.mjs deploy '{"dry_run":false}'
→ "⚠️ 已切换到实盘模式,使用真实资金"
"今天赚了多少?"
→ node scripts/ft.mjs profit
→ node scripts/ft.mjs daily '{"count":7}'
"暂停交易"
→ node scripts/ft.mjs stop"帮我部署Freqtrade"
→ node scripts/ft-deploy.mjs deploy
→ "已部署,当前为dry-run模式,使用模拟资金运行"
"帮我回测BTC策略"
→ node scripts/ft-deploy.mjs backtest '{"strategy":"SampleStrategy","timeframe":"1h","timerange":"20250101-20260301"}'
→ "回测结果: 胜率62%, 最大回撤-8%, 总收益+45%"
"不错,上实盘"
→ node scripts/ft-deploy.mjs deploy '{"dry_run":false}'
→ "⚠️ 已切换到实盘模式,使用真实资金"
"今天赚了多少?"
→ node scripts/ft.mjs profit
→ node scripts/ft.mjs daily '{"count":7}'
"暂停交易"
→ node scripts/ft.mjs stopWhen User Mentions These Keywords → Use Freqtrade
当用户提及以下关键词时 → 使用Freqtrade
- 回测 / backtest → (does NOT require Freqtrade to be running)
ft-deploy.mjs backtest - 写策略 / write strategy → Write a file to
.py, then~/.freqtrade/user_data/strategies/ft-deploy.mjs backtest - 量化策略 / strategy → (requires running process)
ft-dev.mjs strategy_list - 部署机器人 / deploy bot →
ft-deploy.mjs deploy - 实盘 / live trading →
ft-deploy.mjs deploy '{"dry_run":false}' - 盈亏 / profit →
ft.mjs profit - 停止机器人 / stop bot → or
ft.mjs stopft-deploy.mjs stop
IMPORTANT: For backtesting, use . Do NOT write custom Python backtest scripts. The Freqtrade backtester is production-grade with proper slippage, fees, and position sizing simulation.
ft-deploy.mjs backtest- 回测 / backtest → (无需Freqtrade正在运行)
ft-deploy.mjs backtest - 写策略 / write strategy → 将文件写入
.py,然后运行~/.freqtrade/user_data/strategies/ft-deploy.mjs backtest - 量化策略 / strategy → (需要Freqtrade正在运行)
ft-dev.mjs strategy_list - 部署机器人 / deploy bot →
ft-deploy.mjs deploy - 实盘 / live trading →
ft-deploy.mjs deploy '{"dry_run":false}' - 盈亏 / profit →
ft.mjs profit - 停止机器人 / stop bot → 或
ft.mjs stopft-deploy.mjs stop
重要提示:回测必须使用,不要编写自定义Python回测脚本。Freqtrade回测器是生产级别的,支持滑点、手续费和仓位大小模拟。
ft-deploy.mjs backtest