storyclaw-alpaca-trading
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseAlpaca 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
核心规则
- NEVER execute a trade without showing a plan and getting explicit confirmation
- NEVER set up cron jobs without proposing them first
- NEVER make up prices or data — always query real data
- NEVER assume what the user wants to trade — ask first
- 未经展示交易计划并获得用户明确确认,绝不能执行任何交易
- 未经事先提议,绝不能设置定时任务(cron jobs)
- 绝不能编造价格或数据——务必查询真实数据
- 绝不能假设用户想要交易的品种——先询问清楚
Multi-User Support
多用户支持
Each user has their own :
credentials/{USER_ID}.jsonjson
{
"apiKey": "YOUR_KEY",
"apiSecret": "YOUR_SECRET",
"baseUrl": "https://paper-api.alpaca.markets",
"dataUrl": "https://data.alpaca.markets"
}To switch to real trading, change to .
baseUrlhttps://api.alpaca.marketsOr set and env vars.
ALPACA_API_KEYALPACA_API_SECRET每位用户拥有独立的文件:
credentials/{USER_ID}.jsonjson
{
"apiKey": "YOUR_KEY",
"apiSecret": "YOUR_SECRET",
"baseUrl": "https://paper-api.alpaca.markets",
"dataUrl": "https://data.alpaca.markets"
}若要切换至实盘交易,将修改为。
baseUrlhttps://api.alpaca.markets或者设置环境变量和。
ALPACA_API_KEYALPACA_API_SECRETFirst-Time User Flow
新用户操作流程
- Check credentials:
USER_ID=$TELEGRAM_USER_ID node {baseDir}/scripts/trading.js check - Ask what they want to trade (stocks vs crypto, symbols, amount, risk)
- Propose a concrete plan — WAIT FOR CONFIRMATION
- Execute only after user confirms
- 检查凭证:
USER_ID=$TELEGRAM_USER_ID node {baseDir}/scripts/trading.js check - 询问用户交易需求(股票或加密货币、交易标的代码、数量、风险偏好)
- 提出具体交易计划——等待用户确认
- 仅在用户确认后执行交易
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/1Abash
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 indicatorbash
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 # Sellbash
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 reversionbash
node {baseDir}/scripts/trading.js strategy-rsi AAPL # RSI均值回归策略RSI < 30 + no position → BUY; RSI > 70 + has position → SELL
规则:RSI < 30且无持仓→买入;RSI > 70且有持仓→卖出
undefinedundefinedFeatures
功能特性
- 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
配置步骤
- Sign up at https://app.alpaca.markets/brokerage/new-account
- Generate API key + secret (Paper Trading section)
- Create or set env vars
credentials/{USER_ID}.json
- 前往https://app.alpaca.markets/brokerage/new-account注册账户
- 生成API密钥与密钥密码(在模拟交易板块)
- 创建文件或设置环境变量
credentials/{USER_ID}.json
API Limits
API限制
| Tier | Calls/min | Data delay |
|---|---|---|
| Free | 200 | 15 min |
| Unlimited | Unlimited | Real-time |
| 套餐层级 | 每分钟调用次数 | 数据延迟 |
|---|---|---|
| 免费版 | 200次 | 15分钟 |
| 无限版 | 无限制 | 实时 |