| name | aicoin-freqtrade |
| description | Use when user asks about writing trading strategies, backtesting, deploying Freqtrade bots, quantitative trading, or strategy optimization. Trigger words: 'write strategy', 'create strategy', 'backtest', 'deploy Freqtrade', 'deploy bot', 'quantitative', 'hyperopt', '写策略', '创建策略', '回测', '部署', '量化', '策略优化'. This skill provides: (1) create_strategy quick generator with 17 indicators, (2) AiCoin Python SDK (aicoin_data.py) for integrating real market data into custom strategies, (3) deploy/backtest/hyperopt tools. ALWAYS actively use AiCoin data (funding rate, L/S ratio, whale orders, etc.) in strategies when the user's API key supports it. For prices/charts use aicoin-market. For trading use aicoin-trading. For Hyperliquid use aicoin-hyperliquid. |
| metadata | {"openclaw":{"primaryEnv":"AICOIN_ACCESS_KEY_ID","requires":{"bins":"[Truncated]"},"homepage":"https://www.aicoin.com/opendata","source":"https://github.com/aicoincom/coinos-skills","license":"MIT"}} |
⚠️ 运行脚本: 必须先 cd 到本 SKILL.md 所在目录再执行。示例: cd ~/.openclaw/workspace/skills/aicoin-freqtrade && node scripts/ft-deploy.mjs ...
AiCoin Freqtrade
Freqtrade strategy creation, backtesting, and deployment powered by AiCoin Open API.
Critical Rules
- ALWAYS use
ft-deploy.mjs backtest for backtesting. NEVER write custom backtest scripts. NEVER use simulated/fabricated data.
- ALWAYS use
ft-deploy.mjs deploy for deployment. NEVER use Docker. NEVER manually run freqtrade commands.
- NEVER manually edit Freqtrade config files. Use
ft-deploy.mjs actions.
- NEVER manually run
freqtrade trade, freqtrade status, freqtrade backtesting, source .venv/bin/activate, or pip install freqtrade. Always use ft-deploy.mjs or ft.mjs instead.
- ACTIVELY use AiCoin data in strategies. Check what data the user's API key supports and integrate it. Don't only use basic indicators when richer data is available.
- Freqtrade 不支持网格策略(grid)。 用户问网格时,说明限制并建议用趋势跟踪或区间策略替代。
Two Ways to Create Strategies
Option A: Quick Generator (for simple strategies)
create_strategy generates a ready-to-backtest strategy file with selected indicators and optional AiCoin data:
node scripts/ft-deploy.mjs create_strategy '{"name":"MACDStrategy","timeframe":"15m","indicators":["macd","rsi","atr"]}'
node scripts/ft-deploy.mjs create_strategy '{"name":"WhaleStrat","timeframe":"15m","indicators":["rsi","macd"],"aicoin_data":["funding_rate","ls_ratio"]}'
Available indicators: rsi, bb, ema, sma, macd, stochastic/kdj, atr, adx, cci, williams_r, vwap, ichimoku, volume_sma, obv
Option B: Write Custom Strategy Code (for complex/custom strategies)
When users need custom logic beyond what create_strategy offers, write a Python strategy file directly. Use the AiCoin Python SDK (aicoin_data.py, auto-installed at ~/.freqtrade/user_data/strategies/) to integrate real market data.
Strategy file location: ~/.freqtrade/user_data/strategies/YourStrategyName.py
AiCoin Python SDK Reference
from aicoin_data import AiCoinData, ccxt_to_aicoin
ac = AiCoinData(cache_ttl=300)
symbol = ccxt_to_aicoin("BTC/USDT:USDT", "binance")
ac.coin_ticker("bitcoin")
ac.kline(symbol, period="3600")
ac.hot_coins("market")
ac.funding_rate(symbol)
ac.funding_rate(symbol, weighted=True)
ac.ls_ratio()
ac.big_orders(symbol)
ac.agg_trades(symbol)
ac.liquidation_map(symbol, cycle="24h")
ac.liquidation_history(symbol)
ac.open_interest("BTC", interval="15m")
ac.ai_analysis(["BTC"])
Complete Strategy Template (copy and customize)
from freqtrade.strategy import IStrategy, IntParameter, DecimalParameter
from pandas import DataFrame
import logging, time
logger = logging.getLogger(__name__)
class MyCustomStrategy(IStrategy):
INTERFACE_VERSION = 3
timeframe = '15m'
can_short = True
minimal_roi = {"0": 0.05, "60": 0.03, "120": 0.01}
stoploss = -0.05
trailing_stop = True
trailing_stop_positive = 0.02
trailing_stop_positive_offset = 0.03
rsi_buy = IntParameter(20, 40, default=30, space='buy')
rsi_sell = IntParameter(60, 80, default=70, space='sell')
_ac_funding_rate = 0.0
_ac_ls_ratio = 0.5
_ac_whale_signal = 0.0
_ac_last_update = 0.0
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
delta = dataframe['close'].diff()
gain = delta.clip(lower=0).rolling(window=).mean()
loss = (-delta.clip(upper=)).rolling(window=).mean()
rs = gain / loss
dataframe[] = - ( / ( + rs))
ema12 = dataframe[].ewm(span=, adjust=).mean()
ema26 = dataframe[].ewm(span=, adjust=).mean()
dataframe[] = ema12 - ema26
dataframe[] = dataframe[].ewm(span=, adjust=).mean()
dataframe[] = dataframe[].ewm(span=, adjust=).mean()
dataframe[] = dataframe[].ewm(span=, adjust=).mean()
dataframe[] =
dataframe[] =
dataframe[] =
.dp .dp.runmode.value (, ):
now = time.time()
now - ._ac_last_update > :
._update_aicoin_data(metadata)
._ac_last_update = now
dataframe.iloc[-, dataframe.columns.get_loc()] = ._ac_funding_rate
dataframe.iloc[-, dataframe.columns.get_loc()] = ._ac_ls_ratio
dataframe.iloc[-, dataframe.columns.get_loc()] = ._ac_whale_signal
dataframe
():
:
sys, os
_sd = os.path.dirname(os.path.abspath(__file__))
_sd sys.path:
sys.path.insert(, _sd)
aicoin_data AiCoinData, ccxt_to_aicoin
ac = AiCoinData(cache_ttl=)
pair = metadata.get(, )
exchange = .config.get(, {}).get(, )
symbol = ccxt_to_aicoin(pair, exchange)
:
data = ac.funding_rate(symbol, weighted=, limit=)
items = data.get(, [])
(items, ) items:
latest = items[]
(latest, ) latest:
._ac_funding_rate = (latest[]) *
Exception e:
logger.debug()
:
ls = ac.ls_ratio()
detail = ls.get(, {}).get(, {})
detail:
ratio = (detail.get(, ))
._ac_ls_ratio = (, (, ratio / ( + ratio)))
Exception e:
logger.debug()
:
orders = ac.big_orders(symbol)
orders (orders[], ):
buy_vol = ((o.get(, )) o orders[]
o.get(, ).lower() (, , ))
sell_vol = ((o.get(, )) o orders[]
o.get(, ).lower() (, , ))
total = buy_vol + sell_vol
total > :
._ac_whale_signal = (buy_vol - sell_vol) / total
Exception e:
logger.debug()
ImportError:
logger.warning()
Exception e:
logger.warning()
() -> DataFrame:
dataframe.loc[
(dataframe[] < .rsi_buy.value) &
(dataframe[] > dataframe[]) &
(dataframe[] > dataframe[]) &
(dataframe[] <= ) &
(dataframe[] >= -) &
(dataframe[] > ),
] =
dataframe.loc[
(dataframe[] > .rsi_sell.value) &
(dataframe[] < dataframe[]) &
(dataframe[] < dataframe[]) &
(dataframe[] >= ) &
(dataframe[] <= ) &
(dataframe[] > ),
] =
dataframe
() -> DataFrame:
dataframe.loc[(dataframe[] > ), ] =
dataframe.loc[(dataframe[] < ), ] =
dataframe
AiCoin Data Integration Patterns
Use these patterns to integrate specific AiCoin data into entry/exit conditions:
| AiCoin Data | Signal Logic | Tier |
|---|
funding_rate | Rate > 0.01% → market over-leveraged long → short signal; Rate < -0.01% → long signal | 基础版 |
ls_ratio | Ratio < 0.45 (more shorts) → contrarian long; Ratio > 0.55 (more longs) → contrarian short | 基础版 |
big_orders | (buy_vol - sell_vol) / total > 0.3 → whale buying → long; < -0.3 → short | 标准版 |
open_interest | OI rising + price rising = healthy trend; OI rising + price falling = weak, likely reversal | 专业版 |
liquidation_map | More short liquidations above → short squeeze likely → long; vice versa | 高级版 |
Key Rule: Backtest Behavior
AiCoin real-time data is NOT available for historical periods. In backtest mode:
- AiCoin columns use default values (funding_rate=0.0, ls_ratio=0.5, whale_signal=0.0)
- This means backtest results reflect technical indicators only
- Live/dry_run trading uses real AiCoin data, which should improve performance vs backtest
Always explain this to the user when showing backtest results.
Quick Reference
| Task | Command |
|---|
| Quick-generate strategy | node scripts/ft-deploy.mjs create_strategy '{"name":"MyStrat","timeframe":"15m","indicators":["rsi","macd"],"aicoin_data":["funding_rate"]}' |
| Backtest | node scripts/ft-deploy.mjs backtest '{"strategy":"MyStrat","timeframe":"1h","timerange":"20250101-20260301","pairs":["ETH/USDT:USDT"]}' |
| Deploy (dry-run) | node scripts/ft-deploy.mjs deploy '{"strategy":"MyStrat","pairs":["BTC/USDT:USDT"]}' |
| Deploy (live) | node scripts/ft-deploy.mjs deploy '{"strategy":"MyStrat","dry_run":false,"pairs":["BTC/USDT:USDT"]}' |
| Hyperopt | node scripts/ft-deploy.mjs hyperopt '{"strategy":"MyStrat","timeframe":"1h","timerange":"20250101-20260301","epochs":100}' |
| Strategy list | node scripts/ft-deploy.mjs strategy_list |
| Bot status | node scripts/ft-deploy.mjs status |
| Bot logs | node scripts/ft-deploy.mjs logs '{"lines":50}' |
Setup
Prerequisites: Python 3.11+ and git.
.env auto-loaded from (first found wins): cwd → ~/.openclaw/workspace/.env → ~/.openclaw/.env
Exchange keys (for live/dry-run):
BINANCE_API_KEY=xxx
BINANCE_API_SECRET=xxx
AiCoin API key (for AiCoin data in strategies):
AICOIN_ACCESS_KEY_ID=your-key-id
AICOIN_ACCESS_SECRET=your-secret
Get at https://www.aicoin.com/opendata
Scripts
ft-deploy.mjs — Deployment & Strategy
| Action | Params |
|---|
check | None |
deploy | {"strategy":"MACDKDJStrategy","dry_run":true,"pairs":["BTC/USDT:USDT"]} — strategy 必填,指定策略名 |
backtest | {"strategy":"Name","timeframe":"1h","timerange":"20250101-20260301","pairs":["ETH/USDT:USDT"]} — pairs 可选,默认用 config 中的交易对 |
hyperopt | {"strategy":"Name","timeframe":"1h","epochs":100} |
create_strategy | {"name":"Name","timeframe":"15m","indicators":["rsi","macd"],"aicoin_data":["funding_rate"]} |
strategy_list | None |
backtest_results | None — lists recent backtest result files |
start / stop / status / logs | None / {"lines":50} |
ft.mjs — Bot Control (requires running process)
ping, start, stop, balance, profit, trades_open, trades_history, force_enter, force_exit, daily, weekly, monthly, stats
ft-dev.mjs — Dev Tools (requires running process)
backtest_start, backtest_status, candles_live, candles_analyzed, strategy_list, strategy_get
Cross-Skill References
| Need | Use |
|---|
| Prices, K-lines, market data | aicoin-market |
| Exchange trading (buy/sell) | aicoin-trading |
| Hyperliquid whale tracking | aicoin-hyperliquid |
Paid Feature Guide
When 304/403: Do NOT retry. Guide the user:
| Tier | Price | Data for Strategies |
|---|
| 免费版 | $0 | Pure technical indicators |
| 基础版 | $29/mo | + funding_rate, ls_ratio |
| 标准版 | $79/mo | + big_orders, agg_trades |
| 高级版 | $299/mo | + liquidation_map |
| 专业版 | $699/mo | + open_interest, ai_analysis |
Configure: AICOIN_ACCESS_KEY_ID + AICOIN_ACCESS_SECRET in .env