重要前提
安装AI Skills的关键前提是:必须科学上网,且开启TUN模式,这一点至关重要,直接决定安装能否顺利完成,在此郑重提醒三遍:科学上网,科学上网,科学上网。查看完整安装教程 →
alpaca-trading by lacymorrow/openclaw-alpaca-trading-skill
npx skills add https://github.com/lacymorrow/openclaw-alpaca-trading-skill --skill alpaca-trading通过 apcacli 命令行工具执行交易并管理投资组合,该工具用于 Alpaca 的交易 API。
apcacli 是一个 Rust CLI。跨平台安装方法如下:
brew install rustup
rustup-init -y
source "$HOME/.cargo/env"
cargo install apcacli
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source "$HOME/.cargo/env"
cargo install apcacli
cargo install apcacliexport APCA_API_KEY_ID='your-key-id'
export APCA_API_SECRET_KEY='your-secret-key'
# 用于实盘交易(默认为模拟交易):
# export APCA_API_BASE_URL='https://api.alpaca.markets'
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
您是使用 apcacli 进行命令行股票交易的专家。您的目标是帮助用户通过 Alpaca 的 API 高效地交易股票、ETF、期权和加密货币,同时强调安全性和最佳实践。
在帮助用户处理交易任务时:
apcacli 是一个基于 Rust 的 CLI,用于与 Alpaca 交易平台交互。它提供:
当用户想要:
常见触发短语:
何时不应使用此技能:
# 使用 Cargo (Rust 包管理器)
cargo install apcacli
# 验证安装
apcacli --help
要求:
对于模拟交易(测试推荐):
export APCA_API_KEY_ID='your_paper_key_id'
export APCA_API_SECRET_KEY='your_paper_secret_key'
# 模拟交易是默认设置,无需设置 APCA_API_BASE_URL
对于实盘交易:
export APCA_API_BASE_URL='https://api.alpaca.markets'
export APCA_API_KEY_ID='your_live_key_id'
export APCA_API_SECRET_KEY='your_live_secret_key'
获取 API 凭证:
查看账户详情:
apcacli account get
显示账户状态、现金余额、购买力、权益和保证金信息。
查看账户活动:
apcacli account activity
显示最近的账户活动,包括交易、股息和转账。
更新账户配置:
apcacli account config <options>
修改账户设置(使用 --help 查看可用选项)。
提交市价单:
# 按金额买入
apcacli order submit buy AAPL --value 1000
# 按数量买入
apcacli order submit buy AAPL --quantity 10
# 卖出股票
apcacli order submit sell TSLA --quantity 5
提交限价单:
# 按特定价格买入
apcacli order submit buy MSFT --quantity 10 --limit-price 420
# 按特定价格卖出
apcacli order submit sell NVDA --quantity 20 --limit-price 850
提交高级订单:
# 止损单
apcacli order submit sell AAPL --quantity 10 --stop-price 180
# 止损限价单
apcacli order submit sell TSLA --quantity 5 --stop-price 800 --limit-price 795
# 追踪止损单(百分比)
apcacli order submit sell NVDA --quantity 10 --trail-percent 5
列出所有订单:
apcacli order list
显示所有订单及其状态(未成交、已成交、已取消等)。
获取特定订单详情:
apcacli order get <ORDER_ID>
显示全面的订单信息,包括时间戳、价格和状态。
取消订单:
apcacli order cancel <ORDER_ID>
通过 ID 取消一个待处理订单。
取消所有订单:
apcacli order cancel-all
取消所有未成交订单。
列出所有未平仓持仓:
apcacli position list
显示所有未平仓持仓,包括:
获取特定持仓:
apcacli position get <SYMBOL>
显示特定持仓的详细信息。
平仓:
# 平掉整个持仓
apcacli position close <SYMBOL>
# 部分平仓
apcacli position close <SYMBOL> --quantity 5
平掉所有持仓:
apcacli position close-all
平掉所有未平仓持仓。
列出可用资产:
apcacli asset list
显示所有可交易资产。
获取资产详情:
apcacli asset get <SYMBOL>
显示资产信息,包括交易所、类别和可交易状态。
搜索资产:
apcacli asset search <QUERY>
搜索匹配查询的资产。
检查市场时钟:
apcacli market clock
显示当前市场状态(开放/关闭)、下次开放时间和下次关闭时间。
流式传输账户更新:
apcacli stream account
监控实时账户事件,包括订单更新和成交。
流式传输交易更新:
apcacli stream trades
监控您持仓的实时交易事件。
apcacli order get 验证订单详情apcacli position list 查看盈亏apcacli <command> --help 获取详细选项apcacli market clock简单股票购买:
# 1. 检查账户余额
apcacli account get
# 2. 验证资产可交易
apcacli asset get AAPL
# 3. 检查市场是否开放
apcacli market clock
# 4. 提交市价单
apcacli order submit buy AAPL --value 1000
# 5. 验证持仓
apcacli position list
带监控的限价单:
# 1. 提交限价单
apcacli order submit buy MSFT --quantity 10 --limit-price 420
# 2. 保存返回的 ORDER_ID
# 3. 检查订单状态
apcacli order get <ORDER_ID>
# 4. 如果需要,取消订单
apcacli order cancel <ORDER_ID>
投资组合复查:
# 1. 查看所有持仓
apcacli position list
# 2. 检查账户摘要
apcacli account get
# 3. 复查最近活动
apcacli account activity
带止损的平仓:
# 1. 检查当前持仓
apcacli position get AAPL
# 2. 设置追踪止损以保护利润
apcacli order submit sell AAPL --quantity 10 --trail-percent 5
# 3. 监控订单
apcacli order list
| 任务 | 命令 |
|---|---|
| 查看账户 | apcacli account get |
| 账户活动 | apcacli account activity |
| 买入股票(市价) | apcacli order submit buy SYMBOL --value AMOUNT |
| 买入股票(限价) | apcacli order submit buy SYMBOL --quantity N --limit-price PRICE |
| 卖出股票 | apcacli order submit sell SYMBOL --quantity N |
| 列出所有订单 | apcacli order list |
| 获取订单详情 | apcacli order get ORDER_ID |
| 取消订单 | apcacli order cancel ORDER_ID |
| 取消所有订单 | apcacli order cancel-all |
| 列出持仓 | apcacli position list |
| 获取持仓 | apcacli position get SYMBOL |
| 平仓 | apcacli position close SYMBOL |
| 平掉所有持仓 | apcacli position close-all |
| 列出资产 | apcacli asset list |
| 获取资产信息 | apcacli asset get SYMBOL |
| 检查市场状态 | apcacli market clock |
| 流式传输账户事件 | apcacli stream account |
| 流式传输交易 | apcacli stream trades |
--quantity N - 交易的股票数量--value AMOUNT - 投资的美元金额(用于市价单)--limit-price PRICE - 限价单的限价--stop-price PRICE - 止损单的止损价--trail-percent N - 追踪止损百分比--trail-amount AMOUNT - 追踪止损美元金额市价单 - 立即以当前市场价格执行
apcacli order submit buy AAPL --quantity 10
限价单 - 仅在指定价格或更优价格时执行
apcacli order submit buy AAPL --quantity 10 --limit-price 185
止损单 - 当达到止损价时转换为市价单
apcacli order submit sell AAPL --quantity 10 --stop-price 180
止损限价单 - 当达到止损价时转换为限价单
apcacli order submit sell AAPL --quantity 10 --stop-price 180 --limit-price 179
追踪止损单 - 止损价按指定百分比或金额跟随市场
# 基于百分比
apcacli order submit sell AAPL --quantity 10 --trail-percent 5
# 基于美元金额
apcacli order submit sell AAPL --quantity 10 --trail-amount 10
cargo install apcacli 安装APCA_API_KEY_ID 和 APCA_API_SECRET_KEYAPCA_API_BASE_URL 用于实盘交易# 错误:"Missing APCA_API_KEY_ID"
# 解决方案:导出所需的环境变量
export APCA_API_KEY_ID='your_key'
export APCA_API_SECRET_KEY='your_secret'
# 错误:"apcacli: command not found"
# 解决方案:安装 apcacli
cargo install apcacli
# 验证安装
which apcacli
生成 shell 自动补全以加快命令输入:
# 安装自动补全脚本
cargo run --bin=shell-complete > apcacli.bash
source apcacli.bash
# 现在可以使用 Tab 键补全
apcacli order <TAB>
使用流式传输命令实时监控账户活动:
# 终端 1:监控账户事件
apcacli stream account
# 终端 2:执行交易
apcacli order submit buy AAPL --value 1000
# 观察成交通知出现在终端 1 中
将 apcacli 与 shell 脚本结合,实现自动化策略:
#!/bin/bash
# 示例:每日投资组合检查脚本
echo "=== Daily Portfolio Report ==="
echo ""
echo "Account Status:"
apcacli account get
echo ""
echo "Open Positions:"
apcacli position list
echo ""
echo "Recent Activity:"
apcacli account activity
⚠️ 重要提示 :
apcacli 由 d-e-s-o 创建
基于用于 Alpaca API 交互的 apca Rust crate 构建。
每周安装次数
52
仓库
GitHub 星标数
8
首次出现
2026年3月3日
安全审计
安装于
gemini-cli52
github-copilot52
amp52
cline52
codex52
kimi-cli52
Execute trades and manage portfolios through the apcacli command-line tool for Alpaca's Trading API.
apcacli is a Rust CLI. Install it cross-platform:
brew install rustup
rustup-init -y
source "$HOME/.cargo/env"
cargo install apcacli
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source "$HOME/.cargo/env"
cargo install apcacli
cargo install apcacliexport APCA_API_KEY_ID='your-key-id'
export APCA_API_SECRET_KEY='your-secret-key'
# For live trading (default is paper):
# export APCA_API_BASE_URL='https://api.alpaca.markets'
You are an expert in using apcacli for command-line stock trading. Your goal is to help users trade stocks, ETFs, options, and crypto efficiently through Alpaca's API while emphasizing safety and best practices.
When helping users with trading tasks:
apcacli is a Rust-based CLI for interacting with Alpaca's trading platform. It provides:
Use this skill when the user wants to:
Common trigger phrases:
When NOT to use this skill:
# Using Cargo (Rust package manager)
cargo install apcacli
# Verify installation
apcacli --help
Requirements:
For Paper Trading (Recommended for testing):
export APCA_API_KEY_ID='your_paper_key_id'
export APCA_API_SECRET_KEY='your_paper_secret_key'
# Paper trading is the default, no need to set APCA_API_BASE_URL
For Live Trading:
export APCA_API_BASE_URL='https://api.alpaca.markets'
export APCA_API_KEY_ID='your_live_key_id'
export APCA_API_SECRET_KEY='your_live_secret_key'
Get API Credentials:
View account details:
apcacli account get
Shows account status, cash balance, buying power, equity, and margin information.
View account activity:
apcacli account activity
Displays recent account activity including trades, dividends, and transfers.
Update account configuration:
apcacli account config <options>
Modify account settings (use --help for available options).
Submit a market order:
# Buy with dollar amount
apcacli order submit buy AAPL --value 1000
# Buy specific quantity
apcacli order submit buy AAPL --quantity 10
# Sell shares
apcacli order submit sell TSLA --quantity 5
Submit a limit order:
# Buy at specific price
apcacli order submit buy MSFT --quantity 10 --limit-price 420
# Sell at specific price
apcacli order submit sell NVDA --quantity 20 --limit-price 850
Submit advanced orders:
# Stop order
apcacli order submit sell AAPL --quantity 10 --stop-price 180
# Stop-limit order
apcacli order submit sell TSLA --quantity 5 --stop-price 800 --limit-price 795
# Trailing stop order (percentage)
apcacli order submit sell NVDA --quantity 10 --trail-percent 5
List all orders:
apcacli order list
Shows all orders with their status (open, filled, cancelled, etc.).
Get specific order details:
apcacli order get <ORDER_ID>
Displays comprehensive order information including timestamps, pricing, and status.
Cancel an order:
apcacli order cancel <ORDER_ID>
Cancels a pending order by its ID.
Cancel all orders:
apcacli order cancel-all
Cancels all open orders.
List all open positions:
apcacli position list
Shows all open positions with:
Get specific position:
apcacli position get <SYMBOL>
Displays detailed information for a specific position.
Close a position:
# Close entire position
apcacli position close <SYMBOL>
# Close partial position
apcacli position close <SYMBOL> --quantity 5
Close all positions:
apcacli position close-all
Closes all open positions.
List available assets:
apcacli asset list
Shows all tradeable assets.
Get asset details:
apcacli asset get <SYMBOL>
Displays asset information including exchange, class, and tradability status.
Search for assets:
apcacli asset search <QUERY>
Searches for assets matching the query.
Check market clock:
apcacli market clock
Shows current market status (open/closed), next open time, and next close time.
Stream account updates:
apcacli stream account
Monitors real-time account events including order updates and fills.
Stream trade updates:
apcacli stream trades
Monitors real-time trade events for your positions.
apcacli order get to verify order detailsapcacli position listapcacli <command> --help for detailed optionsapcacli market clock before placing ordersSimple stock purchase:
# 1. Check account balance
apcacli account get
# 2. Verify asset is tradeable
apcacli asset get AAPL
# 3. Check market is open
apcacli market clock
# 4. Submit market order
apcacli order submit buy AAPL --value 1000
# 5. Verify position
apcacli position list
Limit order with monitoring:
# 1. Submit limit order
apcacli order submit buy MSFT --quantity 10 --limit-price 420
# 2. Save the returned ORDER_ID
# 3. Check order status
apcacli order get <ORDER_ID>
# 4. If needed, cancel
apcacli order cancel <ORDER_ID>
Portfolio review:
# 1. View all positions
apcacli position list
# 2. Check account summary
apcacli account get
# 3. Review recent activity
apcacli account activity
Close position with stop loss:
# 1. Check current position
apcacli position get AAPL
# 2. Set trailing stop to protect profits
apcacli order submit sell AAPL --quantity 10 --trail-percent 5
# 3. Monitor the order
apcacli order list
| Task | Command |
|---|---|
| View account | apcacli account get |
| Account activity | apcacli account activity |
| Buy stock (market) | apcacli order submit buy SYMBOL --value AMOUNT |
| Buy stock (limit) | apcacli order submit buy SYMBOL --quantity N --limit-price PRICE |
| Sell stock | apcacli order submit sell SYMBOL --quantity N |
| List all orders | apcacli order list |
--quantity N - Number of shares to trade--value AMOUNT - Dollar amount to invest (for market orders)--limit-price PRICE - Limit price for limit orders--stop-price PRICE - Stop price for stop orders--trail-percent N - Trailing stop percentage--trail-amount AMOUNT - Trailing stop dollar amountMarket Order - Executes immediately at current market price
apcacli order submit buy AAPL --quantity 10
Limit Order - Executes only at specified price or better
apcacli order submit buy AAPL --quantity 10 --limit-price 185
Stop Order - Converts to market order when stop price is reached
apcacli order submit sell AAPL --quantity 10 --stop-price 180
Stop-Limit Order - Converts to limit order when stop price is reached
apcacli order submit sell AAPL --quantity 10 --stop-price 180 --limit-price 179
Trailing Stop - Stop price follows market by specified percentage or amount
# Percentage-based
apcacli order submit sell AAPL --quantity 10 --trail-percent 5
# Dollar-based
apcacli order submit sell AAPL --quantity 10 --trail-amount 10
cargo install apcacliAPCA_API_KEY_ID and APCA_API_SECRET_KEY are requiredAPCA_API_BASE_URL for live trading# Error: "Missing APCA_API_KEY_ID"
# Solution: Export required environment variables
export APCA_API_KEY_ID='your_key'
export APCA_API_SECRET_KEY='your_secret'
# Error: "apcacli: command not found"
# Solution: Install apcacli
cargo install apcacli
# Verify installation
which apcacli
Generate shell completion for faster command entry:
# Install completion script
cargo run --bin=shell-complete > apcacli.bash
source apcacli.bash
# Now you can use tab completion
apcacli order <TAB>
Use streaming commands to monitor account activity in real-time:
# Terminal 1: Monitor account events
apcacli stream account
# Terminal 2: Execute trades
apcacli order submit buy AAPL --value 1000
# Watch the fill notification appear in Terminal 1
Combine apcacli with shell scripts for automated strategies:
#!/bin/bash
# Example: Daily portfolio check script
echo "=== Daily Portfolio Report ==="
echo ""
echo "Account Status:"
apcacli account get
echo ""
echo "Open Positions:"
apcacli position list
echo ""
echo "Recent Activity:"
apcacli account activity
⚠️ IMPORTANT :
apcacli created by d-e-s-o
Built on the apca Rust crate for Alpaca API interactions.
Weekly Installs
52
Repository
GitHub Stars
8
First Seen
Mar 3, 2026
Security Audits
Gen Agent Trust HubFailSocketFailSnykWarn
Installed on
gemini-cli52
github-copilot52
amp52
cline52
codex52
kimi-cli52
Lark Drive API 使用指南:飞书云文档、Wiki、表格 Token 处理与文件管理
48,300 周安装
| Get order details | apcacli order get ORDER_ID |
| Cancel order | apcacli order cancel ORDER_ID |
| Cancel all orders | apcacli order cancel-all |
| List positions | apcacli position list |
| Get position | apcacli position get SYMBOL |
| Close position | apcacli position close SYMBOL |
| Close all positions | apcacli position close-all |
| List assets | apcacli asset list |
| Get asset info | apcacli asset get SYMBOL |
| Check market status | apcacli market clock |
| Stream account events | apcacli stream account |
| Stream trades | apcacli stream trades |