alpaca

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

What this is

这是什么

☁️ Cloud broker — Alpaca exposes a public REST API, so this runs directly in the Starchild container, no local gateway needed. US equities and ETFs.
Paper and live are fully separated: different key pairs, different hosts (
paper-api.alpaca.markets
vs
api.alpaca.markets
). A paper key physically cannot touch the live account. Live order placement additionally requires the
--confirm-live
flag.
☁️ 云经纪商 — Alpaca提供公开的REST API,因此该工具可直接在Starchild容器中运行,无需本地网关。支持美股与ETF交易。
模拟账户与实盘账户完全分离:不同的密钥对、不同的主机地址
paper-api.alpaca.markets
vs
api.alpaca.markets
)。模拟账户密钥无法访问实盘账户。实盘下单额外需要添加
--confirm-live
参数。

Get your API keys

获取API密钥

  1. Sign up at alpaca.markets (US brokerage; paper trading is free and needs no funding).
  2. Paper keys: log in → switch to Paper Trading (toggle top-left) → Home → "API Keys" panel → Generate New Keys. Copy the Key ID and Secret Key (secret shown once).
  3. Live keys (optional, real money): switch to Live Trading → same API Keys panel → generate. These are a different pair from paper.
  4. Market data: the free IEX feed works out of the box. SIP (full-market) needs a paid data subscription.
  1. alpaca.markets注册(美国经纪商;模拟交易免费,无需入金)。
  2. 模拟密钥:登录 → 切换至Paper Trading(模拟交易)(左上角切换按钮)→ 主页 → "API密钥"面板 → 生成新密钥。复制Key IDSecret Key(密钥仅显示一次)。
  3. 实盘密钥(可选,涉及真实资金):切换至Live Trading(实盘交易) → 同样在API密钥面板 → 生成密钥。这与模拟密钥是不同的密钥对
  4. 市场数据:免费的IEX数据源可直接使用。SIP(全市场)数据源需要付费订阅。

Configure (.env)

配置(.env)

Request via secure input — never paste keys in chat. Variables:
VariableRequiredNotes
ALPACA_API_KEY
yes (paper)paper Key ID
ALPACA_SECRET_KEY
yes (paper)paper Secret
ALPACA_LIVE_API_KEY
only for livelive Key ID
ALPACA_LIVE_SECRET_KEY
only for livelive Secret
ALPACA_FEED
no
iex
(default) or
sip
通过安全输入方式请求密钥——切勿在聊天框中粘贴密钥。变量说明:
变量是否必填备注
ALPACA_API_KEY
是(模拟账户)模拟账户的Key ID
ALPACA_SECRET_KEY
是(模拟账户)模拟账户的密钥
ALPACA_LIVE_API_KEY
仅实盘账户需要实盘账户的Key ID
ALPACA_LIVE_SECRET_KEY
仅实盘账户需要实盘账户的密钥
ALPACA_FEED
iex
(默认)或
sip

Usage

使用方法

pip install alpaca-py
(first run). All commands print JSON. Default profile is
paper
.
bash
python skills/alpaca/scripts/alpaca_cli.py status
python skills/alpaca/scripts/alpaca_cli.py account
python skills/alpaca/scripts/alpaca_cli.py positions
python skills/alpaca/scripts/alpaca_cli.py orders [--executions]
python skills/alpaca/scripts/alpaca_cli.py quote --symbol AAPL
python skills/alpaca/scripts/alpaca_cli.py history --symbol AAPL --period 1d --limit 90
首次运行需执行
pip install alpaca-py
。所有命令均输出JSON格式内容。默认配置为
paper
(模拟账户)。
bash
python skills/alpaca/scripts/alpaca_cli.py status
python skills/alpaca/scripts/alpaca_cli.py account
python skills/alpaca/scripts/alpaca_cli.py positions
python skills/alpaca/scripts/alpaca_cli.py orders [--executions]
python skills/alpaca/scripts/alpaca_cli.py quote --symbol AAPL
python skills/alpaca/scripts/alpaca_cli.py history --symbol AAPL --period 1d --limit 90

place (paper): qty OR notional, market OR limit

下单(模拟账户):指定数量(qty)或金额(notional),市价(market)或限价(limit)

python skills/alpaca/scripts/alpaca_cli.py place --symbol AAPL --side buy --qty 1 --type market python skills/alpaca/scripts/alpaca_cli.py place --symbol AAPL --side buy --notional 500 --type limit --limit-price 180 python skills/alpaca/scripts/alpaca_cli.py cancel --order-id <id>
python skills/alpaca/scripts/alpaca_cli.py place --symbol AAPL --side buy --qty 1 --type market python skills/alpaca/scripts/alpaca_cli.py place --symbol AAPL --side buy --notional 500 --type limit --limit-price 180 python skills/alpaca/scripts/alpaca_cli.py cancel --order-id <id>

live: must add --profile live AND --confirm-live

实盘下单:必须添加--profile live和--confirm-live参数

python skills/alpaca/scripts/alpaca_cli.py --profile live --confirm-live place --symbol AAPL --side buy --qty 1

Periods: `1m 5m 15m 30m 1h 1d 1w 1M`. Alpaca supports fractional `--notional` (dollar amount) orders.
python skills/alpaca/scripts/alpaca_cli.py --profile live --confirm-live place --symbol AAPL --side buy --qty 1

时间周期选项:`1m 5m 15m 30m 1h 1d 1w 1M`。Alpaca支持按金额(`--notional`)进行fractional下单。

Gotchas

注意事项

  • status
    is the health check — it reports SDK install state, key presence, and pings the account. Run it first.
  • Free IEX data can be sparse/delayed off-hours; use
    sip
    only if the account has the paid feed.
  • Live trading is real money. The
    --confirm-live
    gate is intentional; never auto-add it.
  • status
    命令用于健康检查——它会报告SDK安装状态、密钥是否存在,并测试账户连通性。请先运行该命令。
  • 免费的IEX数据在非交易时段可能数据稀疏或延迟;仅当账户已订阅付费数据源时才使用
    sip
  • 实盘交易涉及真实资金。
    --confirm-live
    参数是有意设置的安全门槛;切勿自动添加该参数。