Learn Algo Trading with Python | Codes | Youtube Series

Hi @Rajashekhar_Rangappa ,

We are looking into the issue.

Hi @Tradehull_Imran

Thanks its working now but its too slow… earlier my algo completed full FnO watchlist in approx. 60 sec. now its taking (470 sec) very long time… i think you have added more sleep time… please reduce it otherwise there is no meaning to run algo.
image

Regards,
Rahul

Thank you imran

1 Like

Is there any method to know which contracts are blocked so that I can avoid those contracts in my Algo altogether

1 Like

I need to scan approx 170 stocks as soon as possible. after execution order, i need only LTP with 2-5 sec delay.

When iam using this code geeting option chain data
option_chain = tsl.get_option_chain(Underlying=“NIFTY”, exchange=“INDEX”, expiry=0)
adding strikes to it wont working and same problem appearing

Got it Sir,
Thanks :pray:

1 Like

@Tradehull_Imran A Humble request from myside. please resolve slow execution issue. and let me know how we can make it faster… my algo now taking lot of time to scan all the fno stocks. please reduce the Sleep time.

@Hardik     "**I got these types of logs when i start the application**"  raise ValueError(f"No expiry date found for {name}")

ValueError: No expiry date found for GMRINFRA
2025-02-28 10:37:00,006 - ERROR - Error processing GNFC: No expiry date found for GNFC
Traceback (most recent call last):
File “C:\Users\manis\AppData\Local\Programs\Python\Python38\lib\site-packages\Dhan_Tradehull\Dhan_Tradehull.py”, line 128, in correct_step_df_creation
raise ValueError(f"No expiry date found for {name}“)
ValueError: No expiry date found for GNFC
2025-02-28 10:37:00,240 - ERROR - Error processing GUJGASLTD: No expiry date found for GUJGASLTD
Traceback (most recent call last):
File “C:\Users\manis\AppData\Local\Programs\Python\Python38\lib\site-packages\Dhan_Tradehull\Dhan_Tradehull.py”, line 128, in correct_step_df_creation
raise ValueError(f"No expiry date found for {name}”)
ValueError: No expiry date found for GUJGASLTD
2025-02-28 10:37:01,305 - ERROR - Error processing INDIAMART: No expiry date found for INDIAMART
Traceback (most recent call last):
File “C:\Users\manis\AppData\Local\Programs\Python\Python38\lib\site-packages\Dhan_Tradehull\Dhan_Tradehull.py”, line 128, in correct_step_df_creation
raise ValueError(f"No expiry date found for {name}“)
ValueError: No expiry date found for INDIAMART
2025-02-28 10:37:01,587 - ERROR - Error processing IPCALAB: No expiry date found for IPCALAB
Traceback (most recent call last):
File “C:\Users\manis\AppData\Local\Programs\Python\Python38\lib\site-packages\Dhan_Tradehull\Dhan_Tradehull.py”, line 128, in correct_step_df_creation
raise ValueError(f"No expiry date found for {name}”)
ValueError: No expiry date found for IPCALAB

Hi @sreetd14

Tagging @Hardik for the same

Hi @Jana_HS ,

We have updated the codebase to include num_strikes in the option chain. Use the below code to update the codebase:

pip install --upgrade Dhan-Tradehull

To get the option chain for selected number of strikes use the below code:

option_chain = tsl.get_option_chain(Underlying="NIFTY", exchange="INDEX", expiry=0, num_strikes=10)
1 Like

Hi @Manish1 ,

  • Open Command Prompt: Press Win, type cmd, and press Enter.
  • Install Dhan-Tradehull: Run pip install Dhan-Tradehull
  • Confirm the installation by running pip show Dhan-Tradehull

Guide to use the updated codebase:
Video reference : https://www.youtube.com/watch?v=P9iPYShakbA

1 Like

Hi @rahulcse56

for the speed issues,
if you are using only LTP so use below code to fetch the ltp for the complete watchlist
In this case we get the ltp for complete watchlist in 1 second.

watchlist = ['CRUDEOIL', 'NIFTY', 'ACC', 'CIPLA', 'GAIL']
data = tsl.get_ltp_data(names=)

.
.
.

If you are using Historical data and want to optimize the same, use below method.

on cmd write pip show Dhan-Tradehull

you will get below response

then goto: Location … example (c:\users\imran\appdata\local\programs\python\python38\lib\site-packages)

find Dhan_Tradehull folder
find Dhan_Tradehull.py
find function get_historical_data

remove time.sleep(2)… or make it time.sleep(0.5)

now we have a limit of 10000 historical api calls per day

lets say they you are working on 5 mins timeframe… so we can make the changes in the code such the the historical data is called only once in 5 mins… This is important and should be implemented… because we have now removed time.sleep()… and if we keep calling historical data then the 10000 api call rate limit would be exceeded… so make changes in code such the for 5 min timeframe … we call historical data only once in 5 min

2 Likes

Hey everyone,
We have updated the our codebase. The below are the changes done

  1. Added num_strikes in the option chain
option_chain = tsl.get_option_chain(Underlying="NIFTY", exchange="INDEX", expiry=0, num_strikes=10)
  1. Fixed the strike selection issue for NIFTY and FINNIFTY.
CE_symbol_name, PE_symbol_name, strike_price = tsl.ATM_Strike_Selection(Underlying='NIFTY', Expiry=0)
  1. Fetched LTP for INDIA VIX
ltp = tsl.get_ltp_data(['INDIA VIX'])

Use the below code to update the codebase:
pip install --upgrade Dhan-Tradehull

Refer the below pypi link for more details:
https://pypi.org/project/Dhan-Tradehull/

2 Likes

Thanks now its fine but not as fast as previous one.

i dont understand logic of 1000 Data APIs call limit in 1 min when we can call only max 10 API call in 1 sec… means we can use only 600 API calls in a min out of 1000 limit… let me know if i am wrong.

@Tradehull_Imran

forgot to answer the other part…

I need to call 1 historical call for each stock… later i need LTP call for for each shortlisted stocks for Trailing SL/SL/Tgt orders.

Fetching wrong data for NIFTY historical data.

@Tradehull_Imran
THANK YOU SO MUCH SIR.

@Tradehull_Imran @Dhananjay_Umalkar with orderId I get all these details , but how can I know my postion is open or not , intrady as well position ??

(Pdb++) o=tsl.get_order_detail(‘32250228223205’)
Order ID 32250228223205: {‘dhanClientId’: ‘1103635437’, ‘orderId’: ‘32250228223205’, ‘exchangeOrderId’: ‘1200000068877799’, ‘correlationId’: ‘NA’, ‘orderStatus’: ‘TRADED’, ‘transactionType’: ‘SELL’, ‘exchangeSegment’: ‘NSE_FNO’, ‘productType’: ‘MARGIN’, ‘orderType’: ‘MARKET’, ‘validity’: ‘DAY’, ‘tradingSymbol’: ‘NIFTY-Mar2025-22500-PE’, ‘securityId’: ‘68447’, ‘quantity’: 75, ‘disclosedQuantity’: 0, ‘price’: 266.3, ‘triggerPrice’: 0.0, ‘afterMarketOrder’: False, ‘boProfitValue’: 0.0, ‘boStopLossValue’: 0.0, ‘legName’: ‘NA’, ‘createTime’: ‘2025-02-28 12:07:48’, ‘updateTime’: ‘2025-02-28 12:07:48’, ‘exchangeTime’: ‘2025-02-28 12:07:48’, ‘drvExpiryDate’: ‘2025-03-06’, ‘drvOptionType’: ‘PUT’, ‘drvStrikePrice’: 22500.0, ‘omsErrorCode’: ‘0’, ‘omsErrorDescription’: ‘TRADE CONFIRMED’, ‘algoId’: ‘0’, ‘remainingQuantity’: 0, ‘averageTradedPrice’: 266.3, ‘filledQty’: 75}

please check chart on nse website and trading view