Two order with single if condition issue

samnpti




Samir, [2/20/2022 3:51 PM]
while True:

try:


if (LTP_New < 1000.00) and (FUT_BUY not in traded_list):
FUTBUY_EXIT = kite.place_order(variety=kite.VARIETY_AMO,
tradingsymbol=FUT_BUY,
exchange=kite.EXCHANGE_NFO,
transaction_type=kite.TRANSACTION_TYPE_SELL,
quantity=lot_Buy,
# price=futlong_ask_exit,
order_type=kite.ORDER_TYPE_MARKET,
product=kite.PRODUCT_NRML)
print("FUT_BUY_EXIT",FUTBUY_EXIT)
traded_list.append(FUT_BUY)

PUTBUY_EXIT = kite.place_order(variety=kite.VARIETY_AMO,
tradingsymbol=PUT_BUY,
exchange=kite.EXCHANGE_NFO,
transaction_type=kite.TRANSACTION_TYPE_SELL,
quantity=lot_Buy,
# price=futlong_ask_exit,
order_type=kite.ORDER_TYPE_MARKET,
product=kite.PRODUCT_NRML)


print("PUT_BUY_EXIT",PUTBUY_EXIT)
traded_list.append(PUT_BUY)


except Exception as e:
continue


Only one order is getting executed not the 2nd one.how to resolve ..
  • SRIJAN
    I guess when you are using try-except block ,you can print the exception. Do that and you will know the problem.
  • CARahulPatel
    As a alternative, you can define order placing logic and than pass necessary parameter for better execution of order. here you go

    def place_order(variety, exchange, trading_symbol, transaction_type, product=None, quantity=None, order_type=None, price=None, trigger_price=None, square_off=None, stop_loss=None, disclosed_quantity=None):

    try:
    order_id = kite.place_order(variety=variety, exchange=exchange, tradingsymbol=trading_symbol, transaction_type=transaction_type, product=product,
    quantity=quantity, order_type=order_type, price=price, trigger_price=trigger_price, squareoff=square_off, stoploss=stop_loss, disclosed_quantity=disclosed_quantity, validity='DAY')
    return order_id
    except Exception as e:
    print("\nCould not place the order during the 1st time because of the following reason: \n" + "'" + str(e) + "'")
    sleep(1)
    try:
    order_id = kite.place_order(variety=variety, exchange=exchange, tradingsymbol=trading_symbol, transaction_type=transaction_type, product=product,
    quantity=quantity, order_type=order_type, price=price, trigger_price=trigger_price, squareoff=square_off, stoploss=stop_loss, disclosed_quantity=disclosed_quantity, validity='DAY')
    return order_id
    except Exception as e:
    print("\nCould not place the order during the 2nd time because of the following reason: \n" + "'" + str(e) + "'")
    sleep(2)
    try:
    order_id = kite.place_order(variety=variety, exchange=exchange, tradingsymbol=trading_symbol, transaction_type=transaction_type, product=product,
    quantity=quantity, order_type=order_type, price=price, trigger_price=trigger_price, squareoff=square_off, stoploss=stop_loss, disclosed_quantity=disclosed_quantity, validity='DAY')
    return order_id
    except Exception as e:
    print("\nCould not place the order during the 3rd and the last time because of the following reason: \n" + "'" + str(e) + "'")
    print("\nSomething seems to be wrong, please check.")

    and placing order you can use

    call_order_id = place_order(variety='regular', exchange=exchange, trading_symbol=call_option_name, transaction_type='BUY', product='MIS', quantity=quantity, order_type='LIMIT', price = 1000)
Sign In or Register to comment.