please see image. i am not unable to work
Check this one if still you are facing issue Please share your code file
@Tradehull_Imran Sir already updated in the code file, for you can download again for fix this
import pdb
import time
import datetime
import traceback
from Dhan_Tradehull import Tradehull
import pandas as pd
from pprint import pprint
import talib
client_code = ââ
token_id = ââ
tsl = Tradehull(client_code,token_id)
all_ltp_data = tsl.get_ltp_data(names = [âNIFTY 19 DEC 24000 akshdgasjhgdhgasjgdhjagsdCALLâ, âNIFTY 19 DEC 24000 PUTâ, âACCâ, âCIPLAâ])
acc_ltp = all_ltp_data[âACCâ]
pe_ltp = all_ltp_data[âNIFTY 19 DEC 24000 PUTâ]
stock_name = âNIFTYâ
ltp = tsl.get_ltp_data(names = [stock_name])[stock_name]
chart = tsl.get_historical_data(tradingsymbol = âNIFTYâ, exchange = âINDEXâ,timeframe=âDAYâ)
data = tsl.get_historical_data(tradingsymbol = âNIFTY 19 DEC 24000 CALLâ ,exchange = âNFOâ ,timeframe=â15â)
order_status = tsl.get_order_status(orderid=82241218256027)
order_price = tsl.get_executed_price(orderid=82241218256027)
order_time = tsl.get_exchange_time(orderid=82241218256027)
positions = tsl.get_positions()
orderbook = tsl.get_orderbook()
tradebook = tsl.get_trade_book()
holdings = tsl.get_holdings()
ce_name, pe_name, strike = tsl.ATM_Strike_Selection(Underlying=âNIFTYâ, Expiry=0)
ce_name, pe_name, ce_strike, pe_strike = tsl.OTM_Strike_Selection(Underlying=âNIFTYâ, Expiry=0, OTM_count=3)
ce_name, pe_name, ce_strike, pe_strike = tsl.ITM_Strike_Selection(Underlying=âNIFTYâ, Expiry=0, ITM_count=5)
Equity
entry_orderid = tsl.order_placement(tradingsymbol=âACCâ ,exchange=âNSEâ, quantity=1, price=0, trigger_price=0, order_type=âMARKETâ, transaction_type=âBUYâ, trade_type=âMISâ)
sl_orderid = tsl.order_placement(tradingsymbol=âACCâ ,exchange=âNSEâ, quantity=1, price=0, trigger_price=2200, order_type=âSTOPMARKETâ, transaction_type =âSELLâ, trade_type=âMISâ)
Options
entry_orderid = tsl.order_placement(tradingsymbol=âNIFTY 19 DEC 24400 CALLâ ,exchange=âNFOâ, quantity=50, price=0, trigger_price=0, order_type=âMARKETâ, transaction_type=âBUYâ, trade_type=âMISâ)
sl_orderid = tsl.order_placement(tradingsymbol=âNIFTY 19 DEC 24400 CALLâ ,exchange=âNFOâ, quantity=25, price=29, trigger_price=30, order_type=âSTOPLIMITâ, transaction_type=âSELLâ, trade_type=âMISâ)
modified_order = tsl.modify_order(order_id=sl_orderid,order_type=âSTOPLIMITâ,quantity=50,price=price,trigger_price=trigger_price)
order_ids = tsl.place_slice_order(tradingsymbol=âNIFTY 19 DEC 24400 CALLâ, exchange=âNFOâ,quantity=5000, transaction_type=âBUYâ,order_type=âLIMITâ,trade_type=âMISâ,price=0.05)
margin = tsl.margin_calculator(tradingsymbol=âACCâ, exchange=âNSEâ, transaction_type=âBUYâ, quantity=2, trade_type=âMISâ, price=2180, trigger_price=0)
margin = tsl.margin_calculator(tradingsymbol=âNIFTY 19 DEC 24400 CALLâ, exchange=âNFOâ, transaction_type=âSELLâ, quantity=25, trade_type=âMARGINâ, price=43, trigger_price=0)
margin = tsl.margin_calculator(tradingsymbol=âNIFTY 19 DEC 24400 CALLâ, exchange=âNFOâ, transaction_type=âBUYâ, quantity=25, trade_type=âMARGINâ, price=43, trigger_price=0)
margin = tsl.margin_calculator(tradingsymbol=âNIFTY DEC FUTâ, exchange=âNFOâ, transaction_type=âBUYâ, quantity=25, trade_type=âMARGINâ, price=24350, trigger_price=0)
exit_all = tsl.cancel_all_orders()
hello @Tradehull_Imran whenever im trying to plot close why that line is linear what is the error in code
If you go to the below link I already explained why the error is coming.
Once again I am sending you the updated code. Please let us know still if you are getting error
import pdb
import time
import datetime
import traceback
from Dhan_Tradehull_V2 import Tradehull
import pandas as pd
from pprint import pprint
import talib
client_code = ""
token_id = ""
tsl = Tradehull(client_code,token_id)
all_ltp_data = tsl.get_ltp_data(names = ['NIFTY 27 FEB 23000 CALL', 'NIFTY 27 FEB 23000 PUT', "ACC", "CIPLA"])
acc_ltp = all_ltp_data['ACC']
pe_ltp = all_ltp_data['NIFTY 27 FEB 23000 PUT']
stock_name = 'NIFTY'
ltp = tsl.get_ltp_data(names = [stock_name])[stock_name]
chart = tsl.get_historical_data(tradingsymbol = 'NIFTY', exchange = 'INDEX',timeframe="DAY")
data = tsl.get_historical_data(tradingsymbol = 'NIFTY 27 FEB 23000 PUT' ,exchange = 'NFO' ,timeframe="15")
order_status = tsl.get_order_status(orderid=82241218256027)
order_price = tsl.get_executed_price(orderid=82241218256027)
order_time = tsl.get_exchange_time(orderid=82241218256027)
positions = tsl.get_positions()
orderbook = tsl.get_orderbook()
tradebook = tsl.get_trade_book()
holdings = tsl.get_holdings()
ce_name, pe_name, strike = tsl.ATM_Strike_Selection(Underlying='NIFTY', Expiry=0)
ce_name, pe_name, ce_strike, pe_strike = tsl.OTM_Strike_Selection(Underlying='NIFTY', Expiry=0, OTM_count=3)
ce_name, pe_name, ce_strike, pe_strike = tsl.ITM_Strike_Selection(Underlying='NIFTY', Expiry=0, OTM_count=5)
# Equity
entry_orderid = tsl.order_placement(tradingsymbol='ACC' ,exchange='NSE', quantity=1, price=0, trigger_price=0, order_type='MARKET', transaction_type='BUY', trade_type='MIS')
sl_orderid = tsl.order_placement(tradingsymbol='ACC' ,exchange='NSE', quantity=1, price=0, trigger_price=2200, order_type='STOPMARKET', transaction_type ='SELL', trade_type='MIS')
# Options
entry_orderid = tsl.order_placement(tradingsymbol='NIFTY 27 FEB 23000 CALL' ,exchange='NFO', quantity=50, price=0, trigger_price=0, order_type='MARKET', transaction_type='BUY', trade_type='MIS')
sl_orderid = tsl.order_placement(tradingsymbol='NIFTY 27 FEB 23000 CALL' ,exchange='NFO', quantity=25, price=29, trigger_price=30, order_type='STOPLIMIT', transaction_type='SELL', trade_type='MIS')
modified_order = tsl.modify_order(order_id=sl_orderid,order_type="STOPLIMIT",quantity=50,price=price,trigger_price=trigger_price)
order_ids = tsl.place_slice_order(tradingsymbol="NIFTY 27 FEB 23000 CALL", exchange="NFO",quantity=5000, transaction_type="BUY",order_type="LIMIT",trade_type="MIS",price=0.05)
margin = tsl.margin_calculator(tradingsymbol='ACC', exchange='NSE', transaction_type='BUY', quantity=2, trade_type='MIS', price=2180, trigger_price=0)
margin = tsl.margin_calculator(tradingsymbol='NIFTY 27 FEB 23000 CALL', exchange='NFO', transaction_type='SELL', quantity=25, trade_type='MARGIN', price=43, trigger_price=0)
margin = tsl.margin_calculator(tradingsymbol='NIFTY 27 FEB 23000 CALL', exchange='NFO', transaction_type='BUY', quantity=25, trade_type='MARGIN', price=43, trigger_price=0)
margin = tsl.margin_calculator(tradingsymbol='NIFT FEB PUT', exchange='NFO', transaction_type='BUY', quantity=25, trade_type='MARGIN', price=24350, trigger_price=0)
exit_all = tsl.cancel_all_orders()
Hi @Hardik
Is dhanhq have ability get future data ( from where I can create future data scanner[heatmap] like long buildup, Short buildup etc. )
Please reply
If not please bring it
and gentle reminder please increase daily data limit which is require for
- Scanning
- Equity
- Commodity
- to hit Target / Stop-loss ( I need frequent market scanning to get proper entry and exit )
Hello @Subhajitpanja
We have already increased the Daily Rate limits, update on the same coming soon.
We already have futures data available on DhanHQ APIs. For building a scanner based on buildups, you will need to combine OI as well as price data, both of which you can get from the APIs itself.
Thank you so much @Hardik
@RahulDeshpande same order i can place as âMISâ
but NRML and CNC not able to place
(Pdb++) order_id = tsl.order_placement(tradingsymbol=âNIFTY 27 FEB 22900 CALLâ, exchange=âNFOâ, quantity=75, price=0, trigger_price=0, order_type=âMARKETâ, transaction_type=âBUYâ, trade_type=âCNCâ, disclosed_quantity=0, after_market_order=False, amo_time=âOPENâ)
'Got exception in place_order as {âstatusâ: âfailureâ, âremarksâ: {âerror_codeâ: âDH-906â, âerror_typeâ: âOrder_Errorâ, âerror_messageâ: âTrades are not allowed for this Product / Scripâ}, âdataâ: {âerrorTypeâ: âOrder_Errorâ, âerrorCodeâ: âDH-906â, âerrorMessageâ: âTrades are not allowed for this Product / Scripâ}}
(Pdb++)
Does anybody has the working sample for trailing? As of now, I have a fixed target. I want to extend my algo for better profit
Hi @prajak_amrute ,
Do update codebase on your system
- 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
Hi @Krunal_Darji ,
Use the below code:
nifty = 'NIFTY 5 MINS.csv' # File path
index_data = pd.read_csv(nifty)
plt.plot(index_data['close'])
plt.savefig("nifty_plot.png")
plt.show()
Hi @Manish1 ,
To place a NORMAL order in the algo, we need to set the tradetype
parameter to 'MARGIN'
.
refer the below code:
order_id = tsl.order_placement(tradingsymbol='NIFTY 27 FEB 26000 CALL', exchange='NFO', quantity=75, price=0, trigger_price=0, order_type='MARKET', transaction_type='BUY', trade_type='MARGIN', disclosed_quantity=0)
Refer the below code for trailing the target points for BUY side:
entry_price = 100
initial_target = 110
trail_points = 2
target_points = initial_target + trail_points
while True:
ltp = tsl.get_ltp_data([name])
if ltp > target_points:
target_points += trail_points
print(f"New Target: {target_points}")
Refer the below for trailing stoploss:
ATM Strike Selection get wrongly select
i run my code in NIFTY but as today got an error From Dhan_Tradehull_V2
instead selection NIFTY is select FINNIFTY its first time in 2 mounts
Exception for instrument name FINNIFTY-FEB2025-22750-PE as Check the Trading symbol
got exception in pnl as âFINNIFTY-Feb2025-22750-PEâ
2025-02-21 16:52:37,630 - ERROR - got exception in pnl as âFINNIFTY-Feb2025-22750-PEâ
Traceback (most recent call last):
File âc:\Users\Jay\OneDrive\Apps\Index_data\Dhan_Tradehull_V2.pyâ, line 346, in get_live_pnl
closePrice = ltp_data[underlying]
KeyError: âFINNIFTY-Feb2025-22750-PEâ
Scaning NIFTY
atm_ce_name: NIFTY 27 FEB 22800 CALL, atm_pe_name: NIFTY 27 FEB 22800 PUT, strike: 22800
@Tradehull_Imran
@Tradehull_Imran Sir,
Yes today it happened with me too⌠for at least 2 rounds of 5 min data
instead of NIFTY options FINNIFTY options were displaced⌠I pinched myself twice, when saw this⌠but now seeing this post⌠I am replyingâŚ
Hi Sir,
Can u please share the new code base which we are using in Advance course
Hi @Tradehull_Imran ,
I want to print last 500 candles data of 5 min timeframes,
what can be the issue in this case?
and I can export all the data as well.
chart = tsl.get_historical_data(tradingsymbol="NIFTY", exchange="INDEX", timeframe='5')
chart.tail(500)
Hi @Tradehull_Imran Sir,
After buying ATM Options, if the Target-1 level gets Hit in only one candle, I want to move my SL to target-1 level and new target level will be TARGET-2⌠how to check this i.e; how to check the condition of reaching T-1 in only one candle⌠Also gimme the code to modify the SL and Target⌠plsâŚ