How I Set Up a Basic Claude Code "Trading Bot" .. using the term trading bot extremely loosely.

This post isn't really for broad distribution, I just put it together as some people asked me about this project on X. If this post ends up being more widely distributed, I put little effort into coming to any good conclusions or sharing any actual tips. It's solely to share a little about what I've done and not whether I did the right thing or not!

Several years ago, my group chat got mildly obsessed with Trading 212, basically a mobile app that made it easy to buy and sell shares. We bought and sold a bunch of stuff, lost money, and that was that.

One of those friends mentioned this week that T212 had added an MCP server to let agents trade on their platform. I had no idea they even had an API! Once I found that, I wasn't interested in the MCP anymore. I decided to rig up some scripts to let Claude Code use the API for buying and selling shares, and see how it'd do maintaining a simple portfolio.

Getting Started

I put £500 into a S&S ISA (Stocks and Shares ISA, a bit like a Roth IRA). I downloaded the API documentation, the terms and conditions, and some other useful documents in Markdown format, then had Claude Code boil them down to the essentials in a CLAUDE.md file. Auth tokens in .env, and claude was ready to go.

I asked Claude Code to do some initial things with the API like query the portfolio, look up shares, that sort of thing. I noticed it was writing lengthy Python one-liners to run directly, which felt inefficient and brittle, so I asked it to look at all the documentation and build some helper scripts instead. It built a folder of scripts to get current positions, account info, search for stocks, buy, sell, and so on, complete with rate limiting.

The CLAUDE.md Rules

The interesting bits of the CLAUDE.md:

Your role is to use the Trading212 (T212) API as documented in api.md. You will code in Python and can use Python for one-off script runs as needed.

You will prompt the user before ANY call that results in actual money being spent. You do not have to prompt if a profit is being taken.

Then I gave it access to some of my existing agent skills:

ask-grok
Ask the Grok model (with X access) for news or sentiment on a stock. Only use when it will genuinely help a trade.
Costs money
fetch_article
Fetch any article on the Web as Markdown.
Free
agent-browser
Advanced access to a headless browser for research.
Free
reddit
Use Reddit's API to browse posts, subreddits, and sentiment.
Free

Then I asked it to keep a log:

You will append to a log in LOG.md of your basic thoughts, trades, transactions, etc. This is so you can act upon prior knowledge or actions. Also be sure to append to LOG.md if you do any sentiment analysis or other things that should be recorded knowledge affecting trades or portfolio.

The Actual Trading Process

The actual trading process is/was a bit crap really. I just ask Claude questions, it does research, and it comes up with suggestions which in most cases I just agree to.

In the first 24 hours it bought a variety of overnight positions in the US (since it was night in the UK when I set this up) and did pretty well with Cloudflare!

The Cloudflare situation was interesting actually as I didn't WANT to sell it, but its price jumped 2.5% on market open and the bot was insistent. I agreed, and it's just as well I did since the price then crashed below where I'd bought in. Removing the user's emotion from the equation paid off!

Starting portfolio in Trading 212

Trading Rules (After 24 Hours)

After 24 hours, I asked Claude to boil down anything it had learnt into a set of trading rules to guide it in future. This is what it came up with:

All basic stuff, but it can be extended over time as I actually figure things out myself.

Day-to-Day Usage

A session right now involves me loading up Claude Code, asking it how things are going, whereupon it looks up the portfolio, figures out if anything needs to be sold, tells me what we're waiting to happen, and so on. If there's any profit to take, it'll either take it or ask me about it, depending on how marginal it is.

Results

20+ trades later, how am I doing?

Current portfolio in Trading 212

I won't be giving up my day job just yet.
But I am in profit.

I'm @cooperx86 if you find this post in some weird way and wanna follow me.