dca
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDCA — Dollar Cost Averaging for Stacks DeFi
DCA — 适用于Stacks DeFi的美元成本平均策略
Automate recurring token purchases (or sales) on Stacks mainnet via direct Bitflow swaps.
The agent executes each order on schedule — no third-party contracts required.
通过Bitflow直接兑换在Stacks主网自动化定期代币买入(或卖出)。
Agent会按计划执行每笔订单 — 无需第三方合约。
How It Works
工作原理
- creates a local plan file with the full schedule
setup - is called by the agent on each schedule tick (via cron or heartbeat)
run - Each checks if an order is due, fetches a live quote, and returns
rununtilblocked--confirm - On confirm: executes the swap on-chain, logs the tx hash, advances the schedule
- shows progress: avg entry price, total spent/received, remaining orders
status
- 创建包含完整计划的本地配置文件
setup - 由Agent在每个计划时间点调用(通过cron或心跳机制)
run - 每次会检查是否有订单到期,获取实时报价,在未添加
run参数时返回--confirm状态blocked - 确认后:在链上执行兑换,记录交易哈希,推进计划进度
- 展示进度:平均入场价、总支出/收入、剩余订单数
status
Quick Start
快速开始
bash
undefinedbash
undefined1. Install dependencies
1. Install dependencies
bun run dca/dca.ts install-packs --pack all
bun run dca/dca.ts install-packs --pack all
2. Health check
2. Health check
bun run dca/dca.ts doctor
bun run dca/dca.ts doctor
3. Create a plan: DCA 50 STX into sBTC over 5 daily orders
3. Create a plan: DCA 50 STX into sBTC over 5 daily orders
bun run dca/dca.ts setup
--token-in STX --token-out sBTC
--total 50 --orders 5 --frequency daily --slippage 3
--token-in STX --token-out sBTC
--total 50 --orders 5 --frequency daily --slippage 3
bun run dca/dca.ts setup
--token-in STX --token-out sBTC
--total 50 --orders 5 --frequency daily --slippage 3
--token-in STX --token-out sBTC
--total 50 --orders 5 --frequency daily --slippage 3
4. Preview the schedule
4. Preview the schedule
bun run dca/dca.ts plan --plan <planId>
bun run dca/dca.ts plan --plan <planId>
5. Execute next order (--confirm required)
5. Execute next order (--confirm required)
Preferred: use env var (doesn't appear in ps aux or shell history)
Preferred: use env var (doesn't appear in ps aux or shell history)
export AIBTC_WALLET_PASSWORD="your-password"
bun run dca/dca.ts run --plan <planId>
export AIBTC_WALLET_PASSWORD="your-password"
bun run dca/dca.ts run --plan <planId>
Review the quote, then:
Review the quote, then:
bun run dca/dca.ts run --plan <planId> --confirm
bun run dca/dca.ts run --plan <planId> --confirm
6. Monitor progress
6. Monitor progress
bun run dca/dca.ts status --plan <planId>
bun run dca/dca.ts status --plan <planId>
7. Cancel remaining orders
7. Cancel remaining orders
bun run dca/dca.ts cancel --plan <planId>
undefinedbun run dca/dca.ts cancel --plan <planId>
undefinedCommands
命令说明
doctor
doctordoctor
doctorSystem health check — verifies Bitflow API, wallet file, and Stacks mainnet connectivity.
系统健康检查 — 验证Bitflow API、钱包文件和Stacks主网连接状态。
install-packs --pack all
install-packs --pack allinstall-packs --pack all
install-packs --pack allOne-time setup: installs required packages. Run once during initial setup — not during normal execution.
Installs: , , , , , ,
@bitflowlabs/core-sdk@stacks/transactions@stacks/network@stacks/wallet-sdk@stacks/encryptioncommandertslibNote:runsinstall-packsand modifiesbun add. This is a one-time setup step — do not call it during regular agent operation or in shared environments where multiple processes may be active.package.json
一次性配置:安装所需依赖包。仅在初始设置时运行一次 — 正常执行期间无需调用。
安装内容: , , , , , ,
@bitflowlabs/core-sdk@stacks/transactions@stacks/network@stacks/wallet-sdk@stacks/encryptioncommandertslib注意:会执行install-packs并修改bun add。这是一次性设置步骤 — 不要在常规Agent运行期间或多进程活跃的共享环境中调用。package.json
Dependencies
依赖说明
If not using , add these to your project manually:
install-packsbash
bun add @bitflowlabs/core-sdk @stacks/transactions @stacks/network @stacks/wallet-sdk @stacks/encryption commander tslib如果不使用,请手动将以下依赖添加到项目中:
install-packsbash
bun add @bitflowlabs/core-sdk @stacks/transactions @stacks/network @stacks/wallet-sdk @stacks/encryption commander tslibsetup
setupsetup
setup| Flag | Required | Description |
|---|---|---|
| ✅ | Input token symbol (e.g. |
| ✅ | Output token symbol (e.g. |
| ✅ | Total amount in human units (e.g. |
| ✅ | Number of orders (2..100) |
| ✅ | |
| ❌ | Slippage % (default |
| ❌ | Hours before first order (default |
Validates the token pair against live Bitflow routes before saving.
| 参数 | 是否必填 | 说明 |
|---|---|---|
| ✅ | 输入代币符号(例如 |
| ✅ | 输出代币符号(例如 |
| ✅ | 总金额(采用人类可读单位,例如 |
| ✅ | 订单数量(2..100) |
| ✅ | |
| ❌ | 滑点百分比(默认值 |
| ❌ | 首次订单延迟小时数(默认值 |
保存前会验证代币对是否存在有效的Bitflow路由。
plan --plan <id>
plan --plan <id>plan --plan <id>
plan --plan <id>Preview the full DCA schedule with per-order timing and current quote estimates.
预览完整DCA计划,包含每笔订单的时间安排和当前报价估算。
run --plan <id> [--confirm] [--wallet-password <pw>]
run --plan <id> [--confirm] [--wallet-password <pw>]run --plan <id> [--confirm] [--wallet-password <pw>]
run --plan <id> [--confirm] [--wallet-password <pw>]Execute the next pending order. Cron-friendly — returns if called before the next order is due.
blocked- Without : Returns live quote preview. Safe to inspect.
--confirm - With : Executes the swap on-chain, logs tx hash, advances schedule.
--confirm
Security: Preferenv var overAIBTC_WALLET_PASSWORDflag. CLI flags appear in--wallet-passwordoutput and shell history — a real risk in long-lived agent processes. Useps auxonly as a fallback.--wallet-passwordbash# Preferred (env var — not visible in ps aux) export AIBTC_WALLET_PASSWORD="your-password" bun run dca/dca.ts run --plan <planId> --confirm # Fallback only (flag — visible in process list) bun run dca/dca.ts run --plan <planId> --confirm --wallet-password "your-password"
执行下一笔待处理订单。适配cron调度 — 如果在订单到期前调用,会返回状态。
blocked- 未添加:返回实时报价预览,可安全查看。
--confirm - 添加:在链上执行兑换,记录交易哈希,推进计划进度。
--confirm
安全提示: 优先使用环境变量,而非AIBTC_WALLET_PASSWORD参数。CLI参数会出现在--wallet-password输出和shell历史中 — 在长期运行的Agent进程中存在安全风险。仅在万不得已时使用ps aux。--wallet-passwordbash# 推荐方式(环境变量 — 不会出现在ps aux中) export AIBTC_WALLET_PASSWORD="your-password" bun run dca/dca.ts run --plan <planId> --confirm # 仅作为备选(参数 — 会出现在进程列表中) bun run dca/dca.ts run --plan <planId> --confirm --wallet-password "your-password"
status --plan <id>
/ status --all
status --plan <id>status --allstatus --plan <id>
/ status --all
status --plan <id>status --allProgress: orders complete, total spent, total received, avg entry price, next order ETA.
展示进度:已完成订单数、总支出、总收入、平均入场价、下一笔订单预计时间。
cancel --plan <id>
cancel --plan <id>cancel --plan <id>
cancel --plan <id>Cancel a plan. Stops all future calls for this plan.
run取消计划。停止该计划的所有后续调用。
runlist
listlist
listList all local DCA plan files with status.
列出所有本地DCA计划文件及其状态。
Token Amounts
代币金额说明
Pass in human-readable units (not microunits):
--total| Token | Example | Meaning |
|---|---|---|
| STX | | 50 STX |
| sBTC | | 0.001 sBTC |
| ALEX | | 100 ALEX |
--total| 代币 | 示例 | 含义 |
|---|---|---|
| STX | | 50 STX |
| sBTC | | 0.001 sBTC |
| ALEX | | 100 ALEX |
Environment Variables
环境变量
| Variable | Description |
|---|---|
| Wallet password (alternative to |
| Direct private key for testing (bypasses wallet file) |
| Simulate all writes — no transactions broadcast |
| 环境变量 | 说明 |
|---|---|
| 钱包密码(替代 |
| 用于测试的直接私钥(绕过钱包文件) |
| 模拟所有写入操作 — 不会广播交易 |
Output Format
输出格式
All commands emit strict JSON to stdout:
json
{
"status": "success | error | blocked",
"action": "Human-readable next step",
"data": {
"telegram": "📊 Emoji-rich Telegram-friendly summary",
"...": "command-specific fields"
},
"error": null
}所有命令会向标准输出输出严格的JSON格式:
json
{
"status": "success | error | blocked",
"action": "Human-readable next step",
"data": {
"telegram": "📊 Emoji-rich Telegram-friendly summary",
"...": "command-specific fields"
},
"error": null
}Safety Guardrails (enforced in code)
安全防护规则(代码强制执行)
| Guardrail | Limit | Enforcement |
|---|---|---|
| Max slippage | 10% | Hard error |
| Max orders | 100 | Hard error |
| Min order size | > 0 | Hard error |
| Spend confirmation | Always | |
| Frequency enforcement | Per-plan | |
| Balance check | STX pre-execution | Error |
| Cancelled/completed plans | Blocked | Error |
| Private key exposure | Never | Zero-exposure in all output |
| Dry run mode | | Simulates without broadcasting |
| 安全防护规则 | 限制值 | 执行方式 |
|---|---|---|
| 最大滑点 | 10% | 触发硬错误 |
| 最大订单数 | 100 | 触发硬错误 |
| 最小订单金额 | > 0 | 触发硬错误 |
| 支出确认 | 始终需要 | 未添加 |
| 频率校验 | 按计划执行 | 调用过早时返回 |
| 余额检查 | 执行前校验STX余额 | 触发错误 |
| 已取消/完成的计划 | 禁止执行 | 触发错误 |
| 私钥暴露 | 绝对禁止 | 所有输出中不会泄露私钥 |
| 模拟运行模式 | | 模拟操作但不广播交易 |
Scheduling
调度方式
The command is designed to be called by cron or heartbeat:
runbash
undefinedrunbash
undefinedCron: execute DCA daily at 9am
Cron: 每天上午9点执行DCA
0 9 * * * AIBTC_WALLET_PASSWORD=xxx bun run /path/to/dca/dca.ts run --plan <id> --confirm
Frequency is enforced by the skill — early calls return `blocked` with time remaining. Safe to call frequently.0 9 * * * AIBTC_WALLET_PASSWORD=xxx bun run /path/to/dca/dca.ts run --plan <id> --confirm
该工具会按计划频率执行 — 提前调用会返回`blocked`状态并显示剩余时间。可安全高频调用。State Files
状态文件
Plans stored at . Contains full plan config, every tx hash, per-order execution log, and running avg cost.
~/.aibtc/dca/<plan-id>.json计划存储在。包含完整计划配置、每笔交易哈希、订单执行日志和实时平均成本。
~/.aibtc/dca/<plan-id>.jsonWallet Support
钱包支持
Three wallet sources (checked in order):
- env var (direct, for testing)
STACKS_PRIVATE_KEY - AIBTC MCP wallet (+ keystore — AES-256-GCM + scrypt)
~/.aibtc/wallets.json - Legacy (older format)
~/.aibtc/wallet.json
三种钱包来源(按优先级检查):
- 环境变量(直接调用,用于测试)
STACKS_PRIVATE_KEY - AIBTC MCP钱包(+ 密钥库 — AES-256-GCM + scrypt加密)
~/.aibtc/wallets.json - 旧版(兼容旧格式)
~/.aibtc/wallet.json
Known Constraints
已知限制
- Mainnet only
- Requires funded wallet (STX for gas + swap input token)
- Bitflow API must be reachable (500 req/min rate limit)
- Not all token pairs have routes — validates before saving
setup
- 仅支持主网
- 钱包需有余额(STX用于Gas费 + 兑换输入代币)
- 需可访问Bitflow API(速率限制为500次请求/分钟)
- 并非所有代币对都有可用路由 — 会在保存前验证
setup
Origin
来源
Winner of AIBTC x Bitflow Skills Pay the Bills competition.
Original author: @k9dreamermacmini-coder
Competition PR: https://github.com/BitflowFinance/bff-skills/pull/31
AIBTC x Bitflow Skills Pay the Bills竞赛获奖作品。
原作者:@k9dreamermacmini-coder
竞赛PR:https://github.com/BitflowFinance/bff-skills/pull/31