All Learn articles

Guide · · 8 min read · By Mike A.

How to build an AI trading agent with Claude

An AI trading agent with Claude is a research loop: ask, gather market research, check the answer, and hand a plan to a person. Four short Python steps build it, and you approve every idea.

An AI trading agent is a research loop with a person at the end

To build an AI trading agent with Claude, write a loop that asks a question, gathers market research through a tool, checks the answer, and passes a proposed plan to a person who approves it. This guide builds the research version in four short Python steps, written with Claude in Claude Code. The agent never places an order. It prepares ideas, and you decide. The research comes from NeuroAPI, Neurobro’s API, in one HTTP call.

The result is an AI stock research agent in Python: a script you can run each morning that returns a short list of ideas for review. It makes a good first version of an AI trading bot with Claude, because alerts, scheduling, and a second opinion can all be added later on top of a list you have already approved.

The loop has three parts:

Piece What it does In this build
A model Writes the script with you and extends it later Claude, in Claude Code
Market research Fetches live data and reasons over it NeuroAPI, one HTTP call
A place to send results Where a person reads and approves A terminal prompt (swap in email or chat)

A model on its own can’t look up a price, so the numbers come from a research call instead of the model’s memory. The page on how to stop AI making up stock prices explains why.

Step 1: Make one call that returns a researched answer

Install requests, then export your key. You can create one in the NeuroAPI dashboard.

pip install requests
export NEUROAPI_KEY="neuro_..."

Everything goes through one endpoint, POST /agent/ask, with an X-API-Key header. Save this as agent.py:

import os
import requests

URL = "https://api.neurobro.ai/api/v1/agent/ask"
HEADERS = {"X-API-Key": os.environ["NEUROAPI_KEY"]}


def ask(body):
    res = requests.post(URL, headers=HEADERS, json=body, timeout=300)
    res.raise_for_status()
    return res.json()


if __name__ == "__main__":
    reply = ask({"prompt": "Is ETH overbought right now?", "mode": "smart"})
    print(reply["answer"])

Ask this in Neurobro

The response carries answer, mode, request_id, and usage. Keep the request_id in your logs. Use fast for a quick check, smart for most work, and max for multi-asset investigations on Pro and Enterprise plans. The timeout is 300 seconds because the agent fetches live data before it replies.

Step 2: Ask for a typed result with output_schema

Prose is hard to check in code. Pass output_schema, a JSON Schema with an object root, and the result comes back as an object in output, with answer set to null. Add this below ask:

SCHEMA = {
    "type": "object",
    "properties": {
        "stance": {"type": "string", "enum": ["bullish", "bearish", "neutral"]},
        "support": {"type": ["number", "null"]},
        "resistance": {"type": ["number", "null"]},
        "invalidation": {"type": "string"},
        "summary": {"type": "string"},
    },
    "required": ["stance", "support", "resistance", "invalidation", "summary"],
    "additionalProperties": False,
}


def read_asset(name):
    prompt = f"Give me a structured read on {name} right now."
    body = {"prompt": prompt, "mode": "smart", "output_schema": SCHEMA}
    output = ask(body).get("output") or {}
    missing = [key for key in SCHEMA["required"] if key not in output]
    if missing:
        raise ValueError(f"{name}: missing {missing}")
    return output

Every property is required and extra fields are refused, which is the shape the docs recommend. The two price levels allow null, so the agent can return null when it can’t source a level instead of a placeholder like zero. On fast and smart the schema is followed on a best-effort basis, so the check on missing keys stays in your code.

Step 3: Loop over a watchlist

A watchlist is a list of names and a loop. Add a short function that keeps going when one call fails:

WATCHLIST = ["BTC", "ETH", "NVDA"]


def run_watchlist():
    reads = {}
    for name in WATCHLIST:
        try:
            reads[name] = read_asset(name)
        except (requests.RequestException, ValueError) as err:
            print(f"{name}: skipped ({err})")
    return reads

Only successful answers count against your plan’s quota, and every call needs an active plan, so start with a short list. You can pick a plan on the NeuroAPI pricing page.

Step 4: Hand the result to a person

The last step is a review screen. Each idea prints with its levels and the point where it fails, and you answer yes or no:

def review(reads):
    approved = {}
    for name, read in reads.items():
        print(f"\n{name}: {read['stance']}, "
              f"support {read['support']}, resistance {read['resistance']}")
        print(read["summary"])
        print("Wrong if:", read["invalidation"])
        if input("Add to today's plan? [y/N] ").strip().lower() == "y":
            approved[name] = read
    return approved


if __name__ == "__main__":
    plan = review(run_watchlist())
    print(f"{len(plan)} ideas approved. Place any orders yourself.")

Replace the earlier __main__ block at the bottom of agent.py with this one. From here you can write the approved ideas to a file, an email, or a chat message.

Why the agent proposes and a person approves

An answer can be out of date or wrong, and the same model can sound equally sure either way. The approval step is where you open a live chart, check the level, and read the date. It also makes the script safe to schedule each morning, because the worst it does is write a list.

Ask Claude Code to extend the script: add a second pass that argues against each idea, or format the approved plan as a morning note. For the choice between this design and a raw data feed, market data API vs AI research API compares the two.

Where NeuroAPI fits in this build

NeuroAPI runs the same agent as Neurobro Web and Neurobro Mobile: it reasons across market, derivatives, on-chain, news, and macro data before it answers, and it returns research, never orders. With output_schema, a value it can’t find comes back as null when your schema allows it. NeuroAPI works over plain HTTP, so the code above ports to any language.

The quickstart takes you from key to first answer, and the cookbook has runnable Python for retries, streaming, and structured reports. Label Neurobro’s answers as AI-generated research wherever you show them.

The markets move fastNow you can too

Get Neurobro

Scan with your phone camera, or choose your store.

NeurobroSmart Trading AIDownload