Alpaca Trading Backtest
alpacahq/alpaca-skills
Execute deterministic, reproducible historical backtests from a start date, end date, and strategy concept using the Alpaca CLI plus agent-written workspace code.
Trading API de Alpaca: órdenes, posiciones, cuenta. An agent skill from gauss314/skills.
$ npx skills add gauss314/skills --skill alpaca-trading -a claude-codeProject install by default; add -g for ~/.claude/skills/.
$ gh skill install gauss314/skills alpaca-trading --agent claude-codeProject scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).
$ git clone --depth 1 https://github.com/gauss314/skills.git skills-src && mkdir -p .claude/skills && cp -r skills-src/skills/alpaca-trading .claude/skills/alpaca-trading && rm -rf skills-srcUse ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.
Claude Code skills documentation · loads skills from .claude/skills/
Install the "alpaca-trading" agent skill from https://github.com/gauss314/skills/tree/main/skills/alpaca-trading into .claude/skills/alpaca-trading/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "alpaca-trading", then confirm the skill loads.Claude Code copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$skill-installer install https://github.com/gauss314/skills/tree/main/skills/alpaca-tradingType this inside Codex. $skill-installer <name> installs a curated skill from openai/skills. The installer writes to $CODEX_HOME/skills (default ~/.codex/skills). Restart Codex if the skill does not show up.
$ npx skills add gauss314/skills --skill alpaca-trading -a codexProject install goes to .agents/skills/; add -g for ~/.codex/skills/.
$ gh skill install gauss314/skills alpaca-trading --agent codexProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/gauss314/skills.git skills-src && mkdir -p .agents/skills && cp -r skills-src/skills/alpaca-trading .agents/skills/alpaca-trading && rm -rf skills-srcUse ~/.agents/skills/ instead of .agents/skills for a personal install.
Codex skills documentation · loads skills from .agents/skills/
Install the "alpaca-trading" agent skill from https://github.com/gauss314/skills/tree/main/skills/alpaca-trading into .agents/skills/alpaca-trading/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "alpaca-trading", then confirm the skill loads.Codex copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$ npx skills add gauss314/skills --skill alpaca-trading -a cursorProject install goes to .agents/skills/; add -g for ~/.cursor/skills/.
$ gh skill install gauss314/skills alpaca-trading --agent cursorProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/gauss314/skills.git skills-src && mkdir -p .cursor/skills && cp -r skills-src/skills/alpaca-trading .cursor/skills/alpaca-trading && rm -rf skills-srcUse ~/.cursor/skills/ instead of .cursor/skills for a personal install.
Cursor skills documentation · loads skills from .cursor/skills/, .agents/skills/, .claude/skills/, .codex/skills/
Install the "alpaca-trading" agent skill from https://github.com/gauss314/skills/tree/main/skills/alpaca-trading into .cursor/skills/alpaca-trading/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "alpaca-trading", then confirm the skill loads.Cursor copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$ gemini skills install https://github.com/gauss314/skills.git --path skills/alpaca-trading--scope user (default) or --scope workspace; --path is the subfolder of the repo that holds the skill; --consent skips the security confirmation prompt.
$ npx skills add gauss314/skills --skill alpaca-trading -a gemini-cliProject install goes to .agents/skills/; add -g for ~/.gemini/skills/.
$ gh skill install gauss314/skills alpaca-trading --agent gemini-cliProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/gauss314/skills.git skills-src && mkdir -p .gemini/skills && cp -r skills-src/skills/alpaca-trading .gemini/skills/alpaca-trading && rm -rf skills-srcUse ~/.gemini/skills/ instead of .gemini/skills for a personal install, then run /skills reload.
Gemini CLI skills documentation · loads skills from .gemini/skills/, .agents/skills/
Install the "alpaca-trading" agent skill from https://github.com/gauss314/skills/tree/main/skills/alpaca-trading into .gemini/skills/alpaca-trading/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "alpaca-trading", then confirm the skill loads.Gemini CLI copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$ gh skill install gauss314/skills alpaca-tradingInstalls for Copilot at project scope by default; add --scope user for a personal install. Preview a skill first with gh skill preview. Needs GitHub CLI 2.90.0 or later (public preview).
$ npx skills add gauss314/skills --skill alpaca-trading -a github-copilotProject install goes to .agents/skills/; add -g for ~/.copilot/skills/.
$ git clone --depth 1 https://github.com/gauss314/skills.git skills-src && mkdir -p .github/skills && cp -r skills-src/skills/alpaca-trading .github/skills/alpaca-trading && rm -rf skills-srcUse ~/.copilot/skills/ instead of .github/skills for a personal install. Commit .github/skills so cloud agent and code review can use it.
GitHub Copilot skills documentation · loads skills from .github/skills/, .claude/skills/, .agents/skills/
Install the "alpaca-trading" agent skill from https://github.com/gauss314/skills/tree/main/skills/alpaca-trading into .github/skills/alpaca-trading/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "alpaca-trading", then confirm the skill loads.GitHub Copilot copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$ npx skills add gauss314/skills --skill alpaca-trading -a opencodeOpenCode documents no install command of its own. Project install goes to .agents/skills/; add -g for ~/.config/opencode/skills/.
$ gh skill install gauss314/skills alpaca-trading --agent opencodeProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/gauss314/skills.git skills-src && mkdir -p .opencode/skills && cp -r skills-src/skills/alpaca-trading .opencode/skills/alpaca-trading && rm -rf skills-srcUse ~/.config/opencode/skills/ instead of .opencode/skills for a personal install.
OpenCode skills documentation · loads skills from .opencode/skills/, .claude/skills/, .agents/skills/
Install the "alpaca-trading" agent skill from https://github.com/gauss314/skills/tree/main/skills/alpaca-trading into .opencode/skills/alpaca-trading/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "alpaca-trading", then confirm the skill loads.OpenCode copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
alpaca-tradingTrading API de Alpaca: órdenes, posiciones, cuenta. An agent skill from gauss314/skills.
Alpaca Trading is an agent skill from gauss314/skills. Trading API de Alpaca: órdenes, posiciones, cuenta. Paper trading y live trading de acciones, crypto y opciones.
Its SKILL.md is about 2.4k tokens, which your agent loads only when the skill is triggered. The skill folder holds 4 other files, including scripts (for example `scripts/check_account.py`, `scripts/check_positions.py` and `scripts/place_order.py`).
It sits in Business, Finance & HR, covering Trading and backtesting. It works with Alpaca. The repository describes itself as: Financial market data consumption skills for claude code and AI agents. The licence is MIT.
3 steps, taken from the first numbered list in SKILL.md.
Read from SKILL.md and the folder at commit 5156f81. It shows what the files ask for, not the result of running them.
Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.
From allowed-tools in the SKILL.md frontmatter.
Ships 3 files in scripts/ (Python), which the agent can run.
Shell commands in SKILL.md call:
pythonpipFrom the folder's file list and the shell code blocks in SKILL.md.
Hosts in commands or code, which the agent is likely to contact:
paper-api.alpaca.marketsapi.alpaca.marketsAlso links to:
docs.alpaca.marketsFrom URLs in SKILL.md, links to its own repository left out.
Names these keys or tokens, usually read from environment variables:
API_KEYSECRET_KEYAPCA_API_KEY_IDAPCA_API_SECRET_KEYFrom names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.
Alpaca Trading loads about 2.4k tokens when it runs. Until then it costs about 32 tokens; SKILL.md has 357 words of instructions outside code blocks.
Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.
The automated check found no risky patterns in SKILL.md.
Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); the scripts in this folder are not scanned.
The full file from gauss314/skills at commit 5156f81, republished under its MIT licence (© gauss314). 357 words, ~2,390 tokens.
.claude/skills/alpaca-trading/SKILL.md (or your agent's skills folder). This skill also uses 3 other files; get the full folder from GitHub.API para trading de acciones, crypto y opciones. Soporta paper trading (gratis) y live trading.
Base URLs:
https://paper-api.alpaca.marketshttps://api.alpaca.marketspip install alpaca-pyDocs: docs.alpaca.markets
import os
from alpaca.trading.client import TradingClient
# Para paper trading
API_KEY = os.getenv("APCA_API_KEY_ID")
SECRET_KEY = os.getenv("APCA_API_SECRET_KEY")
BASE_URL = "https://paper-api.alpaca.markets" # Paper
# Para live trading
# BASE_URL = "https://api.alpaca.markets"
client = TradingClient(API_KEY, SECRET_KEY, paper=True)⚠️ NUNCA hardcodear keys. Usar variables de entorno.
| API | Límite |
|---|---|
| Orders | 200 requests/min |
| Account/Positions | 200 requests/min |
| Account Activities | 200 requests/min |
account = client.get_account()
print(f"Buying Power: ${account.buying_power}")
print(f"Cash: ${account.cash}")
print(f"Portfolio Value: ${account.portfolio_value}")
print(f"Status: {account.status}")from alpaca.trading.requests import AccountConfigurationsRequest
config_request = AccountConfigurationsRequest(
trade_confirmation_email=True,
susi_transfer_email=True
)
client.update_account_configuration(config_request)from alpaca.trading.requests import GetAssetsRequest
from alpaca.trading.enums import AssetClass, AssetStatus
request = GetAssetsRequest(
asset_class=AssetClass.US_EQUITY,
status=AssetStatus.ACTIVE
)
assets = client.get_all_assets(request)
# Filtrar symbols tradables
tradable = [a for a in assets if a.tradable]
print(f"Assets tradables: {len(tradable)}")asset = client.get_asset("AAPL")
print(f"AAPL tradable: {asset.tradable}")
print(f"AAPL class: {asset.asset_class}")| Tipo | Descripción |
|---|---|
market | Ejecuta al precio actual |
limit | Precio máximo (buy) o mínimo (sell) |
stop | Activa orden de mercado cuando alcanza stop_price |
stop_limit | Combina stop + limit |
trailing_stop | Stop relativo al precio |
| TIF | Descripción |
|---|---|
day | Solo para día actual |
gtc | Good Till Cancelled |
opg | Open at market open |
cls | Close at market close |
ioc | Immediate Or Cancel |
fok | Fill Or Kill |
from alpaca.trading.requests import MarketOrderRequest
from alpaca.trading.enums import OrderSide, TimeInForce
order_request = MarketOrderRequest(
symbol="AAPL",
qty=10,
side=OrderSide.BUY,
time_in_force=TimeInForce.DAY
)
order = client.submit_order(order_request)
print(f"Order ID: {order.id}")
print(f"Status: {order.status}")from alpaca.trading.requests import LimitOrderRequest
order_request = LimitOrderRequest(
symbol="AAPL",
qty=10,
side=OrderSide.BUY,
limit_price=150.00, # Máximo a pagar
time_in_force=TimeInForce.GTC
)
order = client.submit_order(order_request)from alpaca.trading.requests import StopOrderRequest
order_request = StopOrderRequest(
symbol="AAPL",
qty=10,
side=OrderSide.SELL,
stop_price=145.00, # Vende cuando caiga a este precio
time_in_force=TimeInForce.GTC
)# Todas las órdenes abiertas
open_orders = client.get_orders(status="open")
print(f"Órdenes abiertas: {len(open_orders)}")
# Órdenes filladas hoy
from datetime import datetime
filled_orders = client.get_orders(
status="fill",
start=datetime(2024, 1, 15)
)
# Orden por ID
order = client.get_order_by_id(order_id)# Cancelar una orden
client.cancel_order(order_id)
# Cancelar todas las órdenes abiertas
client.cancel_orders()from alpaca.trading.requests import ReplaceOrderRequest
replace_request = ReplaceOrderRequest(
limit_price=155.00, # Nuevo precio límite
qty=15 # Nueva cantidad
)
client.replace_order(order_id, replace_request)positions = client.get_all_positions()
for pos in positions:
print(f"{pos.symbol}: {pos.qty} shares")
print(f" Avg Entry: ${pos.avg_entry_price}")
print(f" Market Value: ${pos.market_value}")
print(f" P/L: ${pos.unrealized_pl}")position = client.get_position("AAPL")
print(f"AAPL: {position.qty} shares @ ${position.avg_entry_price}")# Cerrar toda la posición
client.close_position("AAPL")
# Cerrar posición parcialmente (qty=5)
client.close_position("AAPL", qty=5)client.close_all_positions()| Level | Descripción |
|---|---|
| 0 | Sin trading de opciones |
| 1 | Covered calls, cash-secured puts |
| 2 | Buy/sell calls y puts |
| 3 | Spreads |
from alpaca.trading.requests import GetOptionContractsRequest
from datetime import datetime, timedelta
request = GetOptionContractsRequest(
underlying_symbols=["AAPL"],
expiration_date_gte=datetime.now().strftime("%Y-%m-%d"),
expiration_date_lte=(datetime.now() + timedelta(days=30)).strftime("%Y-%m-%d"),
strike_price_gte=100,
strike_price_lte=200,
limit=100
)
contracts = client.get_option_contracts(request)
contract = contracts.option_contracts[0]
# Trade con contract ID
order_request = MarketOrderRequest(
symbol=contract.id, # Usar ID del contract
qty=1,
side=OrderSide.BUY,
time_in_force=TimeInForce.DAY
)# Ejercer una posición de opción
client.exercise_options(position_id)from alpaca.trading.enums import AssetClass
crypto_assets = client.get_all_assets(asset_class=AssetClass.CRYPTO)
crypto = [a for a in crypto_assets if a.tradable]
print(f"Crypto tradables: {[a.symbol for a in crypto[:10]]}")order_request = MarketOrderRequest(
symbol="BTC/USD",
qty=0.1, # Fracciones permitidas
side=OrderSide.BUY,
time_in_force=TimeInForce.GTC
)
client.submit_order(order_request)clock = client.get_clock()
print(f"Market open: {clock.is_open}")
print(f"Next open: {clock.next_open}")
print(f"Next close: {clock.next_close}")if clock.is_open:
print("Mercado abierto - puedes tradear")
else:
print("Mercado cerrado")from datetime import datetime
history = client.get_account_portfolio_history(
date_start=datetime(2024, 1, 1),
timeframe="1D"
)
print(f"Equity: {history.equity}")
print(f"Profit/Loss: {history.profit_loss}")from alpaca.trading.requests import CreateWatchlistRequest
# Crear watchlist
watchlist = client.create_watchlist(
CreateWatchlistRequest(name="Tech Stocks")
)
# Agregar símbolo
client.add_to_watchlist(watchlist.id, "AAPL")
# Obtener watchlists
watchlists = client.get_watchlists()from alpaca.trading.stream import TradingStream
async def handle_trade_update(data):
print(f"Update: {data}")
stream = TradingStream(API_KEY, SECRET_KEY, paper=True)
stream.subscribe_trade_updates(handle_trade_update)
stream.run()Ver ./scripts/:
# Ver cuenta
python ./scripts/check_account.py
# Ver posiciones
python ./scripts/check_positions.py
# Enviar orden de prueba
python ./scripts/place_order.py --symbol AAPL --qty 10 --side buy --type market| Error | Causa | Solución |
|---|---|---|
| 403 Forbidden | Keys inválidas | Verificar API keys |
| 403 | Sin permisos | Habilitar en dashboard |
| 400 Bad Request | Parámetros inválidos | Ver docs de orden |
| 403 Trading Halted | Trading pausado | Esperar o verificar |
| 403 No Buying Power | Sin fondos | Depositar dinero |
| 422 | Symbol no tradable | Verificar symbol |
| 429 Too Many Requests | Rate limit | Implementar backoff |
| Aspecto | Paper | Live |
|---|---|---|
| URL | paper-api.alpaca.markets | api.alpaca.markets |
| Dinero real | ❌ No | ✅ Sí |
| Órdenes reales | ❌ Simuladas | ✅ Reales |
| Datos de mercado | ✅ Reales | ✅ Reales |
| Para testing | ✅ Ideal | ❌ No |
Siempre probar en paper primero.
© gauss314, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file
SKILL.md and 3 other files (scripts) in skills/alpaca-trading of gauss314/skills.
Open the folder on GitHubat commit 5156f81
Alpaca Trading next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.
| Skill | Stars | Used in | Tokens | Auto-check | Licence | Repo updated |
|---|---|---|---|---|---|---|
| Alpaca Trading this skillgauss314/skills | 248 | — | ~2.4k | Automated safety check: Pass | MIT | |
| Alpaca Trading Backtestalpacahq/alpaca-skills | 154 | — | ~3.9k | Automated safety check: Pass | Apache-2.0 | |
| Alpaca Trading Paper Tradingalpacahq/alpaca-skills | 154 | — | ~11k | Automated safety check: Pass | Apache-2.0 | |
| Alpaca Trading Paper Trading CLIalpacahq/alpaca-skills | 154 | — | ~9k | Automated safety check: Pass | Apache-2.0 | |
| Alpaca Trading Paper Trading MCPalpacahq/alpaca-skills | 154 | — | ~11k | Automated safety check: Pass | Apache-2.0 | |
| Tushare Datazillionare/zillionare | 322 | 2 repos | ~2.3k | Automated safety check: Pass | None |
alpacahq/alpaca-skills
Execute deterministic, reproducible historical backtests from a start date, end date, and strategy concept using the Alpaca CLI plus agent-written workspace code.
alpacahq/alpaca-skills
Preview, submit, inspect, and manage Alpaca paper-trading orders across US equities, options, and crypto.
alpacahq/alpaca-skills
Preview, submit, inspect, and manage Alpaca paper-trading orders using the Alpaca CLI.
alpacahq/alpaca-skills
Preview, submit, inspect, and manage Alpaca paper-trading orders using the Alpaca Trading API MCP Server.
zillionare/zillionare
面向中文自然语言的 Tushare 数据研究技能。用于把“看看这只股票最近怎么样”“帮我查财报趋势”“最近哪个板块最强”“北向资金在买什么”“给我导出一份行情数据”这类请求,转成可执行的数据获取、清洗、对比、筛选、导出与简要分析流程。适用于 A 股、指数、ETF/基金、财务、估值、资金流、公告新闻、板块概念与宏观数据等研究场景。
atilaahmettaner/tradingview-mcp
AI Trading Intelligence — live prices, 30+ technical indicators, backtesting (6 strategies), walk-forward overfitting detection, trade logs, equity curves, licensed news sentiment (Marketaux), and…
gauss314/skills
Academic backtesting framework for quantitative research. An agent skill from gauss314/skills.
gauss314/skills
Datos de Google Finance via batchexecute (API RPC interna sin auth ni API key).
gauss314/skills
History of Market (historyofmarket.com) — API publica con 88 datasets historicos de indices US desde 1871.
gauss314/skills
Datos macro y sociales de Argentina via la API oficial Series de Tiempo del Estado (apis.datos.gob.ar/series).
gauss314/skills
Morningstar Screener via API JSON publica: descarga masiva de 53 universes (102K+ listings, 39 paises, NYSE/Nasdaq/BCBA/etc) con 33 campos (precio, market cap, ratios, retornos…
gauss314/skills
Pricing completo de opciones europeas y americanas. An agent skill from gauss314/skills.
Works with
Categories
Trading API de Alpaca: órdenes, posiciones, cuenta. An agent skill from gauss314/skills. Alpaca Trading is an agent skill from gauss314/skills. Trading API de Alpaca: órdenes, posiciones, cuenta.
Alpaca Trading fits situations like: tasks that involve Trading and backtesting.
Run `npx skills add gauss314/skills --skill alpaca-trading -a claude-code`. Or copy the skill folder (skills/alpaca-trading in gauss314/skills) into .claude/skills/alpaca-trading in your project. Claude Code loads it when a task matches its description.
Run `npx skills add gauss314/skills --skill alpaca-trading -a codex`. Or copy the skill folder (skills/alpaca-trading in gauss314/skills) into .agents/skills/alpaca-trading in your project. Codex loads it when a task matches its description.
Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add gauss314/skills --skill alpaca-trading -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/alpaca-trading, .gemini/skills/alpaca-trading, .github/skills/alpaca-trading and .opencode/skills/alpaca-trading in your project.
Going by SKILL.md and its folder, Alpaca Trading needs Python for the scripts in its folder, the command-line tools its instructions call (python and pip) and credentials named API_KEY, SECRET_KEY, APCA_API_KEY_ID and APCA_API_SECRET_KEY. Our summary lists: Python 3; A credential in API_KEY; A credential in SECRET_KEY.
SKILL.md names 3 domains. In commands or code: paper-api.alpaca.markets and api.alpaca.markets; the agent is likely to contact these when it follows the instructions. As links in the text: docs.alpaca.markets. This is read from the text; nothing was executed.
Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. The check reads SKILL.md only: the scripts in the folder are not scanned, so read them before running anything.
Alpaca Trading is published under the MIT licence (declared in SKILL.md). It allows redistribution, so the full SKILL.md is shown on this page.
About 2.4k tokens (SKILL.md is roughly 9.6k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.
Skills that share tags, products or a category with Alpaca Trading: Alpaca Trading Backtest (alpacahq/alpaca-skills, 154 stars), Alpaca Trading Paper Trading (alpacahq/alpaca-skills, 154 stars), Alpaca Trading Paper Trading CLI (alpacahq/alpaca-skills, 154 stars) and Alpaca Trading Paper Trading MCP (alpacahq/alpaca-skills, 154 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.
gauss314 (a GitHub user) maintains it in gauss314/skills, which has 248 GitHub stars. The repository holds 32 skills in this directory. The repository was last updated on June 14, 2026.
Source: gauss314/skills on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.