Skip to content

craigde/StockAgent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

AI Trading Agent with MCP (Model Context Protocol)

Build an autonomous AI trading agent that can execute real trades, analyze options, and monitor macroeconomic conditionsβ€”all through natural language conversation.

Architecture Status License

🎯 What This Project Does

This repository contains OpenAPI specifications that enable AI assistants (Claude, ChatGPT, etc.) to:

  • Execute trades via Alpaca (stocks, ETFs, options)
  • Analyze options chains with Greeks via Tradier
  • Monitor macroeconomic conditions via FRED (Federal Reserve data)

Using Workato's MCP connector, these specs become MCP servers that AI can call as tools.

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                     USER CONVERSATION                        β”‚
β”‚           "Buy $5000 of NVDA" or "Check the yield curve"    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚
                              β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    CLAUDE / CHATGPT                          β”‚
β”‚              AI reasoning and decision making                β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚
                              β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    MCP PROTOCOL LAYER                        β”‚
β”‚           Standardized tool calls via Workato                β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚
              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
              β–Ό               β–Ό               β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚     ALPACA      β”‚ β”‚     TRADIER     β”‚ β”‚      FRED       β”‚
β”‚   Trading API   β”‚ β”‚   Options API   β”‚ β”‚   Economic API  β”‚
β”‚                 β”‚ β”‚                 β”‚ β”‚                 β”‚
β”‚ β€’ Orders        β”‚ β”‚ β€’ Options Chainsβ”‚ β”‚ β€’ Yield Curve   β”‚
β”‚ β€’ Positions     β”‚ β”‚ β€’ Greeks        β”‚ β”‚ β€’ Unemployment  β”‚
β”‚ β€’ Portfolio     β”‚ β”‚ β€’ Historical    β”‚ β”‚ β€’ Inflation     β”‚
β”‚ β€’ Account       β”‚ β”‚ β€’ Quotes        β”‚ β”‚ β€’ GDP           β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“ Repository Contents

File Description
alpaca_openapi.yaml Trading execution (orders, positions, account)
tradier_openapi.yaml Options data (chains, Greeks, quotes)
fred_openapi.yaml Macroeconomic data (rates, inflation, employment)
README.md This file

πŸš€ Quick Start

Prerequisites

  1. Workato Account - Sign up for Workato (MCP connector required)
  2. Alpaca Account - Sign up for Alpaca (free paper trading)
  3. Tradier Account - Sign up for Tradier (free sandbox)
  4. FRED API Key - Get free key

Step 1: Set Up Alpaca

  1. Create account at alpaca.markets
  2. Go to Paper Trading dashboard
  3. Generate API keys (Key ID + Secret Key)
  4. Note: Use paper-api.alpaca.markets for testing

Step 2: Set Up Tradier

  1. Create account at developer.tradier.com
  2. Get your Sandbox Access Token from dashboard
  3. Note: Use sandbox.tradier.com for free delayed data

Step 3: Set Up FRED

  1. Go to FRED API Keys
  2. Request a free API key (instant approval)

Step 4: Import to Workato

For each API:

  1. In Workato, go to App Connections β†’ Create Connection
  2. Select HTTP connector with OpenAPI option
  3. Upload the corresponding .yaml file
  4. Configure authentication:
API Auth Type Configuration
Alpaca API Key (Header) APCA-API-KEY-ID and APCA-API-SECRET-KEY headers
Tradier Bearer Token Authorization header with your access token
FRED API Key (Query) api_key query parameter

Step 5: Create MCP Server

  1. In Workato, go to MCP Servers β†’ Create Server
  2. Add your HTTP connections as tools
  3. Publish the MCP server
  4. Copy the MCP server URL

Step 6: Connect to Claude

In Claude.ai:

  1. Go to Settings β†’ Integrations β†’ MCP Servers
  2. Add your Workato MCP server URL
  3. Authorize the connection
  4. Start chatting!

πŸ’¬ Example Conversations

Trading with Alpaca

User: What's my current portfolio value?

Claude: [Calls Alpaca:Get_Account]
Your portfolio is worth $99,595.06 with $43,581 buying power.
You have 24 open positions.

User: Buy $5000 of NVDA

Claude: [Calls Alpaca:Create_Order]
βœ“ Bought 26.3 shares of NVDA at $190.15
Order filled. Total cost: $5,001.95

Options Analysis with Tradier

User: What covered calls can I sell on SOFI?

Claude: [Calls Tradier:Get_Option_Chains with greeks=true]

Here are the best opportunities for SOFI (current price $26.92):

| Strike | Expiry | Premium | Delta | Annual Return |
|--------|--------|---------|-------|---------------|
| $29    | Feb 20 | $1.38   | 0.40  | 48.4%         |
| $30    | Feb 20 | $1.10   | 0.34  | 38.3%         |
| $28    | Feb 20 | $1.72   | 0.47  | 60.0%         |

Recommendation: The $29 strike offers the best risk/reward balance.

Macro Analysis with FRED

User: What's the current macro environment?

Claude: [Calls FRED:Get_Series_Observations for T10Y2Y, VIXCLS, DFF, UNRATE]

πŸ“Š Market Regime Check (January 2026)

| Indicator | Value | Signal |
|-----------|-------|--------|
| Yield Curve (10Y-2Y) | +0.64% | βœ… Normal |
| VIX | 14.49 | βœ… Low volatility |
| Fed Funds Rate | 4.33% | 🟑 Restrictive |
| Unemployment | 4.1% | βœ… Healthy |

Regime: RISK-ON
Current conditions favor growth assets.

πŸ“Š Available Tools

Alpaca (Trading)

Tool Description
getAccount Account balance, buying power, status
getAllPositions All open positions with P&L
getPosition Single position details
createOrder Create market/limit/stop orders
cancelOrder Cancel open order
closePosition Close a position (full or partial)
getPortfolioHistory Historical portfolio value
getMarketClock Market open/close status

Tradier (Options)

Tool Description
getQuotes Stock/ETF quotes
getOptionChains Full options chain with Greeks
getOptionExpirations Available expiration dates
getOptionStrikes Strike prices for expiration
getHistoricalPrices OHLCV data
getMarketClock Market status

FRED (Macro)

Tool Description
getSeriesObservations Economic data values
getSeriesInfo Series metadata
searchSeries Search for series
getReleaseDates Economic calendar
getCategory Browse data categories

πŸ”‘ Key FRED Series

Series ID Name Frequency Use Case
T10Y2Y 10Y-2Y Yield Spread Daily Recession indicator
VIXCLS VIX Daily Fear gauge
DFF Fed Funds Rate Daily Monetary policy
UNRATE Unemployment Rate Monthly Economic health
CPIAUCSL CPI Monthly Inflation
BAMLH0A0HYM2 High Yield Spread Daily Credit risk
ICSA Initial Claims Weekly Labor market
GDP GDP Quarterly Economic growth

⚠️ Important Disclaimers

  • Paper Trading Only: Start with paper trading to test your setup
  • Not Financial Advice: This is an educational project
  • Options Risk: Options trading involves substantial risk
  • API Limits: Be aware of rate limits on all APIs
  • Data Delays: Tradier sandbox has 15-minute delayed data

πŸ”§ Troubleshooting

Common Issues

401 Unauthorized (Alpaca)

  • Check API key format (needs both Key ID and Secret)
  • Verify using correct base URL (paper vs live)
  • Ensure headers are named correctly

422 Unprocessable Entity (Alpaca Orders)

  • Don't send empty stop_loss or take_profit for simple orders
  • Use either qty OR notional, not both
  • Check market hours for day orders

400 Bad Request (Tradier)

  • Verify Bearer token format
  • Check symbol format for options

No Data (FRED)

  • Add file_type=json to requests
  • Check series_id spelling (case-sensitive)

πŸ“š Resources

🀝 Contributing

Contributions welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Submit a pull request

πŸ“„ License

MIT License - see LICENSE file for details.

πŸ™ Acknowledgments


Built with ❀️ by the AI Trading Agent community

Remember: Always test with paper trading before using real money!

About

MCP Servers for stock agent

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors