this is the code can someone help me @Hardik @RahulDeshpande
from dhanhq import dhanhq
Replace with your client id and access token
client_id = ‘*****’
access_token = ‘****’
dhan = dhanhq(client_id, access_token)
def get_exchange(dhan, exchange):
if exchange == “bsc”:
return dhan.BSC
elif exchange == “mcx”:
return dhan.MCX
elif exchange == “nse”:
return dhan.NSE
def get_side(dhan, side):
if side == “buy”:
return dhan.BUY
elif side == “sell”:
return dhan.SELL
def place_fno_order(dhan, symbol, exchange, side, quantity, order_type, price):
try:
exchange_segment = get_exchange(dhan, exchange)
side = get_side(dhan, side)
order_id = dhan.place_order(
security_id=symbol, # stock id
exchange_segment=exchange_segment,
transaction_type=side,
quantity=quantity,
order_type=order_type,
product_type=dhan.INTRA, # INTRA, CNC (equity), MTF
price=price
)
print(f"Order placed successfully. Order ID: {order_id}“)
except Exception as e:
print(f"Failed to place order: {e}”)
stock = token_dict[‘NIFTY’][‘NSE’][‘SEM_SMST_SECURITY_ID’] # type: ignore
trading_symbol = get_trading_symbol_by_security_id(token_dict, stock)
print(f"Stock is buying: {stock} and symbol is {trading_symbol}")
to place order down
symbol = stock
exchange = ‘nse’
side = ‘buy’
quantity = 1
order_type = ‘market’
price = 0 # Not required for market order
instrument_type = None # Automatically determined based on order_type
expiry_date = ‘6-JUN-2024’
strike_price = 23200
Place F&O order
place_fno_order(dhan, symbol, exchange, side, quantity, order_type, price)