How I Set Up a Basic Claude Code "Trading Bot" .. using the term trading bot extremely loosely.
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:
Then I asked it to keep a log:
You will append to a log in
LOG.mdof your basic thoughts, trades, transactions, etc. This is so you can act upon prior knowledge or actions. Also be sure to append toLOG.mdif 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!
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:
- Never chase. Don't buy a stock that's already up big on the day. By the time we see it, the easy money is gone. MU (+4.7%), EQIX (+9%), HOOD, CSCO were all losses from chasing.
-
Always check the live price before buying. Use
scripts/price.pyto calculate quantity for a target spend. Never estimate from memory. MU was $435, not the $100 expected, resulting in a 4x oversized position. - "Buy the dip on earnings miss" is a coin flip. HOOD and CSCO both failed on this thesis. "Buy the beat" works better, but only if you're early (pre-market/overnight, before the crowd piles in).
- Prefer GBX instruments. Every USD round-trip costs ~0.3% in FX fees. Churning through multiple USD positions in a day compounds this painfully. GBX trades have zero friction.
- Use the 2% insta-sell trigger on short-term trades. It worked perfectly on NET (+3.2%). Take the profit and move on. The difference between 2% and 3% on a small position is pennies, and reversals are real.
- Don't trade just because you have cash. Forcing trades leads to bad entries. It's fine to sit in cash and wait for a proper setup.
- Overnight earnings plays can work, but only with genuine conviction and a clear catalyst. NET was bought before the crowd, on a real earnings blowout, and sold with discipline.
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
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.