Hi @Tradehull_Imran ,
Thanks, will share the update.
Hi @Tradehull_Imran ,
Thanks, will share the update.
Hello @Tradehull_Imran
Thanks for the update, I replaced the Tradehull_Dhan_V2, now I am getting the below…not able to place order
D:\ALgo Programming\9. Session8- 2.1 Version Live Algo\9. Session 9 Dhan_Tradehull_V2>py “My Test Algo.py”
-----Logged into Dhan-----
reading existing file all_instrument 2024-11-18.csv
Got the instrument file
MANAPPURAM
MANAPPURAM is in uptrend, Buy this script
Traceback (most recent call last):
File “C:\Users\priye\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\core\indexes\base.py”, line 3653, in get_loc
return self._engine.get_loc(casted_key)
File “pandas_libs\index.pyx”, line 147, in pandas._libs.index.IndexEngine.get_loc
File “pandas_libs\index.pyx”, line 176, in pandas._libs.index.IndexEngine.get_loc
File “pandas_libs\hashtable_class_helper.pxi”, line 7080, in pandas._libs.hashtable.PyObjectHashTable.get_item
File “pandas_libs\hashtable_class_helper.pxi”, line 7088, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: True
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File “My Test Algo.py”, line 90, in
sell_price = round((cc_5[up_cross]*1.01),1)
File “C:\Users\priye\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\core\series.py”, line 1007, in getitem
return self._get_value(key)
File “C:\Users\priye\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\core\series.py”, line 1116, in _get_value
loc = self.index.get_loc(label)
File “C:\Users\priye\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\core\indexes\base.py”, line 3655, in get_loc
raise KeyError(key) from err
KeyError: True
Now its working, I tried this for target order, target not working, sl is working:
sl_price = round((cc_1[‘close’]*1.02),1)
tgt_price = round((cc_1[‘close’]*0.98),1)
qty = int(per_trade_margin/cc_1[‘close’])
buy_entry_orderid = tsl.order_placement(stock_name,‘NSE’, 1, 0, 0, ‘MARKET’, ‘SELL’, ‘MIS’)
sl_orderid = tsl.order_placement(stock_name,‘NSE’, 1, 0, sl_price, ‘STOPMARKET’, ‘BUY’, ‘MIS’)
tgt_orderid = tsl.order_placement(stock_name,‘NSE’, 1, 0, tgt_price, ‘LIMIT’, ‘SELL’, ‘MIS’)
traded_wathclist.append(stock_name)
Thanks it’s now working, I am able to get intraday data.
Hi, I have uploaded zip folder on my google drive and shared it with you.
After updating the Dhan_Tradehull_V2 file as suggested, I am getting the below errors. Please help me to resolve it.
Hi sir,
import pdb
import time
import datetime
import traceback
import talib
from Dhan_Tradehull_V2 import Tradehull
import pandas as pd
import pandas_ta as ta
import numpy as np
client_code = “"
token_id = "”
tsl = Tradehull(client_code, token_id)
otm_ce_name, otm_pe_name, ce_OTM_strike, pe_OTM_strike = tsl.OTM_Strike_Selection(‘SENSEX’,‘22-11-2024’,3)
ce_chart = tsl.get_intraday_data(otm_ce_name, ‘BFO’, 5)
I’m getting the error like: value error: If using all scalar values, you must pass an index.
import pdb
import time
import datetime
import traceback
import talib
from Dhan_Tradehull_V2 import Tradehull
import pandas as pd
import pandas_ta as ta
import numpy as np
client_code = “"
token_id = "”
tsl = Tradehull(client_code, token_id)
otm_ce_name, otm_pe_name, ce_OTM_strike, pe_OTM_strike = tsl.OTM_Strike_Selection(‘NIFTY’,‘21-11-2024’,3)
ce_chart = tsl.get_intraday_data(otm_ce_name, ‘NFO’, 5)
but this code working fine.
Please help me.
hiii, will you upload your code folder and upload it on google drive and plzz share drive link t ome
@Shravan_Kotagi, from the error you can see you need to subscribe to Data API.
You have sucessfully excuted the code na, so you have subscribed to data API ??
Thank you sir for your help.
How can i get VWAP indicator for my algo. Can you please help me with it?
Thank You in Advance.
Hello, I see that token or cleint id error in your error screenshot. Would you kindly verify that the tokens are still valid and being used with the correct ID?
Hello Sir, I am using LibreOffice, could you please share me the code so that we can use the Websocket.xlsx file in this software format.
Hi @Priyesh_Sharma
Send google drive link of .zip of code files as well.
Hi @Shravan_Kotagi
Yes we need to subscribe to the historical data
check this code
import pandas_ta as pta
index_chart = tsl.get_historical_data(tradingsymbol='NIFTY NOV FUT', exchange='NFO', timeframe="5")
index_chart.set_index(pd.DatetimeIndex(index_chart['timestamp']), inplace=True)
index_chart['vwap'] = pta.vwap(index_chart['high'] , index_chart['low'], index_chart['close'] , index_chart['volume'])
WebSocket is a old method that we used to fetch LTP, you may now access LTP in easy format using Dhan_Tradehull_V2
see : Learn Algo Trading with Python | Codes | Youtube Series - #631 by Tradehull_Imran
Hi @Zee2Zahid
for order-placement see below examples
# To place any order for the Tradingsymbol
# Order types:
# - MARKET: to place a Market order
# - LIMIT: to place a Limit order
# - STOPLIMIT: to place a stoploss limit order
# - STOPMARKET: to place a stoploss market order
# Trade types:
# - MIS: to place a intraday order
# - NRML: to place a positional order
tsl.order_placement(Tradingsymbol: str, Exchange: str,quantity: int, price: int, trigger_price: int, order_type: str, transaction_type: str, trade_type: str)
orderid = tsl.order_placement(tradingsymbol = 'NIFTY 21 NOV 23450 PUT',exchange ='NFO',quantity = 25, price = 0.05, trigger_price =0, order_type = 'LIMIT', transaction_type ='BUY', trade_type ='MIS')
orderid1 = tsl.order_placement('NIFTY 21 NOV 23450 PUT','NFO',25, 0.05, 0, 'LIMIT', 'BUY', 'MIS')
print(orderid1)
orderid = tsl.order_placement('NIFTY 21 NOV 23450 PUT','NFO',25, 0, 0, 'MARKET', 'BUY', 'MIS')
orderid = tsl.order_placement('NIFTY 21 NOV 23450 PUT','NFO', 25, 107, 0, 'LIMIT', 'BUY', 'MIS')
orderid = tsl.order_placement('NIFTY 21 NOV 23450 PUT','NFO', 25, 110, 120, 'STOPLIMIT', 'BUY', 'MIS')
orderid = tsl.order_placement('NIFTY 21 NOV 23450 PUT','NFO', 25, 0, 110, 'STOPMARKET', 'BUY', 'MIS')
# Assume wants to Buy NIFTY 21 NOV 23450 PUT and the LTP of this script is = 109 and place a stoploss order as well as target order
# To Buy this script at Market price and particular Limit price as of follow
# - Trade Type also will be two, based on Intraday or Carryforward
# MIS - MARKET (Intraday Market Price placement order)
orderid = tsl.order_placement(tradingsymbol = 'NIFTY 21 NOV 23450 PUT',exchange ='NFO',quantity = 25, price = 0, trigger_price =0, order_type = 'MARKET', transaction_type ='BUY', trade_type ='MIS')
# Here price and trigger_price is 0 because of market order
# NRML - MARKET (Carryforward Market Price placement order)
orderid = tsl.order_placement(tradingsymbol = 'NIFTY 21 NOV 23450 PUT',exchange ='NFO',quantity = 25, price = 0, trigger_price =0, order_type = 'MARKET', transaction_type ='BUY', trade_type ='NRML')
# Here price and trigger_price is 0 because of market order
# MIS - LIMIT (Intraday particular Limit Price placement order)
orderid = tsl.order_placement(tradingsymbol = 'NIFTY 21 NOV 23450 PUT',exchange ='NFO',quantity = 25, price = 107, trigger_price =0, order_type = 'LIMIT', transaction_type ='BUY', trade_type ='MIS')
# Here price is 107 and trigger_price is 0 because of LIMIT Order, Wants to Buy at 107 price
# NRML - LIMIT (Carryforward particular Limit placement order)
orderid = tsl.order_placement(tradingsymbol = 'NIFTY 21 NOV 23450 PUT',exchange ='NFO',quantity = 25, price = 107, trigger_price =0, order_type = 'LIMIT', transaction_type ='BUY', trade_type ='NRML')
# Here price is 107 and trigger_price is 0 because of LIMIT Order, Wants to Buy at 107 price
# Assume bought the NIFTY 21 NOV 23450 PUT at 110 and now wants to place stoploss and target orders
# MIS - STOPLOSS MARKET (Intraday Stoploss MARKET Order for selling the script)
orderid = tsl.order_placement(tradingsymbol = 'NIFTY 21 NOV 23450 PUT',exchange ='NFO',quantity = 25, price = 0, trigger_price =109, order_type = 'STOPMARKET', transaction_type ='SELL', trade_type ='MIS')
# Here price is 0 because of stoploss market order, want to sell at 109 or below prcie level reached
# NRML - STOPLOSS MARKET (Carryforward Stoploss MARKET Order for selling the script)
orderid = tsl.order_placement(tradingsymbol = 'NIFTY 21 NOV 23450 PUT',exchange ='NFO',quantity = 25, price = 0, trigger_price =109, order_type = 'STOPMARKET', transaction_type ='SELL', trade_type ='MIS')
# Here price is 0 because of stoploss market order, want to sell at 109 or below prcie level reached
# MIS - STOPLOSS LIMIT (Intraday Stoploss Limit Order for selling the script)
orderid = tsl.order_placement(tradingsymbol = 'NIFTY 21 NOV 23450 PUT',exchange ='NFO',quantity = 25, price = 104, trigger_price =109, order_type = 'STOPLIMIT', transaction_type ='SELL', trade_type ='MIS')
# Here, the limit price is 104 and the trigger price is 109. The order will be triggered when the market reaches 109, but the sell will only execute if it can get filled at 104 or better.
# NRML - STOPLOSS LIMIT (Carryforward Stoploss Limit Order for selling the script)
orderid = tsl.order_placement(tradingsymbol = 'NIFTY 21 NOV 23450 PUT',exchange ='NFO',quantity = 25, price = 104, trigger_price =109, order_type = 'STOPLIMIT', transaction_type ='SELL', trade_type ='MIS')
# Here, the limit price is 104 and the trigger price is 109. The order will be triggered when the market reaches 109, but the sell will only execute if it can get filled at 104 or better.
Target orders are not any specific order types, place the order type opposite of entry using limit oe market orders.
# Assume Current LTP of NIFTY 21 NOV 23450 PUT is 120, wants to exit or sell this position at market price
# MIS - MARKET (Intraday Market Price placement order)
orderid = tsl.order_placement(tradingsymbol = 'NIFTY 21 NOV 23450 PUT',exchange ='NFO',quantity = 25, price = 0, trigger_price =0, order_type = 'MARKET', transaction_type ='SELL', trade_type ='MIS')
# Here price and trigger_price is 0 because of market order
# NRML - MARKET (Carryforward Market Price placement order)
orderid = tsl.order_placement(tradingsymbol = 'NIFTY 21 NOV 23450 PUT',exchange ='NFO',quantity = 25, price = 0, trigger_price =0, order_type = 'MARKET', transaction_type ='SELL', trade_type ='NRML')
# Here price and trigger_price is 0 because of market order
# Assume Current LTP of NIFTY 21 NOV 23450 PUT is 110, wants to exit or sell this position at 115 prcie LIMIT order once the LTP price reached 115
# Target orders are typically placed as limit orders for exiting at a profitable price.
# MIS - LIMIT (Intraday particular Limit Price placement order)
orderid = tsl.order_placement(tradingsymbol = 'NIFTY 21 NOV 23450 PUT',exchange ='NFO',quantity = 25, price = 115, trigger_price =0, order_type = 'LIMIT', transaction_type ='SELL', trade_type ='MIS')
# Here price is 115 and trigger_price is 0 because of LIMIT Order, Wants to SELL at 115 price
# NRML - LIMIT (Carryforward particular Limit placement order)
orderid = tsl.order_placement(tradingsymbol = 'NIFTY 21 NOV 23450 PUT',exchange ='NFO',quantity = 25, price = 115, trigger_price =0, order_type = 'LIMIT', transaction_type ='SELL', trade_type ='NRML')
# Here price is 115 and trigger_price is 0 because of LIMIT Order, Wants to SELL at 115 price
# After placing an order, the system returns an `orderid` for tracking the order. Users can monitor the status and modify or cancel it if necessary.
Hi @Tradehull_Imran Sir,
I am getting below error after placing it.
Code:
index_chart = tsl.get_historical_data(tradingsymbol='NIFTY NOV FUT', exchange='NFO', timeframe="1")
print(index_chart)
index_chart.set_index(pd.DatetimeIndex(index_chart['timestamp']), inplace=True)
index_chart['vwap'] = pta.vwap(index_chart['high'], index_chart['low'], index_chart['close'], index_chart['volume'])
Error:
{'status': 'failure', 'remarks': {'error_code': 'DH-905', 'error_type': 'Input_Exception', 'error_message': 'Missing required fields, bad values for parameters etc.'}, 'data': {'errorType': 'Input_Exception', 'errorCode': 'DH-905', 'errorMessage': 'Missing required fields, bad values for parameters etc.'}}
Traceback (most recent call last):
File "C:/Dhan/8. Session8- 2nd Live Algo/8. Session 8 Dhan_Tradehull_V2/vwap strategy.py", line 43, in <module>
index_chart.set_index(pd.DatetimeIndex(index_chart['timestamp']), inplace=True)
AttributeError: 'NoneType' object has no attribute 'set_index'
None```