Learn Algo Trading with Python | Codes | Youtube Series

@Tradehull_Imran Sir

I Ran That Py File In Vs Codes Terminal So

1st Ishue Is Look The Image That Trancebook Ishue How I Can Solve It

2nd Is That File Is Running Currectly Or Not

@Tradehull_Imran Sir Please Guide Me

Very Good Morning Sir,

I am getting the following error, while executing install libraries.bat from session 2 folder. As you have suggested me to install talib by using this particular file from Session 2 folder.

CMD Error:
Requirement already satisfied: packaging>=23.1 in c:\users\rp\appdata\local\programs\python\python38\lib\site-packages (from chromedriver-autoinstaller) (24.1)
WARNING: Requirement ‘C:\Users\RP\Desktop\DHAN Algorhythemic Trading\Session2\Installation\Twisted-20.3.0-cp38-cp38-win_amd64.whl’ looks like a filename, but the file does not exist
Processing c:\users\rp\desktop\dhan algorhythemic trading\session2\installation\twisted-20.3.0-cp38-cp38-win_amd64.whl
ERROR: Could not install packages due to an OSError: [Errno 2] No such file or directory: ‘C:\Users\RP\Desktop\DHAN Algorhythemic Trading\Session2\Installation\Twisted-20.3.0-cp38-cp38-win_amd64.whl’

WARNING: Requirement ‘C:\Users\RP\Desktop\DHAN Algorhythemic Trading\Session2\Installation\TA_Lib-0.4.24-cp38-cp38-win_amd64.whl’ looks like a filename, but the file does not exist
Processing c:\users\rp\desktop\dhan algorhythemic trading\session2\installation\ta_lib-0.4.24-cp38-cp38-win_amd64.whl
ERROR: Could not install packages due to an OSError: [Errno 2] No such file or directory: ‘C:\Users\RP\Desktop\DHAN Algorhythemic Trading\Session2\Installation\TA_Lib-0.4.24-cp38-cp38-win_amd64.whl’

Press any key to continue . . .

Guide me sir.

Hi
@Tradehull_Imran
There is no NRML order works onli MIS works

So please remove the error


C:\Algo Practice\Trading>py “Future BankNifty.py”
Codebase Version 2.1
-----Logged into Dhan-----
reading existing file all_instrument 2024-12-24.csv
Got the instrument file
BUY BANKNIFTY DEC FUT 09:39:53.334306 False True False True TrueTrue cc_1 2024-12-24 09:30:00+05:30
SELL BANKNIFTY DEC FUT 09:39:53.334306 True True True True TrueTrue cc_1 2024-12-24 09:30:00+05:30

BANKNIFTY DEC FUT its time to, Buy this Future
Traceback (most recent call last):
File “C:\Algo Practice\Trading\Dhan_Tradehull_V2.py”, line 128, in order_placement
product_Type = product[trade_type.upper()]
KeyError: ‘NRML’
Error at get_executed_price as list index out of range
Traceback (most recent call last):
File “Future BankNifty.py”, line 132, in
trade_info[‘sl’] = round((trade_info[‘entry_price’]+130),1)
TypeError: unsupported operand type(s) for +: ‘dict’ and ‘int’

lot_size = 15 #tsl.get_lot_size(index_name)*1
trade_info[‘index_name’] = index_name
trade_info[‘entry_orderid’]= tsl.order_placement(trade_info[‘index_name’],‘NFO’, lot_size, 0, 0, ‘MARKET’, ‘SELL’, ‘NRML’)
time.sleep(1)
trade_info[‘entry_price’]= tsl.get_executed_price(orderid=trade_info[‘entry_orderid’])
traded = “yes”
trade_info[‘qty’] = lot_size
trade_info[‘sl’] = round((trade_info[‘entry_price’]+130),1)
traded_wathclist.append(index_name)

Hi @CHETAN_99

I am bit unclear on the question,
but on high level the code seems to be working fine

Hi @Vasili_Prasad


error : 
No such file or directory: ‘C:\Users\RP\Desktop\DHAN Algorhythemic Trading\Session2\Installation\TA_Lib-0.4.24-cp38-cp38-win_amd64.whl’

most probably TA_Lib-0.4.24-cp38-cp38-win_amd64.whl and Twisted-20.3.0-cp38-cp38-win_amd64.whl are not in the same folder where install libraries.bat is kept

they all should be in same folder

Hi @Kalpeshh_Patel

use below code ,


entry_orderid  = tsl.order_placement(tradingsymbol='NIFTY 26 DEC 23950 CALL' ,exchange='NFO', quantity=100, price=0, trigger_price=0, order_type='MARKET', transaction_type='BUY', trade_type='CNC')

sir i wanted to say how i can solve this following problem

-----Logged into Dhan-----
This BOT Is Picking New File From Dhan
Got the instrument file
2024-12-24 10:39:39,935 - ERROR - Error processing GMRINFRA: No expiry date found for GMRINFRA
Traceback (most recent call last):
File “C:\Users\Chetan More\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 GMRINFRA

Hi @virender_singh

We have now updated thew file for quote data
use : Dhan_Tradehull_V2.py - Google Drive

example usage

quote_data = tsl.get_quote(names = ['NIFTY 26 DEC 23950 CALL'])
pprint(quote_data)

response received
{'NIFTY 26 DEC 23950 CALL': {'average_price': 39.34,
                             'buy_quantity': 445075,
                             'depth': {'buy': [{'orders': 1,
                                                'price': 45.4,
                                                'quantity': 50},
                                               {'orders': 1,
                                                'price': 45.35,
                                                'quantity': 150},
                                               {'orders': 14,
                                                'price': 45.3,
                                                'quantity': 2400},
                                               {'orders': 20,
                                                'price': 45.25,
                                                'quantity': 3400},
                                               {'orders': 15,
                                                'quantity': 2025}],
                                       'sell': [{'orders': 4,
                                                 'price': 45.45,
                                                 'quantity': 900},
                                                {'orders': 21,
                                                 'price': 45.5,
                                                 'quantity': 3500},
                                                {'orders': 20,
                                                 'price': 45.55,
                                                 'quantity': 3250},
                                                {'orders': 17,
                                                 'price': 45.6,
                                                 'quantity': 3075},
                                                {'orders': 10,
                                                 'price': 45.65,
                                                 'quantity': 2100}]},
                             'last_price': 45.45,
                             'last_quantity': 125,
                             'last_trade_time': '24/12/2024 11:07:10',
                             'lower_circuit_limit': 0.05,
                             'net_change': 8.5,
                             'ohlc': {'close': 36.95,
                                      'high': 58,
                                      'low': 20.7,
                                      'open': 28.95},
                             'oi': 2948375,
                             'oi_day_high': 2969750,
                             'oi_day_low': 2506300,
                             'sell_quantity': 451975,
                             'upper_circuit_limit': 416.4,
                             'volume': 28113725}}

@Tradehull_Imran Is there an option to filter the instrument file. It has around 1.8L rows and don’t trade those. Its an extra overload for the script. Is it possible to optimise it?

https://images.dhan.co/api-data/api-scrip-master.csv

Hi @Rajashekhar_Rangappa

instrument file is used by the codebase, also its a one time read at the initialization.
Yes, the file is bit heavy but I think its still not a bottleneck to performance.

“Premature optimization is the root of all evil.” - Donald Knuth

1 Like

Yes sir, This above mentioned file is there in the Session 2 folder sir. Please check sir.
VBR Prasad

Hi @Vasili_Prasad

Do try the installation and share the screen recording of the same.
share the file to : tradehull_mentorship@tradehull.com

Respected Imran Sir, We would be greatfull to you, if you can post the Video clip of the Mumbai Meet. Thank you sir.

VBR Prasad

1 Like

Okay sir. Thank you very much

Sir, I was trying to execute Combined premium file in API Upgrade folder.
Following is the code and error details.

CODE:`import pdb
import time
import datetime
import traceback
from Dhan_Tradehull_V2 import Tradehull
import pandas as pd
from pprint import pprint
import talib
import time

---------------for dhan login ----------------

client_code = “1101092420”
token_id = “eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJpc3MiOiJkaGFuIiwicGFydG5lcklkIjoiIiwiZXhwIjoxNzM0NjA4ODc1LCJ0b2tlbkNvbnN1bWVyVHlwZSI6IlNFTEYiLCJ3ZWJob29rVXJsIjoiIiwiZGhhbkNsaWVudElkIjoiMTEwMTA5MjQyMCJ9.TfMDBHpTlWqlfJ0dC-28fyLUuLC0Q_239Y6IYAuEkfZqZvgZns_PI3lk1HnOdmo6gvTwrhDAn3tLv4oZ0u-T5Q”
tsl = Tradehull(client_code,token_id)

call_list = [‘NIFTY 26 DEC 23800 CALL’, ‘NIFTY 26 DEC 23800 PUT’]

while True:
current_time = datetime.datetime.now()
ltp_data = tsl.get_ltp_data(names = call_list)
ce_ltp = ltp_data[‘NIFTY 26 DEC 23800 CALL’]
pe_ltp = ltp_data[‘NIFTY 26 DEC 23800 PUT’]

atm_combined_premium = ce_ltp + pe_ltp
print(current_time, atm_combined_premium)
time.sleep(0.5)

ERROR:
C:\Users\LENOVO PC\Desktop\RP\DHAN Algorhythemic Trading\1. Api Upgrade>py “1.2 combined premium.py”
Codebase Version 2.3 : Solved - ATM issues
-----Logged into Dhan-----
reading existing file all_instrument 2024-12-24.csv
Got the instrument file
Exception at calling ltp as {‘status’: ‘failure’, ‘remarks’: {‘error_code’: None, ‘error_type’: None, ‘error_message’: None}, ‘data’: {‘data’: {‘808’: ‘Authentication Failed - Client ID or Token invalid’}, ‘status’: ‘failed’}}
Traceback (most recent call last):
File “1.2 combined premium.py”, line 33, in
ce_ltp = ltp_data[‘NIFTY 26 DEC 23800 CALL’]
KeyError: ‘NIFTY 26 DEC 23800 CALL’`

Sorry sir, I forgot to update the token_id, now the combined premium file is functional sir.
Thank you
VBR Prasad

1 Like

Hello Sir,

Did you check the same. Every time I am getting live_pnl as 0. Also those exceptions as well.

regards

Thanks. you have pdb set in get_quote function. please comment it out.

1 Like

Hi @Vasili_Prasad
Error says

Exception at calling ltp as {‘status’: ‘failure’, ‘remarks’: {‘error_code’: None, ‘error_type’: None, ‘error_message’: None}, ‘data’: {‘data’: {‘808’: ‘Authentication Failed - Client ID or Token invalid’}, ‘status’: ‘failed’}}

  1. check if Client ID is correct
  2. Also do check if the token being used is not expired

Hi @balrajsingh

if the position book is empty the function will return 0, because no position has been created as of now.