How to Build an AI Trading Bot with Claude and the EODHD API A developer demonstrates how to build an AI trading bot that combines the EODHD API for market data with Anthropic's Claude large language model for reasoning, replacing rule-based logic with contextual judgment. The tutorial shows how to fetch end-of-day prices and live quotes via EODHD, then prompt Claude to output structured buy/hold/sell decisions with reasoning, aiming to adapt to market shifts that static rules miss. Most trading bots are just if-statements wearing a costume. RSI below 30, buy. Moving averages cross, sell. That works fine until the market does something the rules didn't anticipate, and then the bot keeps executing the same logic anyway, because it can't actually think. If you're: this is for you. A rule-based bot doesn't understand the market. It pattern-matches against a formula someone wrote months ago. Earnings surprise. A sudden news event. A sector rotation nobody coded for. The bot has no way to account for any of it, because it was never built to interpret context, only to check conditions. Developers usually discover this the hard way. They backtest a strategy, watch it perform well on historical data, deploy it, and then spend the next few months tweaking thresholds every time the market shifts. The bot isn't wrong. It's just blind. There's also the data problem underneath all of this. Plenty of hobby projects lean on scraped Yahoo Finance endpoints or free tiers that cap out fast, and both tend to fail exactly when you need them most. A trading bot doesn't need more rules. It needs reasoning. That's a different kind of system entirely. Instead of "if X then Y," you want something closer to "given this data, what would a reasonable analyst conclude, and why." Large language models are good at exactly that kind of contextual judgment, as long as you feed them clean, structured data instead of asking them to guess. This tutorial combines two pieces: EODHD API for market data. End-of-day prices, real-time quotes, fundamentals, and historical data through a single REST interface, without maintaining scrapers that break every time a website changes its HTML. Claude for the reasoning layer. Given a snapshot of price action, volume, and basic fundamentals, Claude produces a structured decision buy, hold, sell along with the reasoning behind it, in a format your code can actually parse and act on. You could swap either piece out. The point isn't "use these exact two tools forever," it's showing how the pattern works so you can adapt it. Want reliable market data without building your own scraping layer? EODHD covers over 150,000 tickers with a generous free tier and no rate-limit surprises mid-project. Get your free EODHD API key → You'll need two API keys: one from EODHD, one from Anthropic. pip install requests anthropic python-dotenv Store your keys in a .env file: EODHD API KEY=your eodhd key here ANTHROPIC API KEY=your anthropic key here Start with a function that grabs recent price history and a live quote for a given ticker. python import os import requests from dotenv import load dotenv load dotenv EODHD KEY = os.getenv "EODHD API KEY" def get market data ticker: str, exchange: str = "US" : symbol = f"{ticker}.{exchange}" Last 30 days of end-of-day prices eod url = f"https://eodhd.com/api/eod/{symbol}" eod params = { "api token": EODHD KEY, "period": "d", "fmt": "json", "order": "d", } eod resp = requests.get eod url, params=eod params .json :30 Live quote quote url = f"https://eodhd.com/api/real-time/{symbol}" quote params = {"api token": EODHD KEY, "fmt": "json"} quote resp = requests.get quote url, params=quote params .json return { "ticker": ticker, "current price": quote resp.get "close" , "change pct": quote resp.get "change p" , "volume": quote resp.get "volume" , "recent history": eod resp, } This gives you a clean payload: current price, percentage change, volume, and 30 days of history. No scraping, no broken HTML selectors. This is the part that separates it from a rule-based bot. Instead of hardcoding thresholds, you hand Claude the data and ask for a structured judgment call. python import json from anthropic import Anthropic client = Anthropic api key=os.getenv "ANTHROPIC API KEY" def get trading decision market data: dict - dict: prompt = f"""You are a trading analyst reviewing market data for {market data 'ticker' }. Current price: {market data 'current price' } Change today: {market data 'change pct' }% Volume: {market data 'volume' } Recent 30-day history: {json.dumps market data 'recent history' :10 } Based on this data, provide a trading decision. Respond ONLY with valid JSON in this exact format: {{ "decision": "buy" | "hold" | "sell", "confidence": 0.0 to 1.0, "reasoning": "2-3 sentence explanation grounded in the data provided" }}""" response = client.messages.create model="claude-sonnet-4-6", max tokens=300, messages= {"role": "user", "content": prompt} , raw text = response.content 0 .text.strip return json.loads raw text The key detail here is the response format. Asking for structured JSON, not a paragraph, is what makes this usable in an actual pipeline instead of a chat window. python def run analysis ticker: str : data = get market data ticker decision = get trading decision data print f"\n{ticker} — Decision: {decision 'decision' .upper }" print f"Confidence: {decision 'confidence' }" print f"Reasoning: {decision 'reasoning' }" return decision if name == " main ": run analysis "AAPL" Sample output: AAPL — Decision: HOLD Confidence: 0.62 Reasoning: Price is up 0.8% on below-average volume, suggesting limited conviction behind the move. Recent history shows consolidation rather than a clear trend, so waiting for a volume-confirmed breakout makes more sense than acting now. That reasoning field is the whole point. You get a decision plus the logic behind it, which you can log, review, and adjust over time. A rule-based bot never gives you that. Before connecting this to anything resembling a real account, run it against a paper trading environment. Alpaca is a solid option here. Its paper trading API mirrors the live trading endpoints exactly, so you can route Claude's decisions through simulated buy and sell orders and see how the strategy would have performed, with fake money and real market conditions. python import alpaca trade api as tradeapi alpaca = tradeapi.REST os.getenv "ALPACA API KEY" , os.getenv "ALPACA SECRET KEY" , "https://paper-api.alpaca.markets", def execute paper trade ticker: str, decision: dict : if decision "decision" == "hold": print f"No action for {ticker}, holding position." return side = "buy" if decision "decision" == "buy" else "sell" alpaca.submit order symbol=ticker, qty=1, side=side, type="market", time in force="day", print f"Paper {side} order submitted for {ticker}." Run execute paper trade after get trading decision and you have a full loop: EODHD for data, Claude for reasoning, Alpaca for execution, all without a single dollar at risk. This is also where you'd start tracking accuracy. Log every decision, compare it against what actually happened three or five days later, and you'll quickly see whether the reasoning holds up or needs a better prompt. From here you can build: An LLM adds contextual reasoning that fixed rules can't replicate on their own. Clean, reliable market data matters more than people expect. Claude is only as good as what you feed it, and EODHD removes the guesswork of scraping or rate-limited free APIs. This is a starting point, not a production system. Position sizing, stop losses, and proper risk management live outside the scope of this tutorial, and skipping them before going live is how paper gains turn into real losses. ❓ Do I need trading experience to build this? ✅ No. You need basic Python and an understanding of what a buy, hold, or sell decision means. The reasoning comes from Claude, not from you having to encode strategy logic manually. ❓ Is this real algorithmic trading? ✅ It's a form of it, specifically an LLM-assisted decision layer rather than a pure quantitative model. Traditional algo trading uses fixed mathematical rules; this approach adds a reasoning step on top of the data. ❓ Can I connect this to a real brokerage account? ✅ Technically yes, since Alpaca's live and paper APIs share the same structure. Don't, until you've backtested extensively and added proper risk controls. This tutorial is educational, not a plug-and-play trading system. ❓ Does EODHD provide real-time data or only end-of-day? ✅ Both. EODHD offers end-of-day historical data going back years, plus real-time and delayed quotes depending on your plan, which is why it works for both the historical context and the live price checks in this tutorial. If you're a software or API company looking to explain your product through high-quality educational content, not marketing fluff, feel free to connect with me on LinkedIn: Kevin Meneses González https://www.linkedin.com/in/kevin-meneses-gonzalez/ Building something with market data? EODHD gives you 30+ years of historical data, real-time quotes, and fundamentals in one API. Start free with EODHD → More tutorials like this I write about fintech APIs, Python, and AI agents every week. Read more on kevinmeneses.com → Looking for technical content for your company? I can help — LinkedIn · kevinmenesesgonzalez@gmail.com