@Tradehull_Imran when using braket order does the stoploss it places is it SL or SL_M type ? is there any chance to stoploss doesnt execute if price moved very fast?
also i have looked into tradehull.py the exchange segment dict in place order has mistake for BSE_FNO please whatever we do we get NSE_FNO.
Hello @Tradehull_Imran Sir,
I took your provided Dhan_Tradehull_V2.py file. But getting same issue. I observed that my Websocket.xlsx file is not getting updated. And LTP and other historical data also getting failed. I already subscribed for data.
Thanks
Sudip
Thank you sir , I will integrate and revert you.
Hi @Tradehull_Imran,
Everything was working fine till day before, but today morning I am getting this error:
Exception in Getting OHLC data as {'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.'}}
No intraday data available for MARKSANS
Please help.
even I am getting the same error.
Thanks for the reply, please let me know, how to do backtest ?
if we get such type of error everyday then how we can trust algo to execute on daily basis… please see the issue.
Even i’m getting the same error @Tradehull_Imran . Kindly help
Hi @rahulcse56 @kristrades99 @Aijaz_Ahmad
Use this file
Hi @Tradehull_Imran Sir,
Can you help here.
Working now…thanks
Hi @Arun_Rawat
-
Do subscribe to Data api.
check point 1 : Learn Algo Trading with Python | Codes | Youtube Series - #706 by Tradehull_Imran -
Use this codebase file
Dhan_Tradehull_V2.py - Google Drive
See this is what I am talking about, a simple pnl call is so intermittent. It was working and then did not, you say it is fixed, it was and now again it only returns 0 as Pnl now even with an open position. It is so Unreliable the Apis. It is hard to proceed with a setup when an imp function call fails, it breaks everything.
Hi @Msk92
Whenever the position_book data is not returned, the function will send a int(0), so as to prevent any code breaks
In the code for pnl based exit, it won’t make any exceptions as int value is returned
while True:
live_pnl = tsl.get_live_pnl()
current_time = datetime.datetime.now().time()
if current_time < datetime.time(9, 30):
print("wait for market to start", current_time)
continue
if (current_time > datetime.time(15, 15)) or (live_pnl < max_loss):
I_want_to_trade_no_more = tsl.kill_switch('ON')
order_details = tsl.cancel_all_orders()
print("Market is over, Bye Bye see you tomorrow", current_time)
break
see : Murphy’s Law
Hi @Tradehull_Imran,
while placing a buy limit order, I want to check if the order has been placed successfully or the order is still pending. If the order is still pending I want to cancel it within certain duration. Below is the code.
# Check the condition and place the order accordingly
if current_market_price > high_9_15:
print(f"Buying {first_stock['Ticker']} at market price.")
buy_entry_orderid = tsl.order_placement(first_stock['Ticker'], 'NSE', qty, 0, 0, 'MARKET', 'BUY', 'MIS')
else:
print(f"Placing a buy limit order for {first_stock['Ticker']} above the high of 9:15 candle.")
buy_entry_orderid = tsl.order_placement(first_stock['Ticker'], 'NSE', qty, 0, high_9_15 + 0.05, 'STOPMARKET', 'BUY', 'MIS') # Adjust the increment as needed
print(f"Order ID: {buy_entry_orderid}")
while True:
try:
# Get order details
order_details = tsl.get_order_detail(orderid=buy_entry_orderid)
print(f"Order details: {order_details}")
# Double check if the order is completed
order_status = tsl.get_order_status(orderid=buy_entry_orderid)
print(f"Order status response: {order_status}")
if order_status == "TRADED":
print("I have double checked: Order Completed")
break
# Get order time and calculate the time spent since the order was placed
order_time_response = tsl.get_exchange_time(orderid=buy_entry_orderid)
print(f"Order time response: {order_time_response}")
# Check if order_time_response is valid
if isinstance(order_time_response, str):
order_time = order_time_response
elif isinstance(order_time_response, dict) and 'exchangeTime' in order_time_response:
order_time = order_time_response['exchangeTime']
else:
order_time = None
if order_time and order_time != '0001-01-01 00:00:00':
order_sent_time = datetime.datetime.strptime(order_time, '%Y-%m-%d %H:%M:%S')
time_spent = ((datetime.datetime.now() - order_sent_time).total_seconds() / 60)
# If the order has not been traded within 5 minutes, cancel it
if (time_spent > 5) and (order_status != 'TRADED'):
tsl.cancel_order(buy_entry_orderid)
print(f"Order ID {buy_entry_orderid} has been canceled due to timeout.")
break
else:
print(f"Order ID {buy_entry_orderid} is still pending.")
else:
print("Error: Order time response is invalid")
# Sleep for a short interval before checking again
time.sleep(30)
except Exception as e:
print(f"An error occurred: {e}")
break
But I am getting below error and even though it says “Order ID 6124112124933 has been canceled due to timeout.” but it’s not cancelled.
Order status response: PENDING
Order time response: 2024-11-21 11:46:49
Traceback (most recent call last):
File "D:\Dhan\My Algo\Dhan_Tradehull_V2.py", line 1402, in cancel_order
response = self.xts1.cancel_order(appOrderID=OrderID,orderUniqueIdentifier='123abc',clientID=self.client_code)
AttributeError: 'Tradehull' object has no attribute 'xts1'
Order ID 6124112124933 has been canceled due to timeout.
yes this is correct,
ltp can be considered running/continuous candles close
Also can you repost the question I am bit unclear about it
@Tradehull_Imran thanks its working now, but did you find the Root cause because it is giving problem every other day ?
In bracket orders the SL order is of Trigger Type SLM.
Since its a SLM type Stoploss order, it will be still executed if price moved very fast beyond SL.
yes, For BSE segment there are some issues, we are checking the same
Hi @SUDIP_NATH
Websocket is a old method we used to get LTP,
Now we have upgraded to a easier method to fetch LTP and also some fixes were applied in historical data as well
- See this video : https://www.youtube.com/watch?v=HLiEpNZSD80
- Also apply point 1 and 2 from this thread : Learn Algo Trading with Python | Codes | Youtube Series - #706 by Tradehull_Imran