An agentic AI trading system requires a heartbeat mechanism that continuously monitors trading positions through sub-agents running on smaller, faster models (like GPT 5.4 mini) to fetch live position data from websockets, which then feeds into a main agent (like Codex 5.5) that makes periodic trading decisions (e.g., every 30 seconds) based on the current market conditions and predefined goals, enabling dynamic risk management, hedging strategies, and position adjustments.
Deep Dive
Prerequisite Knowledge
- No data available.
Where to go next
- No data available.
Deep Dive
Building a Agentic AI Trading Heartbeat That WorksAdded:
So, over the weekend, I've been playing more around with setting up my agentic AI trading. I've been using Codex and I kind of ran into this problem because when we are kind of on something that is live, let's say it's a trade, could be on Polymarket, your stock platform, whatever, if you want to do some agentic trading, we need some kind of heartbeat, right? To monitor how we are doing all the time. And this could be a bit of awkward, so I kind of looked into what is the best way to set this up. Uh don't sure if I found it yet, but I want to share today what I have set up. So, uh on Codex, for example, this could be on Cloud, Open Code, whatever, we have these sub agents, right? So, you can see here we have this sub agent. And this could run on smaller models if we have this hard data pipeline. So, I ran me my on 5.4 mini OpenAI GPT 5.4 mini. This is a very fast model and it can do like really good on these structured outputs.
Let's say we get some data from a web socket or something related to our position. So, let's say our position is like a 10x short leverage on SP 500. We can kind of mine that data and the sub agent can fetch that because we really want to save tokens when we feed that into kind of let's say our main model here, right? Let's say it's Codex 5.5.
So, we want the sub agent to kind of monitor this and feed this into our Codex agent, our main agent. And it uses this heartbeat to check this data and make like a let's say like a new decision on our position, let's say every 30 seconds or something. So, this is what I've been testing out and I think I found something that works, at least. Maybe there's more work into it, but I wanted to share the setup and I'll show you how it works because I think this could be really interesting going forward playing more around it around with this creating like this very autonomous setup that could be hopefully profitable.
So, before we do that, speaking about context and stuff like that, uh this is a good time to talk about today's sponsor, Better DB. So, first off, what is exactly Better DB? So, you can think of Better DB as a monitoring, observability, and caching platform. And for AI apps, the big thing is that Better DB gives you kind of two caches that kind of sits between your app and Open AI, for example, so you stop paying for the same answer over and over again.
So, I created this demo I want to show you that kind of shows exactly off how you can actually use Better DB. So, this is the demo I built, right? So, I set up my Open AI key. Uh I have my model GPT-5.5.
Uh I'm going to set the reasoning to low for this demo. But now you can kind of see uh we can run this now a live test.
I'm going to send these five requests to Open AI, five different questions here.
So, we're going to run this uh first without a cache from Better DB and then we're going to run it with Better DB.
So, when we run the comparison here now, you can see we send the first request to Open AI, what is Valkyrie? This took 4 seconds before we got the response, 197 tokens, 7 seconds, 4 seconds, another 350 tokens, right? And now you can see down here we spent 1,300 tokens. And you can see now we run this with Better DB.
The first one had to do one call to Open AI to kind of get the cache. But after that, we have some semantic hits, we have an exact hit. And you can see we only spent or we created 214 tokens. And we saved this amount per call, right?
So, this is why I have been testing out uh Better DB in my app. So, if you want to do the same, you can follow my link in the description and it's super easy to get started. Big thanks to Better DB for sponsoring this part of the video.
And let's get back to the project. So, let me show you now uh how I set up this. So, I think we're going to do it on Hyperliquid. You can see I have about 900 and about $1,000 in the account. So, let's say we open up our terminal here and we go into I just want to do codex this time. Yeah.
YOLO, okay.
And you can see we are on GPT 5.5 high.
So, what if we do sub agents? And you can see we have one agent here. Sub agent, great. So, what we want to do now is I'm just going to read a markdown file I created to kind of set up this. I just called it heartbeat trade MD. And this has everything instructions how to actually run the main model as kind of the main agent and we have the sub agent that is kind of running on GPT 5.4.
And I I guess I could just say I can just say explain the sub agent, what model is it running, and the task. And you can see uh maybe we can blow this up a bit. Maybe something like that. And you can see the sub agents is a read-only trade data reporter named trade data reporter. It's intended to run as a on a fast model specifically specifically GPT 5.4 mini.
And it reads files such as live heartbeat everything we get from the websocket. I'm just going to skip that.
And this it feeds into our main agent.
The main agent uses a sub agent's JSON digest as input. So, we do like a refresh 30 seconds. So, the main agent sleeps for 30 seconds, gets the input from the sub agents, make a decision on our live trade, okay? So, this is basically how we are set up. So, why don't I just show you like a live example now of how this works? I think this is much better than me just talking about it.
So, let's say we wanted to do something like let's say we wanted to do something like this. So, let's set a $50 margin SP 500 short, 10x leverage. So, let's just do that. Let's also add the goal is to make $1 profit in 30 minutes. So, we want the system to have something to aim for, right? Because if you can update the goal, it can make decisions based on the goal. So, let's say we wanted to only make like here $1 profit in 30 minutes.
This means that the decision it makes based on the heartbeat could be different if we wanted to make $10. Then it has to adjust the risk, right?
Because risk is based on if you're going to make $10 on a $50 margin in like 30 minutes, you have to take more risk. If we're going to do $1, we can do lower risk, but maybe yeah, do some other stuff. There's also something called {slash} goal. Oops. {slash} goal on on the Codex. So, we can do like a set goal. This is also something I'm going to look more into. Okay, so you can see here now Codex asked me like a question, "What is the minimum acceptable loss in dollars for this trade?" So, I'm just going to say 100. And you can see we have our target profit. We have our trade set up here, time stop 30 minutes.
We're going to do one live leg. And we can add and we can add hedges. We can adjust positions, lowering, tightening risk, time stop, exit. We can take money off the table. And everything. So, now I think we're just ready to set this position up and we're going to start monitoring. And you can see here Codex does some calculations. A $1 profit needs roughly a 15-point down move down. A little $100 stop would sit likely be on liquidation. So, I'm treating the 100 as the current loss.
So, this is what we want to see. We want to do We want to see the agent calculate some kind of strategy before every trade. You can see it fetched the price is around this. And it talks about this set a we wanted. And from this it can kind of calculate some initial parameters to actually reach our goal. So, this is exactly what I wanted to see, and I'm super happy that the system is even picking this up after I have kind of created it and running it in like a new different trade that we have done before. Okay, so I think we are ready to kind of place the order now, and we should see a position here come up anytime. Yeah, perfect timing. You can see we went in with $50 margin on 10x short on SPY 500. Perfect. So, we should get like a confirmation here now from Codex that we are live, and we should fire up our uh sub agent, our heartbeat to monitor this. And you can see I'm launching the trade data reporter sub agent now, and we'll use this to compact the facts for the 30-second parent uh heartbeat loop. Yes, and you can see we spawned this. We can see we are on GPT 5.4 million in low. Okay, we could have been on maybe Oh, that's fine.
Uh and you can see this is running, and we are waiting for this. This is now fetching our data from our web socket that is of course related to our position. That is uh 10% done and finished waiting, and you can see we got all this data, and now our main agent that is kind of not our sub agent of course is going to read all this. You can see P&L is about plus 10 cents.
Yeah, that matches perfect. Uh now uh it's going to do decision for this heartbeat is hold. The path is still acceptable, and the configured TP is a clean exit path. Yeah.
Perfect. So, this is exactly what I wanted to see, and this is looking quite good. Uh but for the video's sake, uh we're not going to just keep watching this. That's a bit boring. Uh but I want to show you an example of let's say we want to do a hedge now, or let's say the signal was hedge. So, let's see what happens if we if we did that. So, let's just do let's do how would you solve a hedge signal on the current trade with our goal in mind?
So, let's just see how Codex will handle this. This is of course not realistic, but I want to just to show you on the video how our model can adapt on the fly to like a hedge signal on the current trade here and what it would do if that was the case. So, what is kind of interesting here is that you can see if the hedge signal was real, I would not short long the S&P 500. I would use a separate corrected long probably Nvidia as a partial equity hedge. So, we're going to go the opposite end of short.
We're going to do long Nvidia and it's going to using these numbers to calculate this. I think this is quite important. And a reasonable hedge shape would be around 25% hedge ratio. So, we're going to do like an Nvidia. So, it does some calculations here and it sets this up right and it's just going to fire this off and we're going to see we're going to take a long Nvidia position as a hedge to our yeah, I guess $1 goal here on the short position.
As I said that, you can see we went in here 5x Nvidia long as a hedge to our this position. So, this is what I mean and this is exactly what I wanted to see because this kind of opens up a whole new kind of thing we can do going forward with this and I think it's going to be super interesting to actually follow this and see what kind of systems we can set up and try to automate this. This is kind of my end goal, right? So, we just want to say exit the Nvidia position hedge, but double the margin on S&P 500 as the signal is really strong now. Let's capitalize.
So, what we want the agent to do now, if the signal was this, uh let's say it saw that SP signal was really strong, had good momentum, we could uh double down and kind of double our position just for a moment or something like that. So, now I want to see if we exit this Nvidia trade uh Nvidia hedge, and we want to double our value here uh on the margin.
Let's see if we can do that. And you can see for SP500 the strong signal at will be another 50 same side short at 10, add to position equals true. Okay.
But remember, we will get a different price now, but still you can see hopefully now we're going to exit this one, and we're going to double our position value here. And you can see we did double this. Now we are on 98 margin, and now we're just going to exit this. And yeah, we are where we wanted to be. And there you can see we left that, and now we are kind of left with this. So, I think that's uh everything I wanted to show off. And yeah, as you can see we are up and running again, so that's great. So, uh one thing I wanted to mention that next video, or probably in a video in the future, we're going to look more into this {slash} goal, because I think this is something we can implement with great success in this type of system. And this uh use {slash} goal when a task needs Codex to keep working across turns towards a verifiable stopping condition. So, I think this is very good for long running coding work, and this is also good for the setup we have. But that's going to be a different video. So, now I'm just going to close out the position, but basically uh this is what we had a look at today. And I'm going to I'm going to look more into it, and I'm going to come back with an update, because this was kind of my initial take on this, and I'm sure there are a lot of improvements.
So, if you want to see that, uh please uh give this video a like, subscribe, and I will keep you updated on all agentic AI trading, what we learn about it, and hopefully we can start making some interesting decisions.
Don't forget to check out today's sponsor, Better DB, if you want to do something with your tokens and your contacts control. We have a growing community over on Discord, so feel free to drop by. And if you want to talk anything about AI automation, AI agentic trading, or something like that, you find the link in the description. And we are, yeah, a lot of people here now, so it's going to be very interesting to see what people do. So, thank you for tuning in. Have a great day, and I'll see you again soon.
Related Videos
OpenHuman VS Hermes AI: Who Wins?
JulianGoldieSEO
285 viewsβ’2026-05-29
Long-Running Agents β Build an Agent That Never Forgets with Google ADK
suryakunju
142 viewsβ’2026-05-30
This computer is made from real human brain cells. And you can buy it.
Talktmsmedia
3K viewsβ’2026-05-28
BREAKING: Microsoftβs New Image Generating Model Beat Out GPT 1.5 and Nano Banana 2
aimmediahouse
122 viewsβ’2026-06-03
I Made the Same Anime Fight Scene in Every AI Video Generator
NobleGooseAnime
295 viewsβ’2026-05-30
Nvidia Bets Big On AI PCs | New Chip To Power Windows Laptops | Technology | AI Updates | N18S
cnnnews18
3K viewsβ’2026-06-01
I Tested NEW Opus 4.8 on Four Projects (Updated LLM Leaderboard)
AICodingDaily
298 viewsβ’2026-05-29
3D Platformer Update - NO CAPES
SolarLune
294 viewsβ’2026-05-30











