I Built An AI Stock Trading Bot With Claude + IBKR (Full Guide)

I Built An AI Stock Trading Bot With Claude + IBKR (Full Guide)

Analisado Ver no YouTube Solicitado Em
Retorno do vídeo
Chamadas
1
Compra / Venda
1 0
Publicado

Recomendações

Entrada é o preço de fechamento do ativo na data de publicação. Atual é o último fechamento registrado.

  1. TSLA NASDAQ COMPRAR +0,00%
    Entrada $367,81 09 set 2026
    Atual $367,81 09 set 2026
    Resultado +$0,00
    vs. índice +0,0% SPY +0,0% no mesmo período
    Contexto da transcrição original
    …ice, then I could be on the beach, I could be shopping, I could be at dinner, and I could be trading on my phone instead of having to open the app, manually execute. So, I can ask it anything. I can say uh through a voice prompt right now, hey, could you please buy $15,000 worth of Tesla stock at the current market price? You can see it's loading and bang, executed through my phone. Not just that, this is the cool part that even if you don't want to go to the final step and you just want to use it for portfolio analysis, you can do the same thing. So you do…

    hey, could you please buy $15,000 worth of Tesla stock at the current market price?

    Contexto extraído por IA “I can say uh through a voice prompt right now, hey, could you please buy $15,000 worth of Tesla stock at the current market price? You can see it's loading and bang, executed through my phone.”

Transcrição Completa
So, right now on my phone, I'm messaging my finance assistant. I'm asking them what the current balance of my portfolio is, how my positions have performed over the last 24 hours, and I can even ask it to execute a trade for me on my Interactive Brokers account. I've been investing and trading for the last 7 years. And for the last 3 years, I've been on a mission to try and automate my trading. But honestly, it's not until now we have the new frontier models that it's truly possible. Even a few months ago, we didn't have the MCP connections and the correct technology for trade execution. But recently, that changed. And in today's video, I'm going to show you exactly how you can set up the exact same system for yourself to automate portfolio analysis, automate alerts, and finally, execution. The full setup guide with every prompt from today's video is going to be available for free to claim in the description below. You can actually take this spec and put it into your chord and you can get it to build this system for you. But now I'm going to explain how it actually works and how you can implement it for yourself. All right, one caveat before we start because I know when people hear the phrase trading bot, they assume that it's automatically going to be trading or investing on your behalf. Although you can do that and you can set up parameters so the AI can, you know, choose its own picks and trade. That is not what I actually recommend that you should do and it's also not what I do either. Instead, I maintain all discretionary decisions, but I outsource all of the grunt work to the AI, the alerts on my positions, the updates on fundamentals, the execution, so I don't need to go to my computer and sit down and process an order, just being able to speak to my phone and run analysis on my portfolio. That right now is what AI is best at. So, essentially what we're building today is the infrastructure layer to connect the AI, for example, Claude, which is going to be the AI of choice for today's video, with your money. So before we start building, here is an entire map of today's infrastructure. The box on the right is the broker. Everything we do today is about providing an instruction from my head into that box. And there are essentially three ways to do it. Every step requiring less input from me. The first way is the official integration that the broker built where the AI reads your account, works out what should happen, and writes the order, but it stops there because you still need to do the physical execution piece. The second way connects the AI directly to the broker's interface. It's the same request from me except now it sends the order itself and there's nothing to approve. The third way moves the entire process onto a separate device or machine. So I can run this whole thing on my phone without me needing to be at the desk at all. So why are we actually doing this? The first reason is friction. You might know that you need to adjust a position in your portfolio, but the physical friction stops you from doing so. There have been so many times where in an ideal world, I would have added more gold to my portfolio or I would have trimmed a position due to a rate decision or I would have DCAD into something because prices had gone down 20% in that day. But the physical friction and if you've got like ADHD or if you're prone to procrastination, you might relate to this of like sitting down and needing to execute on a thought or on a suggestion, that process is harder than it seems at face value. So that's the first thing that automating the process can help you avoid. And that in and of itself can help you make more money. But the other benefit is being able to read and analyze your portfolio in a more efficient manner. So if you want to use AI currently, if you do not connect your brokerage account to Claude, let's say to analyze your portfolio, essentially what you need to do is every single time you know positions change every single day or every single hour, you need to screenshot and put it into Claude and then it analyzes. And then you need to keep doing this again and again and again. So by having that connection between Claude and your real live positions and your real live account, you can get real live data and thus you can build an alert system when something happens when a set of parameters trigger or when something materially changes in terms of price or price movement in your portfolio so you know about it quickly. So now let's go through tier one, actually making the first connection between your brokerage account and between Claude. Now, I'm going to use Interactive Brokers for today's video cuz it's one of the brokerages that I use and it's the biggest one. However, a lot of brokerages now are now starting to release their own MCP connections. So, just because you might use another broker does not mean you can't do this. You just need to look into your specific broker's capabilities. So, you could even take the guide from today's video, put it into Claude, and say, "Hey, I'm using this broker instead. Is there a way that we can replicate the same architecture?" And there are even other measures you can go to if your account does not have an MCP or an API. For example, you could run it on a VPS, a virtual private server, so a computer that's constantly running that is like scanning or scraping screenshots of your account as long as it's logged in and sending that to Claude. It means it can't execute, but it can still do all of the other stuff that a native connector would. So, there are options, but I'm going to run through the entire process now in IB. So, Interactive Brokers has actually built an official integration for this in recent months. So that's why it's now possible versus a year ago. There's no code, so there's nothing you actually need to install. You just need to go into your Interactive Brokers account and authorize the connection. There are technically two ways to connect and I prefer the second one. The first option is through the app directly. I'm doing this in Claude code cuz it's just the simplest way because you can just paste the address directly into Claude and Claude code will handle the rest. This is the thing now. Claude code is so good. But if you don't know how to do something, often times you can just ask it and it will help you do something even if you know it doesn't work and you need to find a workaround cuz this does happen when you're building bots and when you know you're connecting especially to new technology sometimes you need to find a workaround but claude code is great at that. So once you paste it in it'll send you to your broker's own login. You'll usually get a code back and you can hand it back to Claude Code to finalize the integration. The reason I'm using Claude code is because the architecture we're building upon in today's video is made through Claude, including the Telegram integration. So, keeping it all in one place is just better for simplicity. You can actually use Codeex for this as well, though. So, if you're a GPT user, this will still apply to you. Uh you'll just have to do the same process on Codeex and not on Claude. So, once you've made this connection, now essentially Claude can see your positions, your cash, your margin, your P&L, your transaction history, and your risk exposure. But right now, it only has readonly access. So on the account you've selected, it can see all of the information. You can already start chatting to Claude and querying it and asking about your portfolio, but obviously you can't execute on trades. You still need to do that manually and use Claude as an assistant. So let's try out some prompts so you can see what it can do. You can ask what's my account value? How much dry powder do I have left? And you can see it pulls up the real data from your account. The other thing you can ask is for it to summarize all trades from the last month with total commissions paid, win rate, and average size. What I like about this is it will actually tell you how much you're paying in commission. Sometimes this can fly under the radar. It makes it a lot easier when it comes to your end of month or end of quarter accounting as well. And if you want to level this up even further, you can connect FMP data set or quiver quant data set or massive. These are all providers that have the data on equities for you to be able to cross reference with your portfolio. So you can ask based on the latest earnings reports, is there anything that materially changes with my semiconductor positions? And these videos I'm also releasing on this channel. So, make sure you subscribe. I'll leave the most relevant ones down below because that is a fantastic addition to help you analyze your portfolio. So, in today's video, we're talking about the infrastructure, but in these other videos, I talk about the exact prompts and the best connectors so you can analyze your portfolio even better. But, of course, Claude has knowledge on the market, so it can answer some of these prompts. But to level up, you want even better data in my opinion. I could also ask about currency. This is something that matters, especially if you're investing in multicurrency indexes or if you're not from America. You can ask what the currency impact would be if the US dollar weakens 10% against your largest foreign exposures. And you can do all sorts of things around asking it how concentrated you are to certain markets and making sure you're aligned to your risk parameters. If you don't have risk parameters, I talked about this in my financial advisor build, but what I recommend is going back and forth with Claude and just do a voice prompting session and just dump like your financial situation, your risk tolerance, and really work out a strategy and create some max draw down parameters, some ideal foreign exposure targets, currency targets to make sure that your portfolio is actually aligned with your real goals. And then you can use that voice prompting session to create a markdown file. So, so a memory file essentially that you can have in a local folder that Claude code connects to and then it can actually cross reference your goals based on your real portfolio through connecting to your brokerage account. That's a way that you can create essentially a brain that understands the alignment between your portfolio and what you want. It's pretty incredible. Obviously, all the prompts from today's video are also going to be available alongside the setup guide. Interactive Brokers actually listed a bunch of prompts on their website that they suggest. So, um, I've been using those and then I've been using a mixture of my own with some of the custom connectors that I've added to Claude. But the issue is right now if I ask it to reduce a particular holding by 50%, it won't be able to do it because it doesn't actually have the access to execute on trades. That's not a bug. It's a limitation that has purposefully been implemented into the flow that I've just shown you. IB's own documentation says instructions never become orders automatically. And when you sign the disclosure, you basically are signing that you understand that. And that's usually fine if you're not at your desk. But what if you're not at your desk? That brings us to the second path. And this is not part of the broker's official AI product. Obviously, they have consumer protection at the forefront of what they do. So, they don't want to take on the liability of the user stuffing up execution through a prompt or an AI going rogue. So, to actually implement the execution layer, you need to move over to a new system. I'll show you the system, but what I'll say is that if you're just beginning, what I would recommend is that you just start through the official interactive broker method because you can do a lot with that. You can create dashboards with that. You can prompt with that. You can even run your portfolio and do opportunity cost analysis on that. For example, based on my portfolio performance over the last 12 months, if I had invested in this way, how would it have improved? based on the current environment with rate projections with the current situation with the broader global economy, where is my portfolio most exposed and where am I going to get the most upside? You can do all of that sort of stuff as well as AI journaling already without this next step. This step is for those that want to get a little bit more advanced and I'll show you how to do that today. So, what I actually recommend that you do if you want to go to this next level is you create a paper trading account. So you can create a fake money account on your brokerage so you can actually test out execution until you're ready to put real money on the line. And even for big positions, I'm still managing a lot of that manually. The AI is very good now. And I believe it's really worth testing this out because we want to be at the forefront. I have a belief in the future every trade is just going to be automated through AI agents, but it's not fully there yet. It's still prone to hallucinations. So this is still experimental. At the same time, there are algo traders that have been doing this for decades. Obviously now they can use AI to code for them and create strategies instead of having to do it manually that rely on this connection as well. So it really depends on how advanced you want to get. All right, so the second path doesn't use Interactive Brokers AI product. It uses the TWWS API. This is the programmatic interface that Algo traders have been using for decades and it has a function that can submit orders. The difference between path one and path 2 isn't what Claude's capable of. You essentially need two things on your machine and Claude Code can run you through this process in case you get stuck. First, Python. If you've never touched it, that's fine. You're not going to write anyway. All right. So, the one thing that you need to install is Interactive Brokers own desktop software. This is the same platform that people used to trade manually. So, here's the second path, and it isn't an Interactive Brokers product at all. Interactive Brokers actually has a second way in, and it's much older, around 20 years. It's a proper programming interface built for algo traders and it has a function that sends orders. So now I'm going to download the trader workstation. So it's on the TWWS download page and once again everything will be in the setup guide. This is essentially the interactive brokers trader app. So you can log into it with your interactive brokers account the same way you would on the website. But trader workstation won't let anything else control it like claude until you give it the correct permission. So, if you go into the settings menu, you need to make some adjustments. Firstly, you need to make sure that you allow programs to connect. This is essentially the master switch. Second, you need to adjust the readonly setting. This matters cuz if you leave it on, Claude can look at your account, but it essentially can't touch it. So, as soon as you turn it off, then Claude can place orders. Thirdly, you only want to accept connections from the device that you're on. Fourthly, you want it to stop asking you to confirm every order. You can keep this on if you want some manual intervention, which especially in the experimentation phase is not a bad thing. Once again, I recommend you start with paper trading. Fifth, you can make it restart itself once a day. I'll explain why that matters in a few minutes. Then on the same screen, there's a port number. This is essentially how Claude finds the trader workstation on your machine. Yours might be different to mine. So, whatever it says on the screen is what you give Claude. Mine is currently on the paper one, and it's on screen. Uh usually the paper number is different from the live trading account. So just make sure you're on the right account. So now you can actually connect claude code. This is part of the prompt where you can say I have trader workstation running and logged into my paper trading account with API access enabled and readonly turned off. This is the socket port that we just discussed. Check whether Python is installed. It should be on Mac. Sometimes if you're on Windows it's not. And install it if it isn't. Then set up an environment and connect to the trader workstation using the following which is no longer maintained. Confirm the connection by pulling my account summary and open positions and tell me which account number you're connected to before anything else. So two things in there are deliberate. Firstly, the library name and secondly the last line which always makes sure it tells you which account it's on before it executes any trades. I also recommend that you use a local project folder as we discussed before to keep the entire build in one place. That's also part of the spec. But now, let's level it up. Let me show you how to get it on your phone because this is honestly what I use the most. I love working on the go. And obviously through dispatch on your phone now, you can technically talk if your computer's on to your local system and that's really cool. But Telegram's even better because it's always on. It's always running. And it's also a messaging app that I regularly use. So having it there puts everything in one place. So the first thing that you need is a separate device. You don't really need crazy hardware for this. So, you could run it on an old laptop, technically an old desktop, but a separate device that you're willing to be on all day, unless you're technically willing to have your main computer on all day. I don't really recommend that for security reasons, but you can do it, I guess, if you choose to. But I like to keep things clean by using a separate device. But if you don't want to go out and invest in hardware, if you don't have extra hardware, you can just buy a VPS. There's so many providers that offer this and you can just run it for like $10 a month. you don't really need that much power on the computer as well cuz it's really just executing trades. Um it's not running like a local model or anything. So now this machine will stay on logged into your account. So you don't have to be there. It's on 24/7. Now what we need to do is connect your phone to Claude Code on that computer. So you can prompt from your phone. So there are essentially three pieces here. There's Telegram on your phone and then there's a small script sitting on the machine in Claude code that waits and listens for your messages and behind that is exactly what we just built the connection between Claude code and the trader workstation. So essentially you can send a message on your phone through telegram it'll send it to the script the message will be delivered to Claude and then Claude will deliver that to the trader workstation. So to set it up I've included the setup prompt but essentially you want to use bot father so you can ask Claude code to create the connection. Then you need to go into your device and create a new botfather account. You need to connect the token to claude code. Claude code will ask you for the token. Treat it like a password. And this is one of the other reasons I like doing this on a separate device because if someone gets access to this then they can control your claude code in this case your computer or your trades which is really bad through your token. So be quite careful about this token because you don't want someone to trade on your account. This is one of the bigger risks and why I recommend uh keeping it separate. And also make sure you have two-factor authentication on your Claude account. Make sure you have a good password on the computer. Make sure you have two-actor authentication on your Telegram account as well. What you will also need installed on your computer, you can just ask Claude code as well is Whisper so it can actually listen to your voice messages. If you send them to Telegram, it can transcribe them cuz that's the easiest flow, right? It's just using voice messages. You can even just download the Whisper Flow app if you don't want to use Whisper through the audio messages onto your iPhone directly. So then it just converts the text which I guess is easier for the AI to ingest. I've got both set up. I oscillate between the two, but probably Whisper Flow is the easiest one. I also use it across other areas of my life as well, just for general communication. So now I'm on my phone. I can ask it to do all of the stuff I just typed in before from my phone. And as long as the computer instance is running, which it is on a separate device, then I could be on the beach, I could be shopping, I could be at dinner, and I could be trading on my phone instead of having to open the app, manually execute. So, I can ask it anything. I can say uh through a voice prompt right now, hey, could you please buy $15,000 worth of Tesla stock at the current market price? You can see it's loading and bang, executed through my phone. Not just that, this is the cool part that even if you don't want to go to the final step and you just want to use it for portfolio analysis, you can do the same thing. So you don't need to set up trader workstation. At the end of step one, you can skip straight to the telegram connection. So I can ask a question like, hey, could you tell me how exposed I am to the American market versus the global market? And then it will give me live portfolio analysis. So I can basically query. I could say if I wanted to increase my exposure to let's say Chinese equities, what are some potential options? And then it will give me some options. So you can see you can analyze your portfolio and you can research on your phone as well. So it's all in the same interface. And remember this interface is simply just connecting to claude code. That's all it is. It's just a way for you to transcribe to claude code. So all of your memory, all of your data is still on the computer in that folder. and your account balance is connected to your broker which is running on the computer. So there's nothing on Telegram. It's just a bridge for you to connect to the information on your computer in an easier and more convenient fashion. And this is very cool. I can actually ask Claude to set a scheduled loop where every single morning I get a report based on my real portfolio. So what's happened overnight, what's changed overnight. And I can even set up something like I can ask it, hey, message me if any of my positions drop more than 3% in a single day. So now I'll be notified every time there's a big move in my portfolio. And sometimes this is the difference between making a move that you need to make and being completely unaware and you know losing money unnecessarily. There's been so many times in the past where I didn't have a system like this and you know that would come back to bite me. So you can even set up automated parameters. And I would be careful with this because if you get the wording wrong, you can screw it up. So I'd be extremely careful. But you could theoretically ask it, you know, if this position drops below this price, please sell under these conditions. Now, I'm going to be completely honest, that is not something that I really do. It's something that I look forward to doing in the future because I believe AI trading is the future. But I'm still a bit of a control freak. I still prefer for big transactions to manually do it. So my best use case for this stuff is more on the analysis front or if it's a very simple trade or a rebalance, I'll consider executing a trade autonomously, but that's not where I get the most value right now. It is something, however, in the future that we will continue to get more value from. And that's why right now I'm running lots of live experiments both on real money using algorithms and also paper trading using algorithms that I'm forward testing before I trade them with real money. So, if you're interested in seeing some of those experiments, make sure to subscribe because now that we've built the infrastructure for this, we can plug in any theory, any market strategy. There's even copy strategies where you can copy real hedge fund trades, real insider trades using Quivercoin. I'm doing a video on this. And then you can use this as the execution automated layer for those positions. And look, IB is not the only one. I'm using it as an example today because of TWWS, but you could use, you know, Alpaca for this. That's something I use a lot. They have really native, easy integrations, arguably easier than interactive brokers, but I know most people use interactive brokers, so this video, you know, was the most applicable to the most amount of people. Once again, the full prompt will be available down below. You can get the prompt from accessing my free school community. It's an amazing community where we help you level up in terms of augmenting and improving your trading and investing with AI. I'll see you in the next video. Hopefully, you enjoyed this one. Peace out.

Comentários 0

Ainda não há comentários. Seja o primeiro a compartilhar sua opinião!