alpaca

A comprehensive n8n community node for Alpaca Trading API providing 15 resources and 80+ operations for stocks, options, and crypto trading with paper trading support.

Package Information

Downloads: 7 weekly / 105 monthly
Latest Version: 1.0.0
Author: Velocity BPA

Documentation

n8n-nodes-alpaca

[Velocity BPA Licensing Notice]

This n8n node is licensed under the Business Source License 1.1 (BSL 1.1).

Use of this node by for-profit organizations in production environments requires a commercial license from Velocity BPA.

For licensing information, visit https://velobpa.com/licensing or contact licensing@velobpa.com.

A comprehensive n8n community node for Alpaca Trading API, providing full access to stocks, options, and crypto trading capabilities. Supports paper trading for testing strategies and live trading for real execution.

n8n
License
Version

Features

  • Complete Trading API Integration: Full access to Alpaca's Trading API v2
  • Stock Trading: Market, limit, stop, stop-limit, and trailing stop orders
  • Options Trading: Options contracts, chains, and market data
  • Crypto Trading: Cryptocurrency trading and market data
  • Paper Trading: Test strategies risk-free with paper trading environment
  • Real-time Market Data: Access to IEX and SIP data feeds
  • Fractional Shares: Support for fractional share trading
  • Extended Hours: Trade during pre-market and after-hours sessions
  • Account Management: Portfolio history, activities, and configuration
  • Trigger Node: Event-driven workflows for orders, positions, and market status

Installation

Community Nodes (Recommended)

  1. Open n8n
  2. Go to Settings > Community Nodes
  3. Search for n8n-nodes-alpaca
  4. Click Install
  5. Restart n8n

Manual Installation

# Navigate to your n8n installation
cd ~/.n8n

# Install the package
npm install n8n-nodes-alpaca

Development Installation

# Clone the repository
git clone https://github.com/Velocity-BPA/n8n-nodes-alpaca.git
cd n8n-nodes-alpaca

# Install dependencies
npm install

# Build the project
npm run build

# Link to n8n (Linux/macOS)
mkdir -p ~/.n8n/custom
ln -s $(pwd) ~/.n8n/custom/n8n-nodes-alpaca

# Restart n8n
n8n start

Credentials Setup

Alpaca API Credentials

To use this node, you need an Alpaca account and API credentials:

  1. Sign up at Alpaca
  2. Go to your dashboard
  3. Navigate to API Keys
  4. Generate new API keys
Field Description
API Key ID Your Alpaca API Key ID (starts with PK for paper, AK for live)
API Secret Key Your Alpaca API Secret Key
Environment paper for testing, live for real trading
Trading Base URL Custom trading API URL (optional)
Data Base URL Custom data API URL (optional)

Important: Use paper trading credentials for testing. Live trading uses real money.

Resources & Operations

Account

  • Get Account: Retrieve account details, buying power, and status
  • Get Account Config: Get account configuration settings
  • Update Account Config: Modify DTBP check, trade confirmations, margin settings
  • Get Portfolio History: Historical portfolio value with customizable timeframes

Orders

  • Create Order: Place market, limit, stop, stop-limit, or trailing stop orders
  • Get All Orders: List all orders with status filters
  • Get Order: Retrieve specific order by ID
  • Get Order by Client ID: Find order by your client order ID
  • Replace Order: Modify existing order (quantity, price, time in force)
  • Cancel Order: Cancel specific order
  • Cancel All Orders: Cancel all open orders

Positions

  • Get All Positions: List all open positions
  • Get Position: Get position for specific symbol
  • Close Position: Close position by symbol (full or partial)
  • Close All Positions: Liquidate all positions
  • Exercise Option: Exercise options position

Assets

  • Get All Assets: List tradable assets with filters
  • Get Asset: Get asset details by symbol or ID
  • Get Option Contracts: Search option contracts
  • Get Option Contract: Get specific option contract details

Watchlists

  • Get All Watchlists: List all watchlists
  • Create Watchlist: Create new watchlist
  • Get Watchlist: Retrieve watchlist by ID or name
  • Update Watchlist: Modify watchlist name and symbols
  • Delete Watchlist: Remove watchlist
  • Add Asset: Add symbol to watchlist
  • Remove Asset: Remove symbol from watchlist

Account Activities

  • Get Activities: Get all account activities
  • Get Activities by Type: Filter activities by type (FILL, TRANS, DIV, etc.)

Calendar

  • Get Calendar: Get market calendar with trading days
  • Get Clock: Get market status and next open/close times

Corporate Actions

  • Get Announcements: Search corporate action announcements
  • Get Announcement: Get specific announcement details

Stock Market Data

  • Get Stock Bars: Historical OHLCV bars (candlesticks)
  • Get Latest Bar: Most recent bar for symbol
  • Get Stock Quotes: Historical bid/ask quotes
  • Get Latest Quote: Most recent quote
  • Get Stock Trades: Historical trade data
  • Get Latest Trade: Most recent trade
  • Get Snapshot: Current market snapshot
  • Get Multiple Snapshots: Snapshots for multiple symbols
  • Get Auctions: Auction data
  • Get Condition Codes: Trade condition code reference
  • Get Exchange Codes: Exchange code reference

Options Market Data

  • Get Option Bars: Historical option bars
  • Get Latest Quotes: Latest option quotes
  • Get Snapshots: Option market snapshots
  • Get Option Chain: Full option chain for underlying
  • Get Option Trades: Historical option trades

Crypto Market Data

  • Get Crypto Bars: Historical crypto bars
  • Get Latest Bars: Latest crypto bars
  • Get Crypto Quotes: Historical crypto quotes
  • Get Latest Quotes: Latest crypto quotes
  • Get Crypto Trades: Historical crypto trades
  • Get Snapshots: Crypto market snapshots
  • Get Orderbook: Crypto orderbook data

Crypto Funding

  • Get Wallets: List crypto funding wallets
  • Get Transfers: List crypto transfers
  • Request Withdrawal: Initiate crypto withdrawal
  • Get Whitelisted Addresses: List whitelisted withdrawal addresses
  • Add Whitelisted Address: Add new whitelisted address
  • Delete Whitelisted Address: Remove whitelisted address
  • Get Gas Estimate: Estimate gas fees

News

  • Get News: Search and retrieve news articles with symbol filters

Screener

  • Get Most Active: Most actively traded stocks
  • Get Top Movers: Top market movers (gainers/losers)

Utility

  • Get Forex Rates: Foreign exchange rates
  • Get Logos: Company logo images

Trigger Node

The Alpaca Trigger node supports polling-based event detection:

Event Description
New Order Triggers when a new order is created
Order Filled Triggers when an order is filled/executed
Order Canceled Triggers when an order is canceled
Position Opened Triggers when a new position is opened
Position Closed Triggers when a position is closed
Price Alert Triggers when price crosses a threshold
Market Open Triggers when market opens
Market Close Triggers when market closes
News Alert Triggers on news for a specific symbol

Usage Examples

Place a Market Order

// Buy 10 shares of AAPL at market price
{
  "resource": "orders",
  "operation": "createOrder",
  "symbol": "AAPL",
  "side": "buy",
  "type": "market",
  "quantity": 10,
  "timeInForce": "day"
}

Get Latest Stock Quote

// Get latest quote for AAPL
{
  "resource": "stockData",
  "operation": "getLatestQuote",
  "symbol": "AAPL"
}

Create a Limit Order with Stop Loss

// Buy TSLA with bracket order
{
  "resource": "orders",
  "operation": "createOrder",
  "symbol": "TSLA",
  "side": "buy",
  "type": "limit",
  "quantity": 5,
  "limitPrice": 200,
  "orderClass": "bracket",
  "takeProfit": 220,
  "stopLoss": 190
}

Alpaca Trading Concepts

Concept Description
Symbol Stock ticker (e.g., AAPL, GOOGL)
Asset ID Alpaca's unique asset identifier
Client Order ID Your custom order identifier
Quantity Number of shares (supports decimals for fractional)
Notional Dollar amount for fractional orders
Time in Force Order duration (day, gtc, opg, cls, ioc, fok)
Extended Hours Trade during pre/post market sessions
Paper Trading Risk-free testing environment

Data Feeds

Feed Description Availability
IEX IEX Exchange data Free tier
SIP Consolidated tape (all exchanges) Paid subscription
OPRA Options pricing data Options subscription

Error Handling

The node provides detailed error messages for common issues:

Code Description
400 Invalid request parameters
401 Invalid API credentials
403 Insufficient permissions or buying power
404 Resource not found
422 Unprocessable entity (validation error)
429 Rate limit exceeded
500 Internal server error

Security Best Practices

  1. Use Paper Trading First: Test all workflows in paper trading before going live
  2. Secure API Keys: Never expose API keys in workflows or logs
  3. Rate Limiting: Respect API rate limits (200 requests/minute for trading)
  4. Order Validation: Always validate order parameters before submission
  5. Error Handling: Implement proper error handling in workflows
  6. Access Control: Use n8n's credentials system for secure key storage

Development

# Install dependencies
npm install

# Build the project
npm run build

# Run tests
npm test

# Run tests with coverage
npm run test:coverage

# Lint code
npm run lint

# Fix linting issues
npm run lint:fix

# Watch mode for development
npm run dev

Author

Velocity BPA

Licensing

This n8n community node is licensed under the Business Source License 1.1.

Free Use

Permitted for personal, educational, research, and internal business use.

Commercial Use

Use of this node within any SaaS, PaaS, hosted platform, managed service,
or paid automation offering requires a commercial license.

For licensing inquiries:
licensing@velobpa.com

See LICENSE, COMMERCIAL_LICENSE.md, and LICENSING_FAQ.md for details.

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Support

Acknowledgments

  • Alpaca for their excellent trading API
  • n8n for the workflow automation platform
  • The n8n community for inspiration and support

Discussion