Today, we’re releasing Alpaca’s CLI (command-line interface) for Trading API, providing access to 108 trading functions across stocks, options, crypto, market data, and account management, available directly from your terminal and AI agent. This launch, in combination with the recent updates to Alpaca’s MCP Server, makes it easier for traders to leverage Alpaca’s infrastructure in agentic trading.
Key Features of the Alpaca CLI:
- Extensive Capabilities: Provides access to 108 trading functions across stocks, options, crypto, market data, and account management.
- Simplified Onboarding: Turns the Trading API into a first-class terminal interface with explicit commands and structured output, eliminating the need for hand-written HTTP requests. Authentication for paper trading and market data uses OAuth, requiring no API keys, config files, or environment variables to get started. You can execute your first paper trade in just three commands: install, login, submit.
- Structured Automation & Composability: Every API command returns structured JSON by default, with flags like
--csvand--jqavailable for filtering and reshaping the output. This allows the output to pipe natively into other tools, making it ideal for shell scripts, cron jobs, and CI pipelines. - Spec-Driven Reliability: The CLI is generated directly from Alpaca’s public OpenAPI specifications, ensuring the interface, commands, flags, and descriptions are consistent and that the tool will automatically reflect updates to the Trading API.
- Designed for AI Agents: Connect an agent to the CLI to empower it to place trades, query data, and manage your account with short, explicit commands.
Set Up Alpaca’s CLI in Three Simple Commands
Alpaca’s CLI turns the Trading API into a first-class terminal interface: explicit commands, typed flags, structured output, and no hand-written HTTP requests. With the CLI, you can submit orders, pull market data, manage positions, and inspect your account the same way you use git or curl – from a shell, a script, a CI pipeline, or an AI agent session.
You can go from opening an account to placing your first paper trade in just three commands: install, login, submit. Authentication happens via OAuth for market data and paper trading with no API keys to generate, no config files to write, and no environment variables to set.
go install github.com/alpacahq/cli/cmd/alpaca@latest
# or
# brew install alpacahq/tap/cli
alpaca profile login
alpaca order submit --symbol AAPL --side buy --qty 10 --type marketNote: The release of the CLI today is a preview under active development. Expect breaking changes as we iterate and respond to community feedback.
The Capabilities of Alpaca’s CLI
With the CLI, you can check your account, place an order, pull a quote, and export your positions into a CSV file, all from the terminal:
alpaca account get
alpaca order submit --symbol AAPL --side buy --qty 1 --type market
alpaca data latest-quote --symbol AAPL
alpaca position list --csv > positions.csvEvery API command returns structured JSON by default, with --csv and --jq for filtering and reshaping output.
alpaca account get
alpaca order submit --symbol AAPL --side buy --qty 1 --type market
alpaca data latest-quote --symbol AAPL
alpaca position list --csv > positions.csvA few ways it can be integrated into your workflow:
- Exploring the API: Authenticate with OAuth, browse commands with
--help, and start making calls. No SDK setup, no boilerplate. - Shell Scripts and Automation: Pipe JSON output into
jq, chain commands together, and run them on a schedule with cron. - CI Pipelines: Check positions, cancel open orders, or validate account state as part of a GitHub Actions workflow.
- AI Agent Sessions: Connect an agent to the CLI, empowering it to place trades, query data, and manage your account with short, explicit commands.
Why We Built Alpaca’s CLI
Alpaca’s Trading API covers multiple asset classes, order types, and data sources. The CLI gives that API surface a structured way to access all of it: named commands with clear parameters, built-in help, per-command schemas, and JSON output you can pipe into scripts or other tools.
The recent release of Alpaca’s MCP Server V2 achieves a similar goal. Both tools are generated from Alpaca’s OpenAPI specifications, and both provide an explicit interface in front of the API. Where they differ is in how and when they can be used (more on that below).
How Alpaca’s CLI Was Built
The CLI started as an experiment: how quickly can someone go from signing up for Alpaca to placing their first API call? The answer was to let traders interact with Alpaca’s Trading API directly from the terminal and agentic tools like Cursor and Claude, without assembling HTTP requests by hand.
The earliest iteration of the CLI had hard-coded commands for each endpoint. That approach was replaced almost immediately with code generation from OpenAPI specs. Rather than maintaining a hard-coded command per endpoint, a purpose-built CLI generator reads the specs and generates commands, flags, type definitions, and response schemas from it.
Alpaca’s OpenAPI specs are public, meaning you could generate your own tooling from them. Our CLI exists so you don’t have to. Simply install it and start making API calls.
The Spec Is The Source of Truth
Building the CLI had an unexpected side effect: it surfaced discrepancies in our own OpenAPI specification.
When every command name, flag, description, and help string is derived from the spec, spec quality directly affects product quality. In the agentic era, this matters more than it used to as AI tools that consume API specs and documentation depend on accurate descriptions, consistent naming, and complete type information.
The spec is no longer just documentation; it is the interface.
Design Decisions
The CLI started with more features than it has now. The path to its current design was a series of deliberate trade-offs.
- No Confirmation Prompts. The CLI doesn’t ask "are you sure? (Y/N)" because it is designed for agents, scripts, and automation.
- Minimal Client-Side Validation. This avoids a class of bugs where the CLI rejects something the API would allow.
- JSON-Only Output. Early iterations rendered human-friendly tables alongside JSON, but this was a second output format that couldn’t be easily generated from the OpenAPI specs.
- No Positional Arguments.
alpaca order get ORDER_IDbecamealpaca order get --order-id ORDER_ID. Explicit flags are unambiguous and self-documenting. - No Command Aliases. Shortcuts like
alpaca buyandalpaca pricewere included in the original design, but they created a second surface that drifts from the canonical commands.
Each design decision was driven by the same question: does this move toward or away from a spec-driven CLI? Features that required hand-maintenance were removed. Features that could be generated were prioritized.
How Alpaca’s CLI and MCP Server Differ
AI tooling is evolving quickly. We built the CLI and the MCP servers as two distinct product experiences because developers and agents reach for different interfaces in different contexts.
Here is where we see the differences today:
- Invocation Model: The MCP server runs as a background process that the host communicates with over the course of an entire session. The CLI is a terminal command. Each invocation starts, executes a single operation, and exits. This makes it easy to use in cron jobs, CI pipelines, and shell scripts.
- Context Window Cost: An MCP server exposes its full set of tool schemas to the AI model, which consumes tokens in the context window. A CLI command is a short string, meaning the agent only needs to know the command it wants to run, not the schema of every available tool.
- Composability: The MCP tool calls are discrete function invocations that the AI model orchestrates sequentially. CLI output pipes natively into other tools. For example,
alpaca position list --csv > positions.csvexports your portfolio to a spreadsheet in one line. - No AI Host Required: The MCP server needs an MCP client (Claude, Cursor, etc.). The CLI runs in any terminal, with or without an AI agent, including cron jobs, GitHub Actions, and simple bash scripts.
- Reproducibility: MCP tool calls happen inside an AI session, which makes them harder to extract and replay outside that context. A CLI command is a string. You can log it, share it, paste it in a runbook, or replay it exactly every time.
In practice, the MCP server aligns with long-lived agent sessions where the host benefits from tool schemas, shared context, and multi-tool orchestration. Meanwhile the CLI complements workflows like shell scripts, cron jobs, CI pipelines, copy and paste runbooks, and focused agent actions. They solve adjacent problems, and we believe developers can make use of both.
Important Considerations
When using the CLI, there are some important considerations to remember for account security and risk protection:
- Paper Trading Default: In this CLI preview release, OAuth login is restricted to paper trading. Live trading will require your API keys.
- API Key Security: Your API keys are used to authenticate each request to Alpaca's Trading API. Keep them secure and never share them. Treat them like passwords.
- Paper Trading for Testing: Test strategies on paper trading first. Paper trading uses the same API but does not execute real orders or affect real capital.
- No Confirmation Prompts: Trading commands executed in the CLI happen immediately. Bulk operations like
alpaca order cancel-allandalpaca position close-alldo not ask for confirmation before acting. It’s important to exercise caution before execution. - Whitelisting Bypasses Confirmation: When an AI agent uses the CLI, the host application (Cursor, Claude, etc.) may ask for confirmation before executing commands. You can whitelist CLI commands for the agent to skip these prompts for faster execution, but this removes a safety layer. An agent with whitelisted order commands can place, cancel, or close trades without any human confirmation.
- Order Execution Risk: Orders placed through the CLI execute directly from Alpaca's Trading API. Ensure you review any order before confirming, as unintended orders can result in real financial loss.
- Latency and Slippage: Market orders may experience price slippage, especially for less liquid symbols or during high-volatility periods. Limit orders help control execution price but may not fill immediately.
- API Rate Limits: Alpaca's API has rate limits per account. Repeatedly querying market data or attempting high-frequency order placement may trigger rate limiting.
Open Questions
We’re building the CLI and MCP server in the open. While we have an initial direction, we want to build what developers and agents really need.
If you’re testing with either, we’d love to hear from you about:
- What would you prefer to build with it? We want to know what workflows matter to you.
- How do you choose between the CLI or MCP server? We built both because we think they solve different problems. We’re curious where developers draw that line today, and whether it’s shifting as AI tooling matures.
- What should we add first? The issues tab is available on both the CLI GitHub and MCP GitHub. Tell us what would make these tools indispensable for your workflow.
- How are you integrating AI agents with Trading API? The CLI was designed for agents, but we’re still learning how developers actually wire these tools together. If you’re building something interesting, we want to see it.
If you have preferences between either interface or see any gaps, we want to hear about them! Please share feedback by opening an issue on GitHub, join the conversation in our community Slack, or posting in Alpaca’s official subreddit.
Get Started
Remember, you can sign up for Alpaca's Trading API and install the CLI with go install or Homebrew and make your first API call in under a minute with the below command.
alpaca account get
alpaca order submit --symbol AAPL --side buy --qty 1 --type market
alpaca data latest-quote --symbol AAPL
alpaca position list --csv > positions.csvAlready using the MCP server? The CLI uses the same API keys. Set them as environment variables and both tools work together.
The CLI is open source under Apache 2.0. Feedback, issue submission, and design discussion is welcome on GitHub.
Still have questions? Learn more in our API documentation or contact us at [email protected].
Insights generated by our CLI, MCP server, and connected AI agents are for educational and informational purposes only and should not be taken as investment advice. Alpaca does not recommend any specific securities or investment strategies. Past performance from models does not guarantee future results. Please conduct your own due diligence before making any decisions. All firms mentioned operate independently and are not liable for one another.
The content of this article is for general informational purposes only. All examples are for educational and illustrative purposes only.
Options trading is not suitable for all investors due to its inherent high risk, which can potentially result in significant losses. Please read Characteristics and Risks of Standardized Options before investing.
Fractional share trading allows a customer to buy and sell fractional share quantities and dollar amounts of certain securities. Fractional share trading presents unique risks and is subject to particular limitations that you should be aware of before engaging in such activity. See Alpaca Customer Agreement at https://alpaca.markets/disclosures for more details.
All investments involve risk and the past performance of a security, or financial product does not guarantee future results or returns. There is no guarantee that any investment strategy will achieve its objectives. Keep in mind that while diversification may help spread risk, it does not assure a profit, or protect against loss. There is always the potential of losing money when you invest in securities, or other financial products. Investors should consider their investment objectives and risks carefully before investing.
Securities brokerage services are provided by Alpaca Securities LLC ("Alpaca Securities"), member FINRA/SIPC, a wholly-owned subsidiary of AlpacaDB, Inc. Technology and services are offered by AlpacaDB, Inc.
Cryptocurrency is highly speculative in nature, involves a high degree of risks, such as volatile market price swings, market manipulation, flash crashes, and cybersecurity risks. Cryptocurrency regulations are continuously evolving, and it is your responsibility to understand and abide by them. Cryptocurrency trading can lead to large, immediate and permanent loss of financial value. You should have appropriate knowledge and experience before engaging in cryptocurrency trading. For additional information, please click here.
Cryptocurrency services are made available by Alpaca Crypto LLC ("Alpaca Crypto"), a FinCEN registered money services business (NMLS # 2160858), and a wholly-owned subsidiary of AlpacaDB, Inc. Alpaca Crypto is not a member of SIPC or FINRA. Cryptocurrencies are not stocks and your cryptocurrency investments are not protected by either FDIC or SIPC. Please see the Disclosure Library for more information.
AlpacaDB, Inc., the parent company of Alpaca Securities LLC and Alpaca Crypto LLC, provides services and technology, including the brokerage infrastructure API supporting Alpaca’s financial services. This is not an offer, solicitation of an offer, or advice to buy or sell securities or cryptocurrencies or open a brokerage account or cryptocurrency account in any jurisdiction where Alpaca Securities or Alpaca Crypto, respectively, are not registered or licensed, as applicable.
