Learn Algo Trading with Python | Codes | Youtube Series

@Asjadh_khan_M_A
Try this ==> python_package

Try this ==>

Hi everyone:

Session 4 codes links : 4. Session4- Python Part 1.zip - Google Drive

1 Like


with new code Dhan_websocket.py working fine @Tradehull_Imran sir

1 Like

Hi,

I am getting below error, I have followed the instructions
WebSocket connection error: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108)
Reconnecting Again…
Watchlist changed. Reconnecting the feed…
Error: single positional indexer is out-of-bounds for SILVER-27Aug2024-78000-PE
Error: single positional indexer is out-of-bounds for SENSEX 06 SEP 83300 PUT
Error: single positional indexer is out-of-bounds for SENSEX 06 SEP 83600 CALL
Error: single positional indexer is out-of-bounds for SENSEX 06 SEP 76800 PUT
Error: single positional indexer is out-of-bounds for SENSEX 06 SEP 78500 PUT
Error: single positional indexer is out-of-bounds for SENSEX 06 SEP 77000 PUT
Error: single positional indexer is out-of-bounds for SENSEX 06 SEP 81600 CALL
Error: single positional indexer is out-of-bounds for SENSEX 06 SEP 80100 CALL
Error: single positional indexer is out-of-bounds for SENSEX 06 SEP 78800 CALL
Error: single positional indexer is out-of-bounds for SENSEX 06 SEP 77300 CALL
Error: single positional indexer is out-of-bounds for SENSEX 06 SEP 79000 CALL
Error: single positional indexer is out-of-bounds for SENSEX 06 SEP 84100 PUT
Error: single positional indexer is out-of-bounds for SENSEX 06 SEP 76800 CALL
Error: single positional indexer is out-of-bounds for SENSEX 06 SEP 81900 PUT
Error: single positional indexer is out-of-bounds for BANKNIFTY 28 AUG 51600 CALL
Error: single positional indexer is out-of-bounds for NIFTY 29 AUG 23200 CALL
Error: single positional indexer is out-of-bounds for NATURALGAS1!
Disconnected from WebSocket feed.
WebSocket connection error: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108)
Reconnecting Again…

hi @ddeogharkar
The expiry for SENSEX 06 SEP 77000 PUT has been passed,
so we need to remove expired contracts from Websocket.xlsx

let me know if it works after it

@Tradehull_Imran Sir,

I am getting this console output when I am running

Dhan_codebase usage.py

-----Logged into Dhan-----
reading existing file all_instrument 2024-10-15.csv
Got the instrument file
available_balance 111.18
Traceback (most recent call last):
  File "c:\Users\Subhajit Panja\Documents\Algorithim_HQ\Dhan codebase\Dhan_Tradehull.py", line 394, in ATM_Strike_Selection
    closest_index = ce_df['diff'].idxmin()
  File "C:\Users\Subhajit Panja\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\core\series.py", line 2460, in idxmin
    i = self.argmin(axis, skipna, *args, **kwargs)  # type: ignore[arg-type]
  File "C:\Users\Subhajit Panja\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\core\base.py", line 742, in argmin
    return nanops.nanargmin(  # type: ignore[return-value]
  File "C:\Users\Subhajit Panja\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\core\nanops.py", line 96, in _f
    return f(*args, **kwargs)
  File "C:\Users\Subhajit Panja\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\core\nanops.py", line 1193, in nanargmin
    result = values.argmin(axis)  # type: ignore[var-annotated]
ValueError: attempt to get argmin of an empty sequence
--- Logging error ---
Traceback (most recent call last):
  File "c:\Users\Subhajit Panja\Documents\Algorithim_HQ\Dhan codebase\Dhan_Tradehull.py", line 394, in ATM_Strike_Selection
    closest_index = ce_df['diff'].idxmin()
  File "C:\Users\Subhajit Panja\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\core\series.py", line 2460, in idxmin
    i = self.argmin(axis, skipna, *args, **kwargs)  # type: ignore[arg-type]
  File "C:\Users\Subhajit Panja\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\core\base.py", line 742, in argmin
    return nanops.nanargmin(  # type: ignore[return-value]
  File "C:\Users\Subhajit Panja\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\core\nanops.py", line 96, in _f
    return f(*args, **kwargs)
  File "C:\Users\Subhajit Panja\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\core\nanops.py", line 1193, in nanargmin
    result = values.argmin(axis)  # type: ignore[var-annotated]
ValueError: attempt to get argmin of an empty sequence

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Subhajit Panja\AppData\Local\Programs\Python\Python38\lib\logging\__init__.py", line 1081, in emit
    msg = self.format(record)
  File "C:\Users\Subhajit Panja\AppData\Local\Programs\Python\Python38\lib\logging\__init__.py", line 925, in format
    return fmt.format(record)
  File "C:\Users\Subhajit Panja\AppData\Local\Programs\Python\Python38\lib\logging\__init__.py", line 664, in format
    record.message = record.getMessage()
  File "C:\Users\Subhajit Panja\AppData\Local\Programs\Python\Python38\lib\logging\__init__.py", line 369, in getMessage
    msg = msg % self.args
TypeError: not all arguments converted during string formatting
Call stack:
  File "c:/Users/Subhajit Panja/Documents/Algorithim_HQ/Dhan codebase/Dhan_codebase usage.py", line 33, in <module>
    ce_name, pe_name, strike = tsl.ATM_Strike_Selection('NIFTY','05-09-2024')
  File "c:\Users\Subhajit Panja\Documents\Algorithim_HQ\Dhan codebase\Dhan_Tradehull.py", line 421, in ATM_Strike_Selection
    self.logger.exception("Got exception in ce_pe_option_df ", e)
Message: 'Got exception in ce_pe_option_df '
Arguments: (ValueError('attempt to get argmin of an empty sequence'),)
traday_data
    security_id = self.instrument_df[((self.instrument_df['SEM_TRADING_SYMBOL']==tradingsymbol)|(self.instrument_df['SEM_CUSTOM_SYMBOL']==tradingsymbol))&(self.instrument_df['SEM_EXM_EXCH_ID']==instrument_exchange[exchange])].iloc[-1]['SEM_SMST_SECURITY_ID']
  File "C:\Users\Subhajit Panja\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\core\indexing.py", line 1103, in __getitem__
    return self._getitem_axis(maybe_callable, axis=axis)
  File "C:\Users\Subhajit Panja\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\core\indexing.py", line 1656, in _getitem_axis
    self._validate_integer(key, axis)
  File "C:\Users\Subhajit Panja\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\core\indexing.py", line 1589, in _validate_integer
    raise IndexError("single positional indexer is out-of-bounds")
IndexError: single positional indexer is out-of-bounds
Traceback (most recent call last):
  File "c:/Users/Subhajit Panja/Documents/Algorithim_HQ/Dhan codebase/Dhan_codebase usage.py", line 39, in <module>
    intraday_hist_data['rsi'] = talib.RSI(intraday_hist_data['close'], timeperiod=14)
TypeError: 'NoneType' object is not subscriptable

sometimes I am getting

C:\Users\Subhajit Panja\Documents\Algorithim_HQ\Dhan codebase> py Dhan_codebase usage.py
C:\Users\Subhajit Panja\AppData\Local\Programs\Python\Python38\python.exe: can't open file 'Dhan_codebase': [Errno 2] No such file or directory
PS C:\Users\Subhajit Panja\Documents\Algorithim_HQ\Dhan codebase>

@Tradehull_Imran Sir,
Please help me

available_balance 111.18
also showing wrong

C:\Automation\DhanAPI\3. Session3 - Codebase\Dhan codebase>py Dhan_websocket.py
Reading existing file all_instrument 2024-10-15.csv
Watchlist changed. Reconnecting the feed…
Disconnected from WebSocket feed.
WebSocket connection error: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108)
Reconnecting Again…

@Tradehull_Imran , I am getting certificate issue

hi @Subhajitpanja
Do send me complete zip of your folder, and share on the google drive link

share it with: tradehull_mentorship@tradehull.com

hi @ddeogharkar

  • Press Windows + R.
  • Type cmd and hit Enter. This opens the Command Prompt.
  • In the Command Prompt window, type the following command
    pip install certifi --upgrade
  • and press Enter, (this will update cerifi package)

after this try again and let me know if it works

C:\Users\Subhajit Panja>pip install certifi --upgrade
Requirement already satisfied: certifi in c:\users\subhajit panja\appdata\local\programs\python\python310\lib\site-packages (2024.7.4)
Collecting certifi
  Downloading certifi-2024.8.30-py3-none-any.whl.metadata (2.2 kB)
Downloading certifi-2024.8.30-py3-none-any.whl (167 kB)
Installing collected packages: certifi
  Attempting uninstall: certifi
    Found existing installation: certifi 2024.7.4
    Uninstalling certifi-2024.7.4:
      Successfully uninstalled certifi-2024.7.4
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
algorthim 0.1 requires autobahn==19.11.2, which is not installed.
algorthim 0.1 requires numpy==2.0.1, which is not installed.
algorthim 0.1 requires pandas==2.2.2, which is not installed.
algorthim 0.1 requires pandas-ta==0.3.14b0, which is not installed.
algorthim 0.1 requires pyOpenSSL==24.2.1, which is not installed.
algorthim 0.1 requires requests==2.31.0, which is not installed.
algorthim 0.1 requires smartapi-python==1.4.9, which is not installed.
algorthim 0.1 requires ta==0.11.0, which is not installed.
algorthim 0.1 requires Twisted==24.3.0, which is not installed.
algorthim 0.1 requires twisted-iocpsupport==1.0.4, which is not installed.
algorthim 0.1 requires typing-extensions==4.12.2, which is not installed.
algorthim 0.1 requires urllib3==2.2.2, which is not installed.
algorthim 0.1 requires websocket-client==1.6.1, which is not installed.
algorthim 0.1 requires xlwings==0.31.10, which is not installed.
upstox-python-sdk 2.5.0 requires urllib3>=1.15, which is not installed.
upstox-python-sdk 2.5.0 requires websocket-client, which is not installed.
algorthim 0.1 requires certifi==2024.7.4, but you have certifi 2024.8.30 which is incompatible.
Successfully installed certifi-2024.8.30

@Tradehull_Imran Sir

-----Logged into Dhan-----
reading existing file all_instrument 2024-10-15.csv
Got the instrument file
available_balance 111.18
Traceback (most recent call last):
  File "c:\Users\Subhajit Panja\Documents\Algorithim_HQ\Dhan codebase\Dhan_Tradehull.py", line 394, in ATM_Strike_Selection
    closest_index = ce_df['diff'].idxmin()
  File "C:\Users\Subhajit Panja\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\core\series.py", line 2460, in idxmin
    i = self.argmin(axis, skipna, *args, **kwargs)  # type: ignore[arg-type]
  File "C:\Users\Subhajit Panja\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\core\base.py", line 742, in argmin
    return nanops.nanargmin(  # type: ignore[return-value]
  File "C:\Users\Subhajit Panja\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\core\nanops.py", line 96, in _f
    return f(*args, **kwargs)
  File "C:\Users\Subhajit Panja\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\core\nanops.py", line 1193, in nanargmin
    result = values.argmin(axis)  # type: ignore[var-annotated]
ValueError: attempt to get argmin of an empty sequence
--- Logging error ---
Traceback (most recent call last):
  File "c:\Users\Subhajit Panja\Documents\Algorithim_HQ\Dhan codebase\Dhan_Tradehull.py", line 394, in ATM_Strike_Selection
    closest_index = ce_df['diff'].idxmin()
  File "C:\Users\Subhajit Panja\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\core\series.py", line 2460, in idxmin
    i = self.argmin(axis, skipna, *args, **kwargs)  # type: ignore[arg-type]
  File "C:\Users\Subhajit Panja\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\core\base.py", line 742, in argmin
    return nanops.nanargmin(  # type: ignore[return-value]
  File "C:\Users\Subhajit Panja\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\core\nanops.py", line 96, in _f
    return f(*args, **kwargs)
  File "C:\Users\Subhajit Panja\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\core\nanops.py", line 1193, in nanargmin
    result = values.argmin(axis)  # type: ignore[var-annotated]
ValueError: attempt to get argmin of an empty sequence

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Subhajit Panja\AppData\Local\Programs\Python\Python38\lib\logging\__init__.py", line 1081, in emit
    msg = self.format(record)
  File "C:\Users\Subhajit Panja\AppData\Local\Programs\Python\Python38\lib\logging\__init__.py", line 925, in format
    return fmt.format(record)
  File "C:\Users\Subhajit Panja\AppData\Local\Programs\Python\Python38\lib\logging\__init__.py", line 664, in format
    record.message = record.getMessage()
  File "C:\Users\Subhajit Panja\AppData\Local\Programs\Python\Python38\lib\logging\__init__.py", line 369, in getMessage
    msg = msg % self.args
TypeError: not all arguments converted during string formatting
Call stack:
exception got in ce_pe_option_df attempt to get argmin of an empty sequence
Getting Error at OTM strike Selection as attempt to get argmin of an empty sequence
Getting Error at OTM strike Selection as attempt to get argmin of an empty sequence
single positional indexer is out-of-bounds
Traceback (most recent call last):
  File "c:\Users\Subhajit Panja\Documents\Algorithim_HQ\Dhan codebase\Dhan_Tradehull.py", line 251, in get_inexception got in ce_pe_option_df attempt to get argmin of an empty sequence
Getting Error at OTM strike Selection as attempt to get argmin of an empty sequence
Getting Error at OTM strike Selection as attempt to get argmin of an empty sequence
single positional indexer is out-of-bounds
Traceback (most recent call last):
  File "c:\Users\Subhajit Panja\Documents\Algorithim_HQ\Dhan codebase\Dhan_Tradehull.py", line 251, in get_intraday_data
    security_id = self.instrument_df[((self.instrument_df['SEM_TRADING_SYMBOL']==tradingsymbol)|(self.instrument_df['SEM_CUSTOM_SYMBOL']==tradingsymbol))&(self.instrument_df['SEM_EXM_EXCH_ID']==instrument_exchange[exchange])].iloc[-1]['SEM_SMST_SECURITY_ID']
  File "C:\Users\Subhajit Panja\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\core\indexing.py", line 1103, in __getitem__
    return self._getitem_axis(maybe_callable, axis=axis)
  File "C:\Users\Subhajit Panja\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\core\indexing.py", line 1656, in _getitem_axis
    self._validate_integer(key, axis)
  File "C:\Users\Subhajit Panja\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\core\indexing.py", line 1589, in _validate_integer
    raise IndexError("single positional indexer is out-of-bounds")
IndexError: single positional indexer is out-of-bounds
Traceback (most recent call last):
  File "c:/Users/Subhajit Panja/Documents/Algorithim_HQ/Dhan codebase/Dhan_codebase usage.py", line 39, in <module>
    intraday_hist_data['rsi'] = talib.RSI(intraday_hist_data['close'], timeperiod=14)
TypeError: 'NoneType' object is not subscriptable
PS C:\Users\Subhajit Panja\Documents\Algorithim_HQ>

Successfully installed certifi-2024.8.30

although it is showing @Tradehull_Imran sir

@Subhajitpanja
Installing certifi was not your solution, it was @ddeogharkar solution as mentioned
you got mismatched :sweat_smile:

you need to send me complete zip of your folder, and share on the google drive link
share it with: tradehull_mentorship@tradehull.com

1 Like

Ohh OK sir

Sir I just shared with you please check

Hi @Tradehull_Imran
Still facing same issue, I have tried running old websocket file, it does not give this error, this issue with the new file.

@Tradehull_Imran Episode 4 is not uploaded

Hi @Subhajitpanja
It seems you are using wrong client_code in Dhan_codebase usage.py and Dhan_websocket.py.
The id you are using is of Tradehull test account,

you need to put your id there instead,

I am very sorry sir
I have updated same link

As I said
below file is working fine

Dhan_websocket.py

But this is not working for me

Dhan_codebase usage.py

May i know why Dhan_websocket.py is not updating the excel?

Dhan codebase usage.py is working for me and i can fetch details as shown in video.

Dhan_websocket.py is not Woking for me. Attached the details in screen short for your reference.
Do i need to do any change other that “client_id” and “access_token” ?

hi @dinild
its showing error because there are expired contracts in the watchlist

Do double check if below details are okey and run it again

also let me know if it works for you after making changes