def super_place_order(self, security_id, exchange_segment, transaction_type, quantity,
order_type, product_type, price,
target_price=None, stop_loss_price=None, trailing_sl=0, tag=None):
try:
url = self.base_url + '/super/orders'
payload = {
"dhanClientId": self.client_id,
"transactionType": transaction_type.upper(),
"exchangeSegment": exchange_segment.upper(),
"productType": product_type.upper(),
"orderType": order_type.upper(),
"securityId": security_id,
"quantity": int(quantity),
"price": float(price),
"targetPrice": float(target_price) if target_price else None,
"stopLossPrice": float(stop_loss_price) if stop_loss_price else None,
"trailingJump": float(trailing_sl)
}
if tag:
payload["correlationId"] = tag
payload = json_dumps(payload)
response = self.session.post(url, data=payload, headers=self.header, timeout=self.timeout)
return self._parse_response(response)
except Exception as e:
logging.error('Exception in dhanhq>>super_place_order: %s', e)
return {
'status': 'failure',
'remarks': str(e),
'data': '',
}
i am trying to make function in dhanhq.py to place super order and try to integrate the same in tradehull.py with these codes.
def super_order_placement(self, tradingsymbol: str, exchange: str, quantity: int, price: float,
order_type: str, transaction_type: str, trade_type: str,
target_price: float, stop_loss_price: float, trailing_sl: float = 0) -> str:
"""
Wrapper function for Super Order placement using tradingsymbol.
Returns orderId on success else None.
"""
try:
tradingsymbol = tradingsymbol.upper()
exchange = exchange.upper()
instrument_df = self.instrument_df.copy()
# Mapping dicts
script_exchange = {
"NSE": self.Dhan.NSE, "NFO": self.Dhan.FNO, "BFO": "BSE_FNO",
"CUR": self.Dhan.CUR, "BSE": self.Dhan.BSE, "MCX": self.Dhan.MCX
}
self.order_Type = {
'LIMIT': self.Dhan.LIMIT, 'MARKET': self.Dhan.MARKET,
'STOPLIMIT': self.Dhan.SL, 'STOPMARKET': self.Dhan.SLM
}
product = {
'MIS': self.Dhan.INTRA, 'MARGIN': self.Dhan.MARGIN,
'MTF': self.Dhan.MTF, 'CO': self.Dhan.CO,
'BO': self.Dhan.BO, 'CNC': self.Dhan.CNC
}
Validity = {'DAY': "DAY", 'IOC': "IOC"}
transactiontype = {'BUY': self.Dhan.BUY, 'SELL': self.Dhan.SELL}
instrument_exchange = {
'NSE': "NSE", 'BSE': "BSE", 'NFO': 'NSE',
'BFO': 'BSE', 'MCX': 'MCX', 'CUR': 'NSE'
}
# AMO validation
# Resolve mappings
exchangeSegment = script_exchange[exchange]
product_Type = product[trade_type.upper()]
order_type = self.order_Type[order_type.upper()]
order_side = transactiontype[transaction_type.upper()]
# Security lookup
security_check = instrument_df[
((instrument_df['SEM_TRADING_SYMBOL'] == tradingsymbol) |
(instrument_df['SEM_CUSTOM_SYMBOL'] == tradingsymbol)) &
(instrument_df['SEM_EXM_EXCH_ID'] == instrument_exchange[exchange])
]
if security_check.empty:
raise Exception("Invalid Tradingsymbol provided")
security_id = security_check.iloc[-1]['SEM_SMST_SECURITY_ID']
# Call raw function
order = self.Dhan.super_place_order(
security_id=str(security_id), exchange_segment=exchangeSegment,
transaction_type=order_side, quantity=int(quantity),
order_type=order_type, product_type=product_Type, price=float(price),
target_price=target_price, stop_loss_price=stop_loss_price, trailing_sl=trailing_sl
)
if order['status'] == 'failure':
raise Exception(order)
return str(order["data"]["orderId"])
except Exception as e:
print(f"Got exception in super_order_placement as {e}")
return None
is this correct and if i am going in right direction please guide me ho to add the rest modification of superorder and cacellation , i dont know any knowledge of python but from your video i learnt alot and to make my code run fast i moved to async function with two api all this learnt from chatgpt now my algo is working fine and now i want to buil super order feature please help @Tradehull_Imran