With release of 3.1 video, do videos 5 onwards in series " Master Algo Trading with Python | Episode 5:" still hold good and the py scripts need to be run as is?
I am facing issue in running code in session 5. py i am trying to run is âCorrect code for Ltp based Strike Selection.pyâ in folder âLtp Based Strike Selectionâ. The code and error is pasted below. I have upgraded latest version of dhantradehull.
Blockquote
import pdb
from Dhan_Tradehull import Tradehull
otm_ce_name, otm_pe_name, ce_OTM_strike, pe_OTM_strike = tsl.OTM_Strike_Selection('FINNIFTY','22-10-2024',distance_from_atm)
ce_ltp = tsl.get_ltp(otm_ce_name)
bc1 = (ce_ltp < 5)
print(distance_from_atm, otm_ce_name, ce_ltp)
if bc1:
print("Found the strike which has less than Rs 5 Ltp" ,otm_ce_name, ce_ltp)
Blockquote
error
Blockquote
PS D:\DhanAlgo> d:; cd âd:\DhanAlgoâ; & âc:\Users\abcwin\AppData\Local\Programs\Python\Python38\python.exeâ âc:\Users\abcwin.vscode\extensions\ms-python.debugpy-2025.0.1-win32-x64\bundled\libs\debugpy\launcherâ â49321â âââ âd:\DhanAlgo\5. Session5- Python Part 2\Ltp Based Strike Selection\Correct code for Ltp based Strike Selection.pyâ
-----Logged into Dhan-----
reading existing file all_instrument 2025-03-04.csv
Got the instrument file
No such file: âWebsocket.xlsxâ
Traceback (most recent call last):
File âd:\DhanAlgo\5. Session5- Python Part 2\Ltp Based Strike Selection\Dhan_Tradehull.pyâ, line 49, in init
self.wb = xw.Book(âWebsocket.xlsxâ)
File âc:\Users\saurabhwin\AppData\Local\Programs\Python\Python38\lib\site-packages\xlwings\main.pyâ, line 929, in init
impl = app.books.open(
File âc:\Users\saurabhwin\AppData\Local\Programs\Python\Python38\lib\site-packages\xlwings\main.pyâ, line 5153, in open
raise FileNotFoundError(âNo such file: â%sââ % fullname)
FileNotFoundError: No such file: âWebsocket.xlsxâ
âTradehullâ object has no attribute âsheetâ
Getting Error at OTM strike Selection as âTradehullâ object has no attribute âindex_step_dictâ
argument of type âNoneTypeâ is not iterable
1 None 0
Found the strike which has less than Rs 5 Ltp None 0
âTradehullâ object has no attribute âsheetâ
Getting Error at OTM strike Selection as âTradehullâ object has no attribute âindex_step_dictâ
argument of type âNoneTypeâ is not iterable
2 None 0
Found the strike which has less than Rs 5 Ltp None 0
âTradehullâ object has no attribute âsheetâ
Getting Error at OTM strike Selection as âTradehullâ object has no attribute âindex_step_dictâ
argument of type âNoneTypeâ is not iterable
3 None 0
Found the strike which has less than Rs 5 Ltp None 0
âTradehullâ object has no attribute âsheetâ
Getting Error at OTM strike Selection as âTradehullâ object has no attribute âindex_step_dictâ
argument of type âNoneTypeâ is not iterable
4 None 0
Found the strike which has less than Rs 5 Ltp None 0
âTradehullâ object has no attribute âsheetâ
Getting Error at OTM strike Selection as âTradehullâ object has no attribute âindex_step_dictâ
argument of type âNoneTypeâ is not iterable
5 None 0
Found the strike which has less than Rs 5 Ltp None 0
âTradehullâ object has no attribute âsheetâ
Getting Error at OTM strike Selection as âTradehullâ object has no attribute âindex_step_dictâ
argument of type âNoneTypeâ is not iterable
6 None 0
Found the strike which has less than Rs 5 Ltp None 0
âTradehullâ object has no attribute âsheetâ
Getting Error at OTM strike Selection as âTradehullâ object has no attribute âindex_step_dictâ
argument of type âNoneTypeâ is not iterable
7 None 0
Found the strike which has less than Rs 5 Ltp None 0
âTradehullâ object has no attribute âsheetâ
Getting Error at OTM strike Selection as âTradehullâ object has no attribute âindex_step_dictâ
argument of type âNoneTypeâ is not iterable
8 None 0
Found the strike which has less than Rs 5 Ltp None 0
âTradehullâ object has no attribute âsheetâ
Getting Error at OTM strike Selection as âTradehullâ object has no attribute âindex_step_dictâ
argument of type âNoneTypeâ is not iterable
9 None 0
Found the strike which has less than Rs 5 Ltp None 0
âTradehullâ object has no attribute âsheetâ
Getting Error at OTM strike Selection as âTradehullâ object has no attribute âindex_step_dictâ
argument of type âNoneTypeâ is not iterable
10 None 0
Found the strike which has less than Rs 5 Ltp None 0
PS D:\DhanAlgo>
Blockquote
I was optimizing, the get_option_chain function for least time possible to fetch an option chain, I tried 2 seconds,
in the experiment above, it worked fine.
but in live trades, it still does says, Too many requests
is it that, for some stocks it takes more than 2 sec, for some less than 2 sec ?
what would be an optimum time sleep, without slowing the code down further ?
@rahulcse56 You require LTP only once or continously, if itâs once then you are already know the way, but if you require LTP continously then use âLive Market Feedâ method which uses websocket to fetch the data in realtime without hitting rate limit. I used this method to scan for 400 stocks in realtime basis.
And Iâm getting a WebSocket error: âConnection to the remote host was lost.â
I subscribed to a total of 50 instruments, but the WebSocket is not sending data continuously.
Please help me understand how to send multiple requests and how to avoid this error.
Also getting error like
WebSocket Error: [Errno 104] Connection reset by peer
@Tradehull_Imran
Sir, Iâm facing frequent WebSocket connection losses.
Even when requesting data for just two instruments, itâs not sending data properly.
Please help us, sir.