Learn Algo Trading with Python | Codes | Youtube Series

@Tradehull_Imran
Getting below error.
D:\my_applications\my_algo\Strategies>py final2candle.py
Codebase Version 2.6 : Solved - Pnl Issue
-----Logged into Dhan-----
reading existing file all_instrument 2025-01-05.csv
Got the instrument file
Algo is working 21:52:27.339104
BUY 21:52:27.339104 False False False True True False first_candle 15:15:00
SELL 21:52:27.339104 True True True True True True first_candle 15:15:00

Sell Signal Formed
exception got in ce_pe_option_df ‘<’ not supported between instances of ‘int’ and ‘str’
Algo is working 21:52:37.912802
BUY 21:52:37.912802 False False False True True False first_candle 15:15:00
SELL 21:52:37.912802 True True True True True True first_candle 15:15:00

Sell Signal Formed
exception got in ce_pe_option_df ‘<’ not supported between instances of ‘int’ and ‘str’
Traceback (most recent call last):
File “final2candle.py”, line 33, in
live_pnl = tsl.get_live_pnl()
File “D:\my_applications\my_algo\Strategies\Dhan_Tradehull_V2.py”, line 322, in get_live_pnl
time.sleep(2)
KeyboardInterrupt
^C
D:\my_applications\my_algo\Strategies>

try to remove space ['NIFTY DEC FUT ']

1 Like

@Tradehull_Imran Sir,

I think it is resolved now, i’ll check it tomorrow morning again and let you know.
D:\my_applications\my_algo\Strategies>py final2candle.py
Codebase Version 2.6 : Solved - Pnl Issue
-----Logged into Dhan-----
reading existing file all_instrument 2025-01-05.csv
Got the instrument file
Algo is working 22:14:21.264568
BUY 22:14:21.264568 False False False True True False first_candle 15:15:00
SELL 22:14:21.264568 True True True True True True first_candle 15:15:00

Sell Signal Formed
'Got exception in place_order as {‘status’: ‘failure’, ‘remarks’: {‘error_code’: ‘DH-906’, ‘error_type’: ‘Order_Error’, ‘error_message’: ‘Market is Closed! Want to place an offline order?’}, ‘data’: {‘errorType’: ‘Order_Error’, ‘errorCode’: ‘DH-906’, ‘errorMessage’: ‘Market is Closed! Want to place an offline order?’}}
Algo is working 22:14:35.237018

1 Like

@Tradehull_Imran I’m on 2.6. getting

got exception in pnl as {'status': 'failure', 'remarks': {'error_code': 'DH-906', 'error_type': 'Order_Error', 'error_message': 'Invalid Token'}, 'data': {'errorType': 'Order_Error', 'errorCode': 'DH-906', 'errorMessage': 'Invalid Token'}}

FYI… token is valid till feb 2nd

@Tradehull_Imran one more, can you look into Learn Algo Trading with Python | Codes | Youtube Series - #2017 by Rajashekhar_Rangappa when you get a chance, please?

1 Like

Hello @Tradehull_Imran,

i am getting the below error. please check and help me. Friday the same script was running fine.

live_quote is giving bad data :slight_smile:

@Tradehull_Imran pls see ohlc values which are wrong causing order to fail

see the last price

getting this error since morning,

the same file was working just fine untill friday

> 
> Codebase Version 2.6 : Solved - Pnl Issue
> -----Logged into Dhan-----
> This BOT Is Picking New File From Dhan
> <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108)>
> 'Tradehull' object has no attribute 'response'
> Traceback (most recent call last):
>   File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\urllib\request.py", line 1317, in do_open
>     h.request(req.get_method(), req.selector, req.data, headers,
>   File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\http\client.py", line 1230, in request
>     self._send_request(method, url, body, headers, encode_chunked)
>   File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\http\client.py", line 1276, in _send_request
>     self.endheaders(body, encode_chunked=encode_chunked)
>   File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\http\client.py", line 1225, in endheaders
>     self._send_output(message_body, encode_chunked=encode_chunked)
>   File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\http\client.py", line 1004, in _send_output
>     self.send(msg)
>   File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\http\client.py", line 944, in send
>     self.connect()
>   File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\http\client.py", line 1399, in connect
>     self.sock = self._context.wrap_socket(self.sock,
>   File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\ssl.py", line 500, in wrap_socket
>     return self.sslsocket_class._create(
>   File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\ssl.py", line 1040, in _create
>     self.do_handshake()
>   File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\ssl.py", line 1309, in do_handshake
>     self._sslobj.do_handshake()
> ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108)
> 
> During handling of the above exception, another exception occurred:
> 
> Traceback (most recent call last):
>   File "d:\Dhan Algo\Final Codes\Dhan_Tradehull_V2.py", line 84, in get_login
>     self.instrument_df                                                                  = self.get_instrument_file()
>   File "d:\Dhan Algo\Final Codes\Dhan_Tradehull_V2.py", line 116, in get_instrument_file
>     instrument_df = pd.read_csv("https://images.dhan.co/api-data/api-scrip-master.csv", low_memory=False)
>   File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\io\parsers\readers.py", line 912, in read_csv
>     return _read(filepath_or_buffer, kwds)
>   File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\io\parsers\readers.py", line 577, in _read
>     parser = TextFileReader(filepath_or_buffer, **kwds)
>   File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\io\parsers\readers.py", line 1407, in __init__
>     self._engine = self._make_engine(f, self.engine)
>   File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\io\parsers\readers.py", line 1661, in _make_engine
>     self.handles = get_handle(
>   File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\io\common.py", line 716, in get_handle
>     ioargs = _get_filepath_or_buffer(
>   File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\io\common.py", line 368, in _get_filepath_or_buffer
>     with urlopen(req_info) as req:
>   File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\io\common.py", line 270, in urlopen
>     return urllib.request.urlopen(*args, **kwargs)
>   File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\urllib\request.py", line 222, in urlopen
>     return opener.open(url, data, timeout)
>   File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\urllib\request.py", line 525, in open
>     response = self._open(req, data)
>   File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\urllib\request.py", line 542, in _open
>     result = self._call_chain(self.handle_open, protocol, protocol +
>   File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\urllib\request.py", line 502, in _call_chain
>     result = func(*args)
>   File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\urllib\request.py", line 1360, in https_open
>     return self.do_open(http.client.HTTPSConnection, req,
>   File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\urllib\request.py", line 1320, in do_open
>     raise URLError(err)
> urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108)>
> 
> During handling of the above exception, another exception occurred:
> 
> Traceback (most recent call last):
>   File "d:\Dhan Algo\Final Codes\Dhan_Tradehull_V2.py", line 53, in __init__
>     self.get_login(ClientCode,token_id)
>   File "d:\Dhan Algo\Final Codes\Dhan_Tradehull_V2.py", line 89, in get_login
>     print(self.response)
> AttributeError: 'Tradehull' object has no attribute 'response'
> -----Logged into Dhan-----
> This BOT Is Picking New File From Dhan
> <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108)>
> 'Tradehull' object has no attribute 'response'
> Traceback (most recent call last):
>   File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\urllib\request.py", line 1317, in do_open
>     h.request(req.get_method(), req.selector, req.data, headers,
>   File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\http\client.py", line 1230, in request
>     self._send_request(method, url, body, headers, encode_chunked)
>   File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\http\client.py", line 1276, in _send_request
>     self.endheaders(body, encode_chunked=encode_chunked)
>   File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\http\client.py", line 1225, in endheaders
>     self._send_output(message_body, encode_chunked=encode_chunked)
>   File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\http\client.py", line 1004, in _send_output
>     self.send(msg)
>   File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\http\client.py", line 944, in send
>     self.connect()
>   File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\http\client.py", line 1399, in connect
>     self.sock = self._context.wrap_socket(self.sock,
>   File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\ssl.py", line 500, in wrap_socket
>     return self.sslsocket_class._create(
>   File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\ssl.py", line 1040, in _create
>     self.do_handshake()
>   File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\ssl.py", line 1309, in do_handshake
>     self._sslobj.do_handshake()
> ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108)
> 
> During handling of the above exception, another exception occurred:
> 
> Traceback (most recent call last):
>   File "d:\Dhan Algo\Final Codes\Dhan_Tradehull_V2.py", line 84, in get_login
>     self.instrument_df                                                                  = self.get_instrument_file()
>   File "d:\Dhan Algo\Final Codes\Dhan_Tradehull_V2.py", line 116, in get_instrument_file
>     instrument_df = pd.read_csv("https://images.dhan.co/api-data/api-scrip-master.csv", low_memory=False)
>   File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\io\parsers\readers.py", line 912, in read_csv
>     return _read(filepath_or_buffer, kwds)
>   File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\io\parsers\readers.py", line 577, in _read
>     parser = TextFileReader(filepath_or_buffer, **kwds)
>   File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\io\parsers\readers.py", line 1407, in __init__
>     self._engine = self._make_engine(f, self.engine)
>   File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\io\parsers\readers.py", line 1661, in _make_engine
>     self.handles = get_handle(
>   File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\io\common.py", line 716, in get_handle
>     ioargs = _get_filepath_or_buffer(
>   File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\io\common.py", line 368, in _get_filepath_or_buffer
>     with urlopen(req_info) as req:
>   File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\io\common.py", line 270, in urlopen
>     return urllib.request.urlopen(*args, **kwargs)
>   File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\urllib\request.py", line 222, in urlopen
>     return opener.open(url, data, timeout)
>   File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\urllib\request.py", line 525, in open
>     response = self._open(req, data)
>   File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\urllib\request.py", line 542, in _open
>     result = self._call_chain(self.handle_open, protocol, protocol +
>   File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\urllib\request.py", line 502, in _call_chain
>     result = func(*args)
>   File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\urllib\request.py", line 1360, in https_open
>     return self.do_open(http.client.HTTPSConnection, req,
>   File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\urllib\request.py", line 1320, in do_open
>     raise URLError(err)
> urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108)>
> 
> During handling of the above exception, another exception occurred:
> 
> Traceback (most recent call last):
>   File "d:\Dhan Algo\Final Codes\Dhan_Tradehull_V2.py", line 53, in __init__
>     self.get_login(ClientCode,token_id)
>   File "d:\Dhan Algo\Final Codes\Dhan_Tradehull_V2.py", line 89, in get_login
>     print(self.response)
> AttributeError: 'Tradehull' object has no attribute 'response'
> got exception in pnl as 'Tradehull' object has no attribute 'instrument_df'
> Getting Error at OTM strike Selection as 'Tradehull' object has no attribute 'instrument_df'
> Exception at getting Expiry list as 'Tradehull' object has no attribute 'commodity_step_dict'
> Unable to find the correct Expiry for NIFTY
> None has delta None
> Traceback (most recent call last):
>   File "d:/Dhan Algo/Final Codes/Strategy_Iron_Condor.py", line 114, in <module>
>     far_OTM_CE_name, far_OTM_CE_strike = find_otm_strikes(index_name, expiry, 'CE', far_OTM_delta)
>   File "d:\Dhan Algo\Final Codes\Functions_All_Qaisar.py", line 187, in find_otm_strikes
>     if OTM_CE_delta <= delta and found_CE_strike == 'no' and no_repeat_scanning_CE:
> TypeError: '<=' not supported between instances of 'NoneType' and 'float

i am facing the same issue… earlier my algo was working fine but today its not working…

look some bug introduced in production. its fixed now btw.

anyways its so sad they are pushing wrong code into prod.

@Dhan @Tradehull_Imran

still its not working for me…

1 Like

@Tradehull_Imran SIR, SAME FOR ME AS WELL, ITS NOT WORKING

PS C:\Users\DELL> & C:/Users/DELL/AppData/Local/Programs/Python/Python38/python.exe "f:/2. 2 Candle Theory Algo/2. 2 Candle Theory Algo/70 -50 rsi finding.py"
Codebase Version 2.1
-----Logged into Dhan-----
This BOT Is Picking New File From Dhan
<urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108)>
'Tradehull' object has no attribute 'response'
Traceback (most recent call last):
  File "C:\Users\DELL\AppData\Local\Programs\Python\Python38\lib\urllib\request.py", line 1317, in do_open   
    h.request(req.get_method(), req.selector, req.data, headers,
  File "C:\Users\DELL\AppData\Local\Programs\Python\Python38\lib\http\client.py", line 1230, in request      
    self._send_request(method, url, body, headers, encode_chunked)
  File "C:\Users\DELL\AppData\Local\Programs\Python\Python38\lib\http\client.py", line 1276, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "C:\Users\DELL\AppData\Local\Programs\Python\Python38\lib\http\client.py", line 1225, in endheaders   
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "C:\Users\DELL\AppData\Local\Programs\Python\Python38\lib\http\client.py", line 1004, in _send_output
    self.send(msg)
  File "C:\Users\DELL\AppData\Local\Programs\Python\Python38\lib\http\client.py", line 944, in send
    self.connect()
  File "C:\Users\DELL\AppData\Local\Programs\Python\Python38\lib\http\client.py", line 1399, in connect
    self.sock = self._context.wrap_socket(self.sock,
  File "C:\Users\DELL\AppData\Local\Programs\Python\Python38\lib\ssl.py", line 500, in wrap_socket
    return self.sslsocket_class._create(
  File "C:\Users\DELL\AppData\Local\Programs\Python\Python38\lib\ssl.py", line 1040, in _create
    self.do_handshake()
  File "C:\Users\DELL\AppData\Local\Programs\Python\Python38\lib\ssl.py", line 1309, in do_handshake
    self._sslobj.do_handshake()

Hi @rahulcse56
do send code as well

Hi @Qaisar

Do apply point no 3

Hi @Himansshu_Joshi

Apply point no 3 : Learn Algo Trading with Python | Codes | Youtube Series - #177 by Tradehull_Imran

do use this upgraded codebase file : Dhan_Tradehull_V2.py - Google Drive

Note : The library will update when necessary, but the link to the codebase file remains same

Its working now, Thank you

`

tsl.get_live_pnl()

` is still not working

Still same issue @Dhan @Tradehull_Imran

Hi @Arun_Rawat ,

It seems the code is comparing a string with an integer. Check the datatype of the variable using type(variable_name). If it’s a string, convert it to an integer using int(variable_name). To convert a column to integers, use:


ce_pe_option_df['column_name'] = ce_pe_option_df['column_name'].astype(int)

Let me know if this works, also send your complete code.