logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

alpaca-brokerage-interface-service

Interface for programmatic interaction with the Alpaca financial trading platform via natural language instructions. Facilitates portfolio oversight, real-time asset quote retrieval, and automated order execution for securities trading.

Author

alpaca-brokerage-interface-service logo

miguelyad26

MIT License

Quick Info

GitHub GitHub Stars 3
NPM Weekly Downloads 0
Tools 1
Last Updated 2026-02-19

Tags

apiapisrequeststrading apiapi usingapis http

Alpaca Brokerage Interface Service

This implementation serves as a Model Context Protocol (MCP) bridge, enabling large language models (LLMs) such as Claude to issue commands directly to the Alpaca trading infrastructure. It abstracts complex API calls into conversational commands for managing stock transactions, querying account metrics, retrieving market intelligence, and handling existing holdings.

Core Capabilities

  • 📚 API Reference Access: Provides linkage to the underlying Alpaca Software Development Kit documentation for construction assistance.
  • 📈 Asset Valuation: Fetch instantaneous security quotations and historical time-series pricing data.
  • 🏦 Financial Status: Review account capital reserves, available purchasing power, and operational status.
  • 🗄️ Holding Oversight: Inspect current security positions and evaluate their performance metrics.
  • 🛍️ Trade Initiation: Dispatch requests for market or limit orders using descriptive language.
  • 📜 Transaction Tracking: List, monitor the status of, and revoke pending orders.

Prerequisites for Deployment

  • Runtime Environment: Python version 3.10 or newer.
  • Credentials: Valid Alpaca API authentication keys.
  • Client Application: Claude for Desktop or any compatible MCP client software.

Setup Procedure

  1. Repository Acquisition: bash git clone https://github.com/YOUR_USERNAME/alpaca-mcp.git cd alpaca-mcp

  2. Dependency Installation: bash pip install mcp alpaca-py python-dotenv

  3. Credential Configuration: Establish a .env file containing your secrets:

API_KEY_ID=your_alpaca_api_key API_SECRET_KEY=your_alpaca_secret_key

Operational Guide

Launching the Service

Initiate the service execution via:

bash python alpaca_mcp_server.py

Integrating with Claude for Desktop

  1. Launch the Claude Desktop application.
  2. Navigate to the configuration panel (Settings).
  3. Access the "Developer" section and select "Edit Config".
  4. Incorporate the service definition into your claude_desktop_config.json:

{ "mcpServers": { "alpaca": { "command": "python", "args": [ "/path/to/alpaca_mcp_server.py" ], "env": { "API_KEY_ID": "your_alpaca_api_key", "API_SECRET_KEY": "your_alpaca_secret_key" } } } }

  1. Save the configuration and reload the Claude client.

Exposed Functionality

The service exposes the following discrete operational methods:

  • get_account_info() - Retrieve current monetary holdings and administrative status.
  • get_positions() - Enumerate all assets currently held in the portfolio.
  • get_stock_quote(symbol) - Obtain the most recent price quote for a specified ticker.
  • get_stock_bars(symbol, days) - Fetch historical trading records (bars) for an asset over a duration in days.
  • get_orders(status, limit) - Query the ledger for orders matching specific fulfillment states.
  • place_market_order(symbol, side, quantity) - Submit an instruction to acquire or divest at the prevailing market rate.
  • place_limit_order(symbol, side, quantity, limit_price) - Submit an instruction to trade contingent upon reaching a specified price threshold.
  • cancel_all_orders() - Nullify every outstanding order.
  • close_all_positions(cancel_orders) - Liquidate every open security holding.

Sample Inquiries

When linked with Claude, users can pose questions such as:

  • "What are my total cash reserves and available purchasing power?"
  • "Display my active security allocations."
  • "What is the current trading price for AAPL?"
  • "Chart the price movement history for TSLA across the preceding ten calendar days."
  • "Procure five units of MSFT stock via a market transaction."
  • "Sell a quantity of ten AMZN shares using a ceiling price of $130."
  • "Void all currently active trade requests."

Operational Note

By default, this service utilizes Alpaca's simulated (paper) trading environment. To transition to live capital deployment, modify the paper=True parameter to paper=False during the initialization of the TradingClient.

Security Advisory

This MCP service is granted comprehensive transactional permissions over your Alpaca account. It is imperative to scrutinize and authorize all proposed trading actions suggested by Claude before execution.

Licensing

Distributed under the MIT License.

== Wikipedia Context: XMLHttpRequest (XHR) ==

XMLHttpRequest (XHR) defines an Application Programming Interface embodied by a JavaScript object, designed to facilitate the transmission of Hypertext Transfer Protocol (HTTP) requests from a web browser environment toward a backend web server. The methods afforded by this API permit a browser-hosted application to dispatch queries to the server subsequent to the initial page load completion, and subsequently receive transmitted data. XMLHttpRequest constitutes a foundational element of Asynchronous JavaScript and XML (Ajax) programming paradigms. Preceding the advent of Ajax, the primary means of server interaction relied upon traditional hyperlinks and form submission mechanisms, operations that typically necessitated the complete replacement of the current viewed page.

== Chronology == The conceptual framework underpinning XMLHttpRequest was first formulated in the year 2000 by the development team at Microsoft Outlook. This concept was subsequently instantiated within the Internet Explorer 5 browser release (1999). However, the initial syntax did not employ the standardized identifier XMLHttpRequest. Instead, developers utilized the constructor identifiers ActiveXObject("Msxml2.XMLHTTP") and ActiveXObject("Microsoft.XMLHTTP"). As of Internet Explorer version 7 (released in 2006), universal support for the XMLHttpRequest identifier became the standard across all major browser platforms, including Mozilla's Gecko rendering engine (2002), Safari version 1.2 (2004), and Opera version 8.0 (2005).

The XMLHttpRequest identifier has since evolved into the established convention across the primary browser landscape.

=== Standardization Efforts === The World Wide Web Consortium (W3C) formally published a Working Draft specification for the XMLHttpRequest object on April 5, 2006. Subsequently, on February 25, 2008, the W3C released the Level 2 specification. This Level 2 revision introduced enhancements such as mechanisms to monitor the progress of ongoing events, enabling cross-domain resource requests, and supporting the handling of raw byte streams. By the conclusion of 2011, the Level 2 specification elements were integrated back into the original primary specification document. In late 2012, the responsibility for ongoing maintenance and documentation was transferred to the WHATWG, which now sustains a dynamic document utilizing Web IDL for its definition.

== Utilization Methodology == Generally, the procedure for dispatching a request using XMLHttpRequest involves several distinct programming stages.

  1. Object Instantiation: Create an XMLHttpRequest object instance by invoking its constructor function:
  2. Request Configuration: Invoke the open method to define the request verb (e.g., GET, POST), specify the target resource URI, and designate whether the operation will execute synchronously or asynchronously:
  3. Asynchronous Listener Setup: If an asynchronous request mode is chosen, establish an event handler function designed to trigger upon changes in the request's operational state:
  4. Transmission Commencement: Execute the request transmission by calling the send method, optionally including payload data:
  5. State Monitoring: Process state transitions within the registered event listener. Upon successful receipt of server data, this information is typically stored within the responseText property. When the object finalizes its processing of the response, its state transitions to 4, signifying the "done" status.

Beyond these fundamental steps, XMLHttpRequest provides extensive configuration options governing request transmission parameters and response management. Custom header fields can be programmatically affixed to the request to guide server fulfillment logic, and data intended for server reception can be supplied directly within the send invocation. The received payload can be automatically parsed from its initial format (like JSON) into an immediately usable JavaScript data structure, or alternatively, it can be processed incrementally as data arrives rather than awaiting the complete transfer. Furthermore, requests possess the capability to be halted prematurely or configured to automatically terminate if completion is not achieved within a predetermined time limit.

== Inter-Domain Communication ==

During the nascent phases of the World Wide Web's evolution, it was recognized that circumvention of the same-origin policy was technically feasible, leading to potential...

See Also

`