**Build a Fully Automated Trading Algo with AI | Part 2 | No Coding Required — Transcript & Summary | SozAI**
Source: https://sozai.app/transcript/build-fully-automated-trading-algo-ai-part2/

Learn how to build a fully automated trading algorithm with AI, focusing on static IP setup and order placement using Kite Connect API, no coding needed.

## Key Takeaways

- Static IP whitelisting is mandatory for fully automated order placement in algo trading.
- Dynamic IPs from mobile or typical broadband connections are unsuitable for fully automated algos.
- The Kite Connect developer account allows IP whitelisting with a weekly update limit.
- API keys are sensitive credentials and must be kept secure.
- AI tools can significantly simplify algo development, reducing the need for manual coding.

## What the video covers

- This video is a continuation of a previous tutorial on semi-automated trading algos, now focusing on fully automated algo trading with order placement.
- It explains the importance of static IP whitelisting for order placement APIs as per SEBI regulations.
- Static IP is defined as a permanent internet address required for auditability and security in algo trading.
- Viewers are guided on how to find their public IP and add it to the Kite developer account for whitelisting.
- The video clarifies that dynamic IPs, such as those from mobile hotspots, cannot be used for fully automated trading.
- The tutorial builds on the previously created dashboard and Kite Connect app to enable full automation.
- It covers practical steps to retrieve the IP, enter it in the broker’s system, and the update policy allowing IP changes once per week.
- The video emphasizes the security of API keys and advises not to share them.
- It also touches on algo signal scanning, stop loss placement, and optimization concepts.
- The overall approach uses AI tools like ChatGPT to facilitate algo development without coding.

## Chapters

1. 00:00 Introduction and Recap of Semi-Automated Algo
2. 02:38 Understanding Static vs Dynamic IP
3. 04:41 How to Obtain a Static IP for Algo Trading
4. 06:47 Adding Static IP to Kite Developer Account
5. 09:18 Static IP Update Policy and Broker Requirements
6. 10:52 Overview of Algo Signal Scanning and Stop Loss
7. 13:10 Security Considerations for API Keys
8. 19:00 Using AI Tools to Learn Kite Connect API

Answers

## Questions about this video

Why is a static IP required for fully automated algo trading?

A static IP is required to whitelist the IP address from which orders are placed, ensuring auditability and compliance with SEBI regulations. It helps brokers trace order origins and prevents unauthorized access.

Can I use my phone hotspot or dynamic IP for fully automated trading?

No, dynamic IPs such as those from phone hotspots change frequently and are not allowed for fully automated order placement. You must obtain a static IP from your internet service provider.

How often can I update the static IP in the Kite developer account?

You can update your static IP only once per calendar week, so it is important to ensure the IP is correct before submitting it.

## Full Transcript — Download SRT & Markdown

00:00

Speaker A

So Aka and I recorded an algo video previously, and we had an overwhelming response to that. In the video, we asked if you guys wanted to understand how to do a full-fledged algo, a fully automatic algo with order placement, and

00:16

Speaker A

the response was quite amazing. Uh, we were surprised, and this video is for all of you who commented saying that you want a full-fledged uh algo. [music] And uh, we are going to be doing that today.

00:29

Speaker A

But uh, if you're new to this uh channel, if you're watching this video for the first time, then please do make it a point to watch the previous video where we recorded, which was on semi-automated algo. Uh, we've established the uh

00:44

Speaker A

premise for algo trading there. Uh, including setting up the infra required for developing an algo, which involved downloading uh Codeex, which is now called ChatGPT. They've changed the naming convention. We also downloaded um and connected Python libraries. Python

01:04

Speaker A

library. We connected uh, we created an app on Kite Connect. We also uh instructed Codeex or now ChatGPT to download uh Kite Connect Python SDK.

01:17

Speaker A

Yeah. Yeah. So all of that was discussed in the previous uh video. Please do watch that. We are picking off this video keeping the previous video as base. So in the last video, as I just mentioned, we developed a semi-automated algo, and in

01:32

Speaker A

this video, the objective is to develop a fully automated algo. Now Akshai, before we deep dive, is there anything uh different in terms of setting up the infra required on the LLM side? Yeah. So with the Algo uh infra

01:52

Speaker A

that we had created, uh there is no difference. Uh, but with the Kite developer account that we had created, uh last video also we had touched up on the static IP.

02:01

Speaker A

Uh, that we'll have to revisit today because the order placement via APIs require a static IP uh whitelisting.

02:09

Speaker A

Okay. So that is the only bit that we'll be touching upon today, and we'll be building up on the same dashboard that we built last time. So why don't you start with helping me understand what static IP is?

02:20

Speaker A

Please do remember I'm I'm not a tech guy. I don't have any tech background.

02:25

Speaker A

So please dumb it down as much as you can and tell me what static IP is.

02:30

Speaker A

Why should I care, and how do I get this? So uh, an IP is basically in like the simplest term it is your internet's address.

02:38

Speaker A

Okay. So uh, you have two types of IP generally. So you have static IP. Uh, that is your address that does not change, and then you have dynamic IP which changes often.

02:48

Speaker A

Uh, so there is a SEBI regulation now which was enforced from April 1st. Uh, there are a lot of different uh rules that have come up, and one of the rules is to whitelist your static IP.

02:58

Speaker A

Okay. So essentially now for every broker you have to give them your static IP where your algo runs from, and that IP as I said static so it it cannot change often. [music] It has to remain the same

03:10

Speaker A

uh throughout. Okay. Uh, on different broker platforms you can change it uh depending on how they allow you to change it. Uh usually as a rule it is a week uh before you can change your IP again and again.

03:22

Speaker A

I don't know if this analogy is correct. So tell me if this is if my understanding is okay. So static IP is basically a way for the regulators to identify who this person is and where the order is coming from.

03:36

Speaker A

Is that is that correct? Yeah. So it is like an audit auditability you can you can trace where the orders are coming from.

03:42

Speaker A

Okay. Uh, any bad actors any uh if if uh if if an algo goes rogue you can sort of so that they can come back to you and say boss this is on you.

03:51

Speaker A

Yeah exactly. So the brokers know that this is the algo this is it has come the orders are come from this whitelisted IP.

03:57

Speaker A

Okay. So it's just the other bit is that only the orders API are gated by the IP whitelist. So which is why in the last video we were able to do everything for the data using the data APIs.

04:09

Speaker A

Uh, but now since we are building a fully automated system we would have to revisit the static IP.

04:14

Speaker A

Now just to reconfirm I think when we are talking about fully automated the only difference between what we did previously and what we are about to do today is the order placement. So order placement is going to be automated by

04:27

Speaker A

the algo and hence this is called a fully automated uh system. Yeah. And to do fully automated, we need static IP. Yes.

04:35

Speaker A

Right. And what it is and why we need it, you just explained. How do I get it?

04:41

Speaker A

So there are a couple of things here. So a lot of us uh depending on what Wi-Fi you're using, either we are on a phone Wi-Fi or a broadband or your home or office internet.

04:51

Speaker A

U you have to ensure that while you have an IP that you that is visible, you have to ensure that it is remain static. So if you're on your phone Wi-Fi, unfortunately IPs are not static. They change based on your cell tower

05:04

Speaker A

location. Uh, it could be the same with your broadband also your home Wi-Fi uh or your office Wi-Fi. In that case, you'll have to basically reach out to your uh internet service provider and ask them to assign you a static IP.

05:18

Speaker A

You're saying I can't hotspot and do a fully automated algo. Yeah, you cannot hotspot and do a fully automated algo. So I will have to call my telecom provider, Vodafone, Jio, whatever and ask them please give me a static IP

05:32

Speaker A

and follow whatever their procedure is. So that is step one. Yeah. Okay. So now for this video have you done that?

05:40

Speaker A

Uh yeah. So for this video we are at a static IP. We are at a location where the static IP is set. Uh, but I'll quickly show you how you can retrieve your static IP.

05:49

Speaker A

Okay. Uh, and also where to put it on the Kite developer account. Okay. Uh, yeah. So we'll just navigate to uh your browser and all you have to do is search here is what is my IP.

06:01

Speaker A

My IP. Okay. This is the simplest way to know what your static IP is. Uh, this is the public IP that is required uh uh to be whitelisted.

06:09

Speaker A

So there is no I so there are two different types of IPv4 IPs. You'll have an IPv4 and IPv6. Most brokers allow you to put uh both or you could choose to put either one.

06:20

Speaker A

Okay. So in this case I can see my IPv4 is this. I I'll just copy it here or you can just copy directly.

06:26

Speaker A

I'll navigate to my Kite developer account that we had created last time. No, but how do I know that is a static IP?

06:34

Speaker A

Whatever IP you showed me, how do I know that is static and not [laughter] dynamic?

06:39

Speaker A

Yeah, essentially if your IP doesn't change often if your IP if you if you come tomorrow and it's a different IP, your IP is not static. It is dynamic and it's changing.

06:47

Speaker A

Okay. Um so yeah so I copy the IP from here I navigate to the Kite developer account uh it's already logged in in my case uh [music] and we have the the Kite application that we created last time

07:02

Speaker A

the my first my first algo is what we created in the previous video previous video yeah and we can see the status is active as well so um it's still continuing uh right now [music] uh we have a sort of a indication here

07:16

Speaker A

about the static IP Uh so very quickly now I'll show where to go and paste it. So in the top bar we have a profile tab where if we scroll down a bit uh we have a section for IP whitelist.

07:29

Speaker A

Okay. This was also available when we had first signed up when we had created the sign up account.

07:35

Speaker A

So that time we had skipped it but this time we we'll be putting the IP white list.

07:39

Speaker A

Okay. Uh so in my case I've already added the IP here. Uh if if it's not added on your end, you can just simply copy it from here.

07:48

Speaker A

Uh go to Oh yeah. So there is an update policy lets you know how often you can update it. So it can be updated only once per calendar week.

07:56

Speaker A

Okay. Yeah. This is what you mentioned. Exactly. So once every 7 days. Yeah. Understood.

08:00

Speaker A

And yeah, so please double check the IPs as you'll not be able to change them again till the next Monday.

08:05

Speaker A

Okay. So what you're showing is on uh what you're basically showing is how to enter this static IP on Kite developer account. But it doesn't matter which broker you're trading with. They all provide this facility for you to

08:20

Speaker A

submit your static IP. So by rule every broker needs to have if you're placing orders via their API the

08:32

Speaker A

So yeah, I'll just quickly put I agree. And all you have to do here is change your add a static IP. If there was one more in this case, I'll just be adding one below it. So So you mean to say I can add multiple

08:45

Speaker A

static IPs. You can add only two static IPs. So if ever there was a connection issue or something happens, uh you could add uh another static IP and your ALGO still sufficiently continuously. It's like a failover mechanism. Okay.

08:58

Speaker A

Yes. So also if in case people have the IPv6 also you could add both in [music] that case you will have both your IP.

09:06

Speaker A

By the way I I don't know what is IPv6 versus IP IPv4. Uh but I will not waste time on this video to figure that. I will Google it.

09:16

Speaker A

No. Yeah it is just it is basically different IPs uh but for your same connection.

09:21

Speaker A

Okay. Um so yeah in this case I've added the current uh IP. It's already listed and once you add it here, you have to simply go down and click update and it'll automatically update your accounts IP.

09:34

Speaker A

So right now it's already been updated and since I don't want to re-update it, I'll just leave it as is.

09:40

Speaker A

So what we've done so far is so we did whatever we did in the last video which is setting up the algo connecting it to kite connect and uh generating the signals.

09:50

Speaker A

Yeah. So from there the first step today is to ensure we give our static IP.

09:56

Speaker A

Yeah. Done. So now that it is done how far where are we in the stage uh in the timeline of creating the algo are we good to go right away or is there anything else that needs to be done?

10:10

Speaker A

No no no we are good to go right away. There is we have finished everything that is required. Again this was like the the layer of algo layer that we are building last uh last [music] uh time.

10:21

Speaker A

Uh the only thing missing last time was the IP white list that has been added and now we can just go to building the algo end to end.

10:29

Speaker A

Okay. So that means to say we need to discuss what the algo is. Yes.

10:33

Speaker A

Okay. What is it that you have in mind? Yeah. So this time so last time we did a moving average crossover which worked very well for a screener. Yeah, this time we can probably do a positional algo something slightly

10:45

Speaker A

different where we will we will try and find stocks that are breaking out both in volume and price.

10:52

Speaker A

It's a price volume breakout. Yeah. Okay. And our entry would be based on uh how far if there is a if there is a retracement of the stock to uh the breakout candle.

11:04

Speaker A

So essentially we want to catch stocks that have not already broken out or broken down we are taking a long only positional algo.

11:10

Speaker A

Okay. So if there is a retracement happening uh we have a certain tolerance limit and if the stock is retracing into that tolerance limit uh we will put a buy GTT order at the low of the breakout candle.

11:23

Speaker A

Great. Uh let's now just define this a little further. Yeah, I understood it's a price volume breakout uh and you want to buy it when there is a retracement.

11:33

Speaker A

Uh but how do you define a price breakout? How do you define a volume breakout? Is [music] it 1x the average 2x? What is it that you have in mind?

11:42

Speaker A

Uh yeah. So uh in this case first uh before we discuss what the volume breakout is. So we'll be doing it over nifty 100 stocks. So we have a universe decided and for a credible volume breakout uh I

11:54

Speaker A

think anything above 3x of the volume of the average for the last 20 you could 20 trading days or one month.

12:01

Speaker A

Okay. Uh and uh and similarly a price breakout as [music] well. So it's breaking out the previous uh 20 candles high.

12:09

Speaker A

Okay. And if these conditions are satisfied uh there is a signal generated there is there is another part of the signal which is that the stock also shouldn't have broken past its tolerance. Uh so from the high of the breakout candle

12:23

Speaker A

we will we will have a 1% high and a 1% low and the stock technically has to trade in that band.

12:29

Speaker A

So it shouldn't be a stock that has already broken out and then come back down after many days. uh and so yeah so those are the the final list of stocks that satisfies the volume price and tolerance [music] will be the list we

12:41

Speaker A

will so I'll just quickly summarize that uh basically you are looking for stocks that have a volume breakout in the sense you are looking back 20 days prior today's volume should be 3x more than the average of last 20 days yeah

12:57

Speaker A

condition one condition number two is you're looking at the price you're comparing today's goes uh against the last 20 days and it should be uh it should be the high.

13:09

Speaker A

Yeah, it should be greater than the previous high. Yeah, it should be greater than the uh close of the last 20 days.

13:15

Speaker A

Yeah, the high. And then you are also ensuring after the breakout has happened, the stock is trading within 1% tolerance of uh of the high point.

13:27

Speaker A

Yes. Right. Yeah. And then you also mentioned about retracement. Yeah. So you're looking for the stock to have after doing this 1% tolerance, it should have retraced back.

13:39

Speaker A

Yeah. So the tolerance is technically your retracement. So because you put a band uh the stock is trading, it's it you could say it's accumulating at the breakout candle range.

13:48

Speaker A

Okay. And uh our assumption is that it might come down to the low of the breakout candle. So that's where the buy GT is.

13:55

Speaker A

Okay. Okay. So when this happens, you're going to place a your Algo is going to place a GTT order. Yeah, actually this sounds like a fairly straightforward algo.

14:04

Speaker A

Yeah, ideally before we develop an algo and take it live, I would personally like to figure out if the idea is worth pursuing or not and for that we need to back test.

14:16

Speaker A

Yeah. Right. We won't back test today because we've not planned for that. But guys, please let us know if you want to figure out how to back test an algo.

14:27

Speaker A

uh then I'm sure we can uh do a video on that. So please do comment below and let us know if you want us to do a video on back test and if there is a good response we will consider doing it.

14:38

Speaker A

Yeah. So um so that is our algo that we have defined. Okay. Um so uh the next step would be uh so in the last video we had built a dashboard.

14:48

Speaker A

Okay. Uh we would be building all of this onto the same dashboard. So uh it isn't we are not doing the entire uh algo dashboard development journey this time.

14:56

Speaker A

M so on the same dashboard the same last step that we had we will be prompting um chpd uh it's no longer called codeex it's called chp we'll be prompting uh chhat gpd to build onto the same algo

15:08

Speaker A

okay so so very quickly the first step would be we would launch the dashboard that we had built last time okay so um so basically here you are referring back to the same folder where everything was exactly yeah so depending on it should

15:24

Speaker A

be available in your previous chats so the last time it was called my first algo.

15:27

Speaker A

Yeah. Uh you can just create a new chat there in the same folder or if you're stored if the folder is in your uh uh desktop you could directly navigate to [music] Exactly.

15:38

Speaker A

So now uh any since it was there in my previous chat I'm just going to create a new chat here in that same folder and ask it to [music] can you launch the dashboard?

15:55

Speaker A

Yeah. So, it's going to take a couple of minutes to launch the dashboard. Okay.

15:59

Speaker A

By the way, all the prompts that we are using will be made available in the description.

16:12

Speaker A

Yeah, Karthik. So, uh that GPT has launched it for us. Uh it's worked for about 1 minute and 30 seconds and told me where it is hosted it. So, I'll just quickly right click and open it in an

16:23

Speaker A

external browser. [music] Done. So this is our UI that we had login UI. This is exactly what we built last time.

16:28

Speaker A

Last time. So the same steps I'll have to put my API key, API secret and the request token that we had done the last time.

16:34

Speaker A

Correct. Okay. So um I can quickly if I had stored it on my desktop you can take it directly from there. Uh I am just going to navigate to my account.

16:44

Speaker A

Yeah. So I'm going to copy the API key from here. Paste it here. Uh I'm going to take my API secret.

16:56

Speaker A

Yeah. So the API key and the API secret we got it from the developer account.

17:01

Speaker A

Okay. Um the last time I had saved a I had saved it I bookmarked the URL for the request. Okay.

17:07

Speaker A

Correct. Yeah. So I'm just going to use the same bookmark and I'm going to login.

17:10

Speaker A

Yeah. By the way guys uh just to reiterate the fact your API key, your API secret uh is as good as login ID and password. Please do not share it with anyone. This is sensitive information.

17:23

Speaker A

So this is meant only for your use. So uh again like [clears throat] last time we have been redirected to google.com. Okay.

17:30

Speaker A

And at the top the URL is what we care about. So we have a bit that says request token. Yeah.

17:36

Speaker A

And the same process again we just copy everything after the request token uh after the equals. and we going to go back to our UI and we're going to log in.

17:52

Speaker A

Yeah. So this is the same dashboard that we had last time. Uh the signals tab I can generate the signals as well.

17:59

Speaker A

Okay. So now we will be building this algo onto the uh the same dashboard that we have here.

18:05

Speaker A

But just to clear my confusion so whatever we did last time was a different set of conditions. So we are working with a different algo today.

18:12

Speaker A

Yeah. Right. So okay. So what what we did just the meat of the algo for the last video has nothing to do with what we are going to do.

18:22

Speaker A

Yes. Now so everything we prompt right now will be what the algo is. So this was the last time's video that we had done the crossover signals that we generated.

18:30

Speaker A

Uh this time we going to create a new tab for our algo signal. So the way we'll approach this automation is that first we'll again very similar to what we did with the crossovers.

18:39

Speaker A

we'll build our signals because you need to confirm uh at the end of it I'm just writing a prompt but I need to confirm the signals are true or not.

18:47

Speaker A

So very similar to the last time we'll build our signals for this and we'll confirm on our kite portal and then we'll go ahead with building the automation.

18:56

Speaker A

Done. Okay. Um so I already have the prompt ready. I'll just navigate. So these signals are useless for us today.

19:02

Speaker A

Yeah. So this is just the last time's videos. Yeah. You just wanted to show it.

19:07

Speaker A

Yeah. [music] Okay. Yeah. So, I'm just going to navigate back to the chat GPT codeex that we have. And in the same uh chat, I'm just going to place the prompt here.

19:16

Speaker A

Yeah. By the way, guys, this prompt is the meat of the algo. We will make this available uh for you in the description.

19:24

Speaker A

Uh this is a fairly lengthy uh prompt. Uh I don't think so we can go through this in this video. But please do check uh the prompt in the description uh or wherever we are going to make it

19:34

Speaker A

available. If you have any uh questions around that, please do feel free to comment and we will get back uh with our response for that.

19:43

Speaker A

Yeah. So just going to uh but just to reiterate the prompt is basically explaining to Chad GPT whatever we discussed a while ago in terms of identifying price and volume breakout and also ensuring that the price is within the 1% tolerance band.

20:00

Speaker A

Yeah. Yeah. So I'll just and this prompt does not include order placement yet, right?

20:08

Speaker A

Yeah. So just to clarify again, yeah, this prompt does not include order placement yet. So the way we would go about building automation uh because automation is a real meat. It it actually uh impacts your capital. So uh

20:20

Speaker A

how we would go about this is first we'd build the signals. We confirm if what we are thinking about is exactly what codeex has been able to think as well or produce as well for us.

20:31

Speaker A

And once that confirmation is there, we would go about doing the uh automation process.

20:35

Speaker A

Makes sense? Yeah. So yeah, this is going to take a couple of minutes as well.

20:40

Speaker A

Okay. Um just quickly glancing through the prompt, it's the same logic. There's a new tab, Algo signals tab. It tells you how how how far back you want your uh volume loop back. for 20 days your price look back uh your multiplier that we had

20:55

Speaker A

discussed the 3x and the tolerance that is there in percentage so and then so it has a little bit about what the strategy is and then it also tells how we want it to look so how the table would look at the end

21:08

Speaker A

so that's what this prompt does uh we would have it in the description maybe uh you can go it's it's a fairly easy Yeah.

21:22

Speaker A

So, yeah, Karthik, it's worked for about 8 minutes and it's uh it's done what the prompt has told it to. So, let us know what is happening here.

21:31

Speaker A

Uh very quickly, we'll just navigate to the dashboard. Okay. So, in the dashboard, we are Are you expecting to see signals?

21:38

Speaker A

Yes. So, this has also scanned the price history. Yeah. So, it has also it has built it for us.

21:45

Speaker A

It's just one button away from scanning generating the signals for us. So, as you can see here, a new tab has been added called Algo signals.

21:52

Speaker A

I'll just navigate there. And there's a button. Oh, it's it's scanning already. It's already scanning.

21:57

Speaker A

Yeah. So, since it's launched the dashboard, it is also scanning. Okay. So, in your prompt, you you specified to call this tab Algo signals.

22:06

Speaker A

Yeah, I specified to call it Algo signals. I gave it all the rules that I had and now it's going through the universe of 100 stocks. So it has told us yeah there are four triggered breakouts.

22:17

Speaker A

It's scanned about 100 stocks and uh it has basically it is also ranked it by age here.

22:24

Speaker A

Okay. So the most recent uh breakout is cold India is cold India. Yeah. Can we go to kite and uh check and validate whether it's as per our this thing.

22:36

Speaker A

So uh I think it's we just one more now it's finished it scan. So it has got us five stocks.

22:42

Speaker A

Okay. Maybe we can just check co India because it's the most recent. Yeah. So I'll just navigate to uh my kite.

22:49

Speaker A

Okay. Okay. So I'm already logged in. Okay. Uh very quickly we'll just search [music] coal India.

23:04

Speaker A

So also I forgot to mention it's on a daily time frame. Yeah. So with respect with respect to coal India, we can see there is a volume breakout happening. Okay.

23:13

Speaker A

So the day also was given. So one second can you go back to that?

23:17

Speaker A

Yeah. Yeah. So I I see another large green candle. Yeah. Which is slightly larger than the current day candle.

23:25

Speaker A

Yes. But I'm guessing this is um because it's taking a 20-day average. Yes. [music] So it's taking a 20day average and the signal that is giving the age is 2 days ago. So it is this candle and it is taking the last 20 days

23:40

Speaker A

that is here. So about a month of trading day. Yeah. And so the candle volume is fine. I think the candle is also breaking the high the previous high 20-day high. Yeah.

23:51

Speaker A

Oh okay. And so now the the logic here was at the high of the close of this candle there is a tolerance limit that is there. As long as the stock closes within the tolerance limit, our understanding is

24:04

Speaker A

that it would come and retrace back eventually to the low of this breakout candle, [music] which is where we would be placing our buy GD order.

24:11

Speaker A

Okay. Uh maybe we see one more stock just as confirmation. Yeah. Uh I think there was KOC.

24:18

Speaker A

Yes. So Kak about 6 days ago. 6 days ago. Yeah. So just navigating [music] to Kodak.

24:26

Speaker A

Yeah. So uh 6 days ago is this talk. Mhm. Uh 3. Yeah. So this candle here is the breakout is 3x the average breakout of the last 20.

24:37

Speaker A

Uh and again it's within a price range here. [music] Understood. Yeah. So that satisfies our tolerance as well.

24:45

Speaker A

So both a volume and a price breakout happening. Yeah. And within the tolerance range.

24:50

Speaker A

Within the tolerance range. So essentially the tolerance range is to prevent. So if KOTC had rallied all the way up and then come back down, it is a Yeah, you don't want to be stuck in the fall signals. So the tolerance helps.

25:03

Speaker A

This is the candles that remain within the tolerance range. So KOTC also satisfies this.

25:08

Speaker A

Yeah. So Algo now has uh I mean clearly it is identifying stocks based on the conditions that we specified.

25:18

Speaker A

Uh great. Uh what is the next step? The next step is order placement, right?

25:23

Speaker A

Which is the next step is the automation which is GTT which is the buy GTT. So very quickly what I'll I'll just explain. So we would be putting a buy GT at the low of the breakout candle.

25:34

Speaker A

Okay. And uh since risk management also is something that we should always include in alos uh uh I'll be adding a 2% sorry I'll be adding a 5% uh stop-loss.

25:45

Speaker A

Yeah. So so okay part one is we've identified the breakout. Yeah. The second part is once uh the breakout is identified.

25:56

Speaker A

Obviously when you develop an algo, you're not going to go back and check each and every signal.

26:01

Speaker A

Yeah. You would want the system to automatically place the GT order for you. Yes.

26:06

Speaker A

Right. Uh and then once the GT is placed, the third part is risk management.

26:11

Speaker A

Yeah. Which is placing of a stop-loss order. Yes. So so that stop-loss order will be triggered once the GTT is uh in the is in place. Right.

26:20

Speaker A

Yeah. So the stop loss will be triggered once the order is complete complete of course.

26:24

Speaker A

So once the trigger GT trigger is hit uh uh again so this is an algo that you will have to authenticate every morning.

26:31

Speaker A

So you will you will log into this algo and every morning it will check whether the GTT triggers that it had that it had placed the previous day or the previous couple of days has been hit or not.

26:41

Speaker A

And depending on if those signals have been hit it will then place a stop loss just to protect your So basically in that way correct me if I'm wrong. Yeah, the algo not only scans for signals.

26:54

Speaker A

Yeah, it will also scan for the status of the order that has been placed.

26:58

Speaker A

Yeah. If an order has been placed, GTT has been placed, then it will place a stop-loss order.

27:05

Speaker A

Exactly. So it is it is not only finding signals for the day, it is also ensuring that the orders that are placed by this algo uh the last couple of days or whenever you have been running the algorithm and

27:17

Speaker A

it's placed these GT orders, it has to keep a memory of those orders. Okay.

27:22

Speaker A

Uh and so effectively it's keeping a state it's it's managing the state of all the orders and all the actions it has been doing.

27:28

Speaker A

Okay. Okay. Now let's say a signal is generated uh today at 11:00 and uh and I want the order to be placed you know uh the GTT to be placed uh right then because the condition is satisfying let's assume it's come to the

27:46

Speaker A

low of the breakout candle. Yeah. U so for that will the algo do it automatically or do I have to run it again? No. So the first time you log in uh it could be morning by 8 or 9 or

28:01

Speaker A

whenever you tend to log in. Uh as long as this algo or the system doesn't shut down the algo is constantly working.

28:08

Speaker A

Okay. So now that means to say morning as soon as I authenticate or in simple words run my [music] algo uh it'll continuously scan monitor the placement of GTT.

28:22

Speaker A

Yeah. Once GTT is placed, the uh stop-loss order will also be placed. Placed. So there is no need for the user to run the algo again and again.

28:32

Speaker A

Yeah. Yeah. There is no need for the user to run the algo again and again.

28:35

Speaker A

Yeah. No need to press that run algo button. Yeah. So just the first time in the morning when they set up the system, they would just need to click the button and see the new orders or just run. The button

28:46

Speaker A

is essentially to run the dashboard. Yeah. And post that it is automated and probably this is why it is called a fully automated system.

28:53

Speaker A

Yeah. Yeah. Okay. Super. So let's uh so yeah. So now we'll get to the next problem.

28:58

Speaker A

One second. I know the next thing that you're going to do is place GTT.

29:02

Speaker A

Yeah. Uh but for the sake of my satisfaction, can you show me your GT order uh tab? I just want to see it's all empty. I just Yes. Yes. So I'll just quickly navigate to my orders tab. So no GTT orders, no

29:16

Speaker A

orders as well. So completely empty. So after your next prompt to the ALGO, yeah, I'm assuming GTT orders will be placed.

29:24

Speaker A

Yes. So this section should be filled with the orders that are there, the signals that are there in the Okay, exciting. Let's do that.

29:31

Speaker A

Yeah. So the next step is to add the next prompt. I'll quickly go back to our chat that was here.

29:36

Speaker A

Okay. And place a prompt here. And it should automatically by the way this prompt also will be made available uh to you in the description.

29:49

Speaker A

But then please understand that this prompt is actually going to place an order. So we will modify the prompt uh to remove the order placement and share a modified prompt with you all in the description. Uh a do you want to talk

30:03

Speaker A

about what modification we intend to do with the prompt? Yeah. So with this prompt uh the current prompt that we are using right now will place the orders. So the only thing that we'd be modifying here is we'd be

30:12

Speaker A

removing the order placement APIs that are there. Uh this prompt essentially without that would have everything else which [music] is the logic of your buys at which level it would place the buy GT order. Uh essentially you could think of

30:26

Speaker A

it as a dummy order placement. The prompt that we'll be sharing online would be a dummy order placement. So it'll manage the state of your previous orders. M it'll manage the state of your current order. So and by state I mean uh whether

30:38

Speaker A

those orders are placed or not, whether they're rejected or cancelled. So it'll track it every day.

30:43

Speaker A

Uh just that the order placement bit would not be there in the process. Yeah. Now if I'm watching this video and getting inspired to develop my full algorithm, what am I supposed to do by looking at the second prompt which you're going to

30:56

Speaker A

modify and share? Yeah. How do I do how do I replicate on my own?

31:01

Speaker A

Yeah. Uh whatever we are doing. Um so the prompt will still have the meat of its section which is uh how to place the orders, what level is placing the orders and also the most important part of the

31:13

Speaker A

algo is the state management. [music] Uh essentially when a lot of us build alos for the first time uh we don't end up thinking about state management as a very important bit. So correct.

31:23

Speaker A

Uh if I were to run the without state management, if I were to run the same algo tomorrow, it would place another set of GT orders and then if I run it the next day, it would place another set. So essentially

31:34

Speaker A

there's nothing stopping it from placing orders. So state management is very very essential. Uh it keeps a track of all the orders it has placed earlier. Uh all the signals that are coming right now and whether these orders are completed,

31:47

Speaker A

rejected, failed. Uh it has all the logic there. [music] Okay. So the prompt that we will share will have the meat of the logic just the order placement bit is missing.

31:57

Speaker A

Okay. So yeah Karthik uh the next prompt is also done. It has implemented a GDD placement workflow.

32:12

Speaker A

Taken about 9 minutes to develop that. Yes, it's taken about 9 minutes to do the entire bit. So quickly navigating to the dashboard.

32:20

Speaker A

Okay. So just to confirm it, it wouldn't have placed GTT just yet, right? Yeah, it wouldn't have placed GTT just yet. So this GTT order tab is empty as we saw last time.

32:30

Speaker A

Okay. Uh now it requires there is a GT placement tab that has been created again. Nothing here.

32:36

Speaker A

So every morning we would have to run the scanner. So this is now just to be super clear.

32:43

Speaker A

Yeah. Now I've developed my algo. We've developed our GTT placement uh uh part also. So today is a fresh day. I log in and I run.

32:53

Speaker A

Yeah. Right. So now this is going to look for signals. Yeah. So this is going to look for signals uh for uh so Kota and Cole India should show up again.

33:01

Speaker A

Should show up again and post that signal. So every morning you would log into your dashboard should run the scanner and then we have a new button called run live.

33:10

Speaker A

Yeah, that's what I was noticing. Yeah. Yeah. So this this button essentially runs the algo live constantly. So if there's an order that needs to be placed, it will place the order.

33:19

Speaker A

Yeah. Now before you do this, can we just reconfirm if our GT is empty?

33:23

Speaker A

Yeah. So I'll just quickly go to the GTD tag, [music] we can see it's empty.

33:26

Speaker A

It's empty. Okay. Great. Okay. So going back to the dashboard. Okay. Uh I'll quickly India is there.

33:33

Speaker A

Yes. Kak, Semens, H, and Titan. Okay. So it's going to place GTT for all these stocks.

33:39

Speaker A

Yes, it's going to place GT for all. It's supposed to place at least. Okay.

33:43

Speaker A

So once placed uh it should then also so tomorrow if I were to open the dash dashboard it shouldn't replace the same because these [music] these uh scans these sorry uh breakout triggers would also be there tomorrow.

33:57

Speaker A

Correct. Yeah. Yeah. I mean clearly the Titan one is running for 19 days. Exactly.

34:01

Speaker A

H for 17 days. So you only need to place the order once. Once and then manage or track whether what is happening so that we can then place uh the order again.

34:12

Speaker A

So now the GTT placement tab is also filled populated. It tells us uh the status of the account tells us the buy status whether it is success or not.

34:21

Speaker A

Okay. Uh and then it is saying stop-loss status is pending planned after the buy.

34:27

Speaker A

When the buy trigger is hit again this is the part of the state management.

34:30

Speaker A

Okay. Right. So once the buy trigger is hit then the stop loss would be triggered.

34:33

Speaker A

Yeah. Now actually so just can you just scroll to the left please? Yeah. Yeah. So here u you've decided the quantity to be one.

34:43

Speaker A

Now but in reality a quantity can be decided based on as a percentage of capital. So exactly that that means to say for an algo developer there is this entire unit or part of cash management that can go into algo. Right.

35:00

Speaker A

Yeah. So which we've not done today. We've just by defaulted we defaulted it to one quantity but it can be let's say I have 10 lakh as my trading capital it can be a percentage of that it can

35:14

Speaker A

based on how many how much capital is used uh the algo can see what is the balance capital and then place according to that also exactly right so so that that entire thing is a different universe of trading uh

35:29

Speaker A

yeah so what we have done here is automatic management at the basic step. Uh there is also risk management that we have very small we have applied a 5% risk.

35:38

Speaker A

Uh but ideally you would have order management, you would have your risk management, you would have your cash management. How you decide what is a better uh signal to trade on? So uh we have the signals here.

35:50

Speaker A

Uh but is maybe a younger age better than the older age? Has it been uh [music] retracing for many days? Is that a good signal or not? Yeah.

36:07

Speaker A

Alo that. Yeah. Yeah. So I mean this is just to give a sense of how to develop a fully automated algo.

36:13

Speaker A

Yes. Uh there are several nuances to this. Uh we spoke about cash management. Yeah.

36:20

Speaker A

Checking margins etc. Now obviously like what you touched upon just now is the the recency of the order and and qualifying whether a signal is worth pursuing or not.

36:33

Speaker A

All that's part of back testing also I'm guessing. Exactly. So that video we can do separately if users want uh where we can back test an algo strategy itself.

36:44

Speaker A

Yeah maybe something around optimizing an algo. So we built an algo but what is the optimum parameter of your particular algo? Exactly. Yeah. Now, yeah, you showed you clicked on the GTT placement and we saw this.

36:56

Speaker A

Now, the same thing should also be on kite right? Yeah. So, quickly navigating [clears throat] to the kites terminal.

37:02

Speaker A

So, we can see here RGT tab has all of the same stocks. Yeah. Uh quantity is one.

37:11

Speaker A

Yeah. And so, they're pending a trigger. So, it also tells you how far you are from the trigger.

37:15

Speaker A

Uh and your status whether it is active or not. Okay. Now the stop-loss bit is uh also built right?

37:23

Speaker A

Yes. So the stop-loss bit is also built here. Okay. So very quickly it [music] if I just navigate to the side it tells that it's planned after the buy order is hit.

37:32

Speaker A

Correct. Yeah. Um one more check we can do. So when you're building something like this is will it multip it place multiple uh buys. So if I were to run the same button [music] again run live.

37:43

Speaker A

Yeah. So this is assuming the second day. Ah this is assuming the second day.

37:47

Speaker A

Okay. So that is something that is also a good check to have. Again, uh much of this code is written by an AI though doing it really really well and over time it has gotten really really good.

37:58

Speaker A

Now [music] uh these are small checks that you should always add when you build an algo.

38:02

Speaker A

Right. So you're simulating day two and running. So I'm simulating day two again. So I've run this GT placement says Yeah. So you can say now the account state says already active.

38:13

Speaker A

Yeah. uh it was before it was success and it was order place. Now the state management has taken over and it has let us know that there is an GT already active already in the system.

38:23

Speaker A

So there is no need to place another quantity. Yeah. So this bit is there in the prompt.

38:28

Speaker A

So I mean obviously there are no GTS placed because the because we are still away from far away from quite far away from the thing. Uh I don't know if you can wait for it to trigger.

38:40

Speaker A

Yeah. But assuming that uh it places a GTT order. Yeah. Uh GTT gets triggered then the next step u the algo is expected to do is place a stop-loss order.

38:52

Speaker A

Stop loss order. Yes. Okay. So this while so since the algo runs live every day uh what we have built here is a dashboard that we log into uh we run the scanner and we run it live.

39:03

Speaker A

Run it live essentially keeps this algo uh alive. So as the as the orders are getting triggered so it is constantly checking whether your previous GT orders are triggered and then it places a stop-loss order.

39:16

Speaker A

So let me just summarize whatever I've learned so far. Uh so obviously the first part of this entire thing was discussed in the previous video.

39:25

Speaker A

Yeah. So where we develop the infrastructure to develop our algo right from uh chat GPT to yeah Python libraries and kite connect python libraries and nodejs all that stuff we created an app on kite connect.

39:42

Speaker A

U so that established our algo infra. Uh in this video we discussed we we are we are attempting to take that conversation forward with uh trying to make this entire algo fully automated.

39:55

Speaker A

Uh the first thing that we had we spoke about was the need for static IP uh and how to get a static IP and how to connect that static IP onto our dashboard could we did that on kite connect it

40:09

Speaker A

could be on any broker's platform all of them have uh facility to do that post that was fairly simple it was literally just two prompts uh first prompt was to define our algo and uh let the uh coding

40:27

Speaker A

agent or LLM or chart GPT to uh develop this ALGO for us and it added that ALGO signal onto our dashboard.

40:35

Speaker A

Yeah. Um the second part was uh order placement, right? Uh which is GTT placement for us.

40:43

Speaker A

There's also the third part of stop-loss placement which we've not seen live. Yeah. Uh but I'm guessing it is uh it is in place. the AI has developed it and uh and then you know you everyday log whatever you've developed click on

41:00

Speaker A

run live and this should essentially run your algo seamlessly yes right yes uh before we close the video ashai any piece of advice for aspiring algo traders what they should keep in mind what are the usual pitfalls and uh where

41:20

Speaker A

can people uh where do people usually go wrong? Yeah. Yeah. Um so uh again we we have since we have not coded anything much of our faith is like rested upon ch here in this case.

41:33

Speaker A

So every step there should be a confirmation step. So if you were building a signal if you're just pulling data there has to be confirmation of whether the data you have received is right.

41:42

Speaker A

So best way to check is you pull the data you go back to your kite correct account and you check if the data is correct. Then would be the signals. M so since in the last video we [clears throat] did a moving average

41:52

Speaker A

crossover in this video the signals were very complex there are multiple moving parts of a volume breakout of price breakout and tolerance and we then confirmed it with again kite as well. Uh similarly for order placement also uh the best way would be to instead of

42:07

Speaker A

going to a directly directly adding the orders API maybe uh we add a dummy tab we confirm the buys and the sell levels again because this is your actual capital getting automatically placed as an order.

42:21

Speaker A

So we do a dummy tab and then once you're okay with everything uh we can add the orders API. Yeah. So I understand what we've developed is a positional algo. So runs it could probably some this is something good for

42:36

Speaker A

a swing trader. Yeah. Uh but what about a fully automated system for someone who wants to do shorterterm trading maybe intraday maybe uh buy today sell it tomorrow.

42:50

Speaker A

help me understand what are the order types available, what are the data sets available, how do I learn more about this? Uh give me some overview of that please.

43:00

Speaker A

Yeah, so uh with every broker API, they'll have their own documentation. Uh since we have used kite connect API, uh I'll just quickly navigate to the kite connect documentation.

43:11

Speaker A

So depending on which uh broker API you're using, you'll have to go to the documentation [music] page. Uh I'll just go to the kite connect API documentation the first link that comes here. So this is the API documentation that is there.

43:25

Speaker A

Uh again codeex uh because this documentation has been there for so long and it is it is available on the internet for free. Codex already has context of it which is why we are able to build so much without having given

43:36

Speaker A

the documentation. [music] Uh but to make make it much easier because we know a lot of us a lot of the people are using uh different LLMs. We have an agent set up here.

43:46

Speaker A

It's also a tab here on the side. Okay. Uh so all you can do is uh if you were to develop if you were developing something and you wanted it to know exactly what APIs are there, you can

43:55

Speaker A

just copy this entire uh link and uh basically give this link to chatg in chat and ask it to learn everything there is about kite connect API from this link.

44:06

Speaker A

This this is your way to train the model. Yeah, this is a way to train the model on what APIs are available. So in the same chat I'm just going to show you how to do it. So I'll just give it the link

44:15

Speaker A

and just tell it uh can you learn about agent setup from here and that's it. So if you were doing this from scratch uh uh for the first time maybe you can just navigate to the kite API documentation

44:32

Speaker A

go to agent setup and give it this link. Okay and it'll automatically understand uh what APIs are available. This will also basically in simpler terms chat GPT or whatever whichever LLM this will understand all the different types of

44:49

Speaker A

orders available. Yeah. And I can define my algo and it will tell me whether that's possible or not.

44:54

Speaker A

Yes. Exactly. Okay. So that is one bit of the API documentation. Separately. Uh you could either ask chargex what your algo is and whether you can do it with kite APIs or not.

45:06

Speaker A

Uh or ask it to tell you. So there are multiple different uh errors and exceptions that you can get. So as if you're building a full scale algo, you have to be well versed with what errors and exceptions you get as well.

45:18

Speaker A

Um uh then there is a tab for your user. This is your basic information that you have of your account.

45:25

Speaker A

Uh there is an orders tab that is there on how to place different type of orders. So a buy or a sell order, uh stop-loss order. Um there is a tab for orders whether it's an aftermarket order as well a cover market cover order

45:39

Speaker A

iceberg order depending on your strategy type [music] you have just the variety tab here in the order placement has multiple different forms right your order type also market order limit order stop-loss order multiple different types uh validity product there is market

45:54

Speaker A

protection as well um so a lot more is there on the kite APIs than the algo that we touched last so you have a section of GTT orders, you could place alerts as well.

46:05

Speaker A

Uh you could we have a portfolio API that lets you track your positions and your holdings.

46:11

Speaker A

Yeah. Um then you have your data which is your market code. The the instruments API tells you all the instruments that are available to you.

46:18

Speaker A

Uh this is across NSE BS. So when you when you pointed the agent to that URL uh and asked it to learn it's it it is going to learn all the everything everything it knows that this is for the kite API.

46:29

Speaker A

Understood. So it knows everything by context. Yeah. Even mutual funds. I see. Exactly. So everything is available here in the APIs. So if you were doing this for the first time, it's good to go through all of this, learn as [music]

46:42

Speaker A

much possible of what is available and then maybe build your algo slowly piece by piece.

46:48

Speaker A

Then you have websocket streaming which is basically your live ticks that are coming. We have used websocket in our previous video in in this video as well.

46:57

Speaker A

So the the ticks change here as well. So constantly monitoring the websocket as well. You have historical data. So if you were doing back test and you wanted historical data, uh you have it from a minute interval all the

47:09

Speaker A

way to hourly, daily and longer. Understood? Yeah. Um [music] yeah. So mutual funds margin calculations.

47:18

Speaker A

Uh one very good thing about uh the APIs here is the [music] uh in in your margin you have charges API. So when you are doing back tests and you want to know exactly what you're being charged, you're being charged as well. So in your

47:31

Speaker A

back test, it makes it more robust. Correct. Yeah. You obviously have to factor in your charges.

47:36

Speaker A

Exactly. Slippages. Slippages. So while slippages, you can put a percentage because you can't recreate the market. But charges API gives you exactly the charges that you're getting charged as well.

47:46

Speaker A

So this is a good API that is I mean of course we will do a back testing video if if there is demand from uh people. Yeah.

47:54

Speaker A

Then we can define an algo and back test it. But let's see what the users uh you know our audience want.

48:02

Speaker A

Yeah. Based on that we'll take a call. So yeah this is mostly all the APIs that are there. Um again if there is something you want to know you could just chat with uh chat yeah withex and ask it can I do

48:14

Speaker A

this order placement type or that data if it's available or not and codec. So this this is a good starting point for anyone building an algo. Just give this URL the agent setup one and ask it to learn and then start

48:27

Speaker A

conversing about your algo. Yeah. Great. Okay. So, uh thank you so much Ashai. So, this was u a very basic fully automated algo. Although basic I think it's a great starting point for uh especially for someone like me who has

48:46

Speaker A

zero coding language uh coding uh experience, zero tech experience. uh I know a little bit of markets and uh along with uh you know with the help of LLMs now I can aspire to build my own algo right so thank you so much um and uh I

49:06

Speaker A

hope you guys like this video please do comment and let us know and we'll see you guys in the next

Topics: automated trading algo trading static IP Kite Connect API whitelisting no coding algo ChatGPT Python SDK order placement Zerodha

Study this video

- [Flashcards from this video](https://sozai.app/tools/ai-flashcard-generator/?from=transcript&id=76675)
- [Quiz on this video](https://sozai.app/tools/quiz-generator/?from=transcript&id=76675)

Free, made by AI from this transcript. No signup.


---
This is the markdown twin of https://sozai.app/transcript/build-fully-automated-trading-algo-ai-part2/ — the same content, without the markup.
Published by SozAI (https://sozai.app). Reuse and quotation are allowed with attribution and a link back.
Machine-readable index: https://sozai.app/llms.txt · data API: https://sozai.app/api/
