storyclaw-alpaca-trading

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Alpaca Trading - US Stock & Crypto Trading

Alpaca交易 - 美股与加密货币交易

Trade US stocks and crypto via Alpaca API. Supports both paper trading (simulated, free) and real trading.
通过Alpaca API交易美股与加密货币,同时支持模拟交易(paper trading,免费)实盘交易

Critical Rules

核心规则

  1. NEVER execute a trade without showing a plan and getting explicit confirmation
  2. NEVER set up cron jobs without proposing them first
  3. NEVER make up prices or data — always query real data
  4. NEVER assume what the user wants to trade — ask first
  1. 未经展示交易计划并获得用户明确确认,绝不能执行任何交易
  2. 未经事先提议,绝不能设置定时任务(cron jobs)
  3. 绝不能编造价格或数据——务必查询真实数据
  4. 绝不能假设用户想要交易的品种——先询问清楚

Multi-User Support

多用户支持

Each user has their own
credentials/{USER_ID}.json
:
json
{
  "apiKey": "YOUR_KEY",
  "apiSecret": "YOUR_SECRET",
  "baseUrl": "https://paper-api.alpaca.markets",
  "dataUrl": "https://data.alpaca.markets"
}
To switch to real trading, change
baseUrl
to
https://api.alpaca.markets
.
Or set
ALPACA_API_KEY
and
ALPACA_API_SECRET
env vars.
每位用户拥有独立的
credentials/{USER_ID}.json
文件:
json
{
  "apiKey": "YOUR_KEY",
  "apiSecret": "YOUR_SECRET",
  "baseUrl": "https://paper-api.alpaca.markets",
  "dataUrl": "https://data.alpaca.markets"
}
若要切换至实盘交易,将
baseUrl
修改为
https://api.alpaca.markets
或者设置环境变量
ALPACA_API_KEY
ALPACA_API_SECRET

First-Time User Flow

新用户操作流程

  1. Check credentials:
    USER_ID=$TELEGRAM_USER_ID node {baseDir}/scripts/trading.js check
  2. Ask what they want to trade (stocks vs crypto, symbols, amount, risk)
  3. Propose a concrete plan — WAIT FOR CONFIRMATION
  4. Execute only after user confirms
  1. 检查凭证:
    USER_ID=$TELEGRAM_USER_ID node {baseDir}/scripts/trading.js check
  2. 询问用户交易需求(股票或加密货币、交易标的代码、数量、风险偏好)
  3. 提出具体交易计划——等待用户确认
  4. 仅在用户确认后执行交易

Commands

命令列表

Account & Positions

账户与持仓

bash
node {baseDir}/scripts/trading.js check              # Check config
node {baseDir}/scripts/trading.js account            # Balance
node {baseDir}/scripts/trading.js positions          # Current holdings
node {baseDir}/scripts/trading.js history            # Order history
node {baseDir}/scripts/trading.js portfolio-history  # Equity curve (1W default)
node {baseDir}/scripts/trading.js portfolio-history 1M  # 1D/1W/1M/3M/1A
bash
node {baseDir}/scripts/trading.js check              # 检查配置
node {baseDir}/scripts/trading.js account            # 查询账户余额
node {baseDir}/scripts/trading.js positions          # 查询当前持仓
node {baseDir}/scripts/trading.js history            # 查询订单历史
node {baseDir}/scripts/trading.js portfolio-history  # 查询权益曲线(默认1周)
node {baseDir}/scripts/trading.js portfolio-history 1M  # 支持1D/1W/1M/3M/1A周期

Market Data

市场数据

bash
node {baseDir}/scripts/trading.js quote AAPL         # Real-time quote
node {baseDir}/scripts/trading.js bars AAPL 30       # Price history
node {baseDir}/scripts/trading.js rsi AAPL 14        # RSI indicator
bash
node {baseDir}/scripts/trading.js quote AAPL         # 查询实时报价
node {baseDir}/scripts/trading.js bars AAPL 30       # 查询价格历史
node {baseDir}/scripts/trading.js rsi AAPL 14        # 计算RSI指标

Trading

交易操作

bash
node {baseDir}/scripts/trading.js buy AAPL 10        # Buy (market order)
node {baseDir}/scripts/trading.js sell AAPL 10       # Sell
bash
node {baseDir}/scripts/trading.js buy AAPL 10        # 买入(市价单)
node {baseDir}/scripts/trading.js sell AAPL 10       # 卖出

Strategy

策略执行

bash
node {baseDir}/scripts/trading.js strategy-rsi AAPL  # RSI mean reversion
bash
node {baseDir}/scripts/trading.js strategy-rsi AAPL  # RSI均值回归策略

RSI < 30 + no position → BUY; RSI > 70 + has position → SELL

规则:RSI < 30且无持仓→买入;RSI > 70且有持仓→卖出

undefined
undefined

Features

功能特性

  • US Stocks & Crypto (AAPL, TSLA, BTC, ETH, and more)
  • Paper OR real trading (depends on credentials)
  • Real-time quotes (15-min delayed on free tier)
  • Market orders, technical indicators (RSI)
  • Market hours: Stocks 9:30-16:00 ET Mon-Fri; Crypto 24/7
  • 支持美股与加密货币交易(涵盖AAPL、TSLA、BTC、ETH等标的)
  • 可切换模拟交易或实盘交易(取决于凭证配置)
  • 实时报价(免费版延迟15分钟)
  • 支持市价单、技术指标(RSI)
  • 交易时间:美股为美东时间周一至周五9:30-16:00;加密货币全天24小时交易

Setup

配置步骤

  1. Sign up at https://app.alpaca.markets/brokerage/new-account
  2. Generate API key + secret (Paper Trading section)
  3. Create
    credentials/{USER_ID}.json
    or set env vars
  1. 前往https://app.alpaca.markets/brokerage/new-account注册账户
  2. 生成API密钥与密钥密码(在模拟交易板块)
  3. 创建
    credentials/{USER_ID}.json
    文件或设置环境变量

API Limits

API限制

TierCalls/minData delay
Free20015 min
UnlimitedUnlimitedReal-time
套餐层级每分钟调用次数数据延迟
免费版200次15分钟
无限版无限制实时