(Resolved) Dhan API calls please suggest

where should i place AMO could you pls provide an example

@saisaigraph you can add AMO flag here as:

response1 = dhan.place_order(
                    transaction_type=dhan.BUY,
                    exchange_segment=dhan.NSE,
                    product_type=dhan.INTRA,
                    order_type=dhan.LIMIT,
                    security_id=15254,
                    quantity=1,
                    price=2517.8,
                    after_market_order=True,
                    amo_Time='OPEN'
                    )

You can look at amo_Time and keep it as per your choice.

1 Like

I am also getting error with message in remarks as ‘/ by zero’ while using place_order method

code :

def place_order_entry(symbol, lots , contractType, securityId, quantity, price, after_market_order, target, stoploss):
# Your existing order placement logic here

Your existing order placement logic here

print("Placing Buy Order for symbol : " + str(symbol) + " for Contract Type : " + str(contractType) +
    " with Qty : " + str(quantity) + " in " + str(lots) +
    " lot/s at the Trigger Price : " + str(float(price) + (float(price) * 0.01)) +
    " & Entry Price : " + str(float(price)))

fundLimits = dhan.get_fund_limits()

# Check for potential division by zero
denominator = float(price) + (float(price) * 0.01)
if denominator == 0:
    print("Error: Division by zero encountered.")
    orderID = {'status': 'failure', 'remarks': {'error_code': 'RS-9005', 'message': 'Division by zero'}, 'data': ''}
else:
    amountofTrade = float(quantity) * denominator + float(150)
    print("Amount required for trade : " + str(amountofTrade))
    availBal = fundLimits['data']['availabelBalance']
    print("Available balance : " + str(availBal))
    print(quantity)
    if availBal > (amountofTrade * 2):

        print("Initiating Order!!")
        orderID = dhan.place_order(
            tag=str(target),
            security_id=securityId,
            transaction_type=dhan.BUY,
            exchange_segment=dhan.FNO,
            product_type=dhan.INTRA,
            order_type=dhan.SL,
            validity='DAY',
            quantity=quantity,
            price=float(price) + float(price * 0.01),
            trigger_price=float(price),
            after_market_order=False,
            amo_time='OPEN',
        )
    else:
        orderID = {
            'status': 'failure',
            'remarks': {'error_code': 'RS-9005',
                        'message': 'The Available balance (' + str(availBal) +
                                ') is not more than twice the Trade Amount (' + str(amountofTrade) + ')'},
            'data': []
        }

return orderID

Output :

Funds Required for executing Trade: 225
Placing Buy Order for symbol : NIFTY29-02-202422500 for Contract Type : CE with Qty : 50 in 1 lot/s at the Trigger Price : 1.53015 & Entry Price : 1.515
Amount required for trade : 226.5075
Available balance : 12063.96
50
Initiating Order!!
{‘status’: ‘failure’, ‘remarks’: {‘error_code’: ‘RS-9005’, ‘message’: ‘/ by zero’}, ‘data’: ‘’}

Please let me know what kind of calculation is going which is giving me this error please fix this provlem asap @Hardik

Hello @BhaveshMestry

Can you send the JSON payload being sent on the API? This Python code snippet is not entirely clear.

Just two remarks here which can be potential causes of issue here:

  1. Ensure securityId being passed is correct (from Security ID list for particular instrument)
  2. Nifty Options are traded at a tick size of 0.05. Trigger price and Entry price has to be 1.55 and 1.50 respectively for current values (you will have to round off here).
1 Like