HOW TO PLACE OPTIONS ORDERS USING KITE CONNECT with PYTHON

In this tutorial, you will learn how to place options orders using KITE Connect with Python. We will place orders for Indices like BankNifty and Nifty.

1. Placing Options Orders in Nifty 50

2. Placing Options Orders in BankNifty

It is the same for stocks or equity also. This isn’t fully automated code, we need to give expiry, apart from that everything is fine. If you want, you can modify it according to your logic.

Before you run the below code, you must generate a request token and access token, I already made a video and wrote a tutorial on it.

Please watch or read before this tutorial.

How to Connect Zerodha kite connect API with Python

Here are the sample trades, Don’t worry about rejections, Those are just because of low margins. I am sure my code will work 100%.

1. Placing Options Orders in Nifty 50

Here, we are placing nifty 50 option order. Copy the code and run it. You can give directly the strike price like 17800 and also you can mention CE / PE.

By default, it is set up as PE and strike price as current Nifty 50 Price. You can also place option order ITM ( In The Money ) or OTM ( Out Of The Money ) by adding 50 or 100 points.

def option_oder_nifty(lot = 1,strike=None,o_type='PE'):
    
        
    if strike is None:
        nfty = kite.ltp('NSE', '256265')
        nf_ltp = nfty['256265']['last_price']
        strike = int(round(nf_ltp, -2)) 
        tradingsymbol = 'NIFTY21SEP'+str(strike)+o_type #manual setup
        
    else:
        tradingsymbol = 'NIFTY21SEP'+str(strike)+o_type
        
    print(tradingsymbol)

    kite.place_order(variety='regular', exchange='NFO', tradingsymbol=tradingsymbol,
        transaction_type='SELL', quantity=str(lot*50), product='NRML', order_type='MARKET', price='NONE', validity='DAY',
        disclosed_quantity=None, trigger_price=None, squareoff=None, stoploss=None, trailing_stoploss=None, tag=None)
        
        
option_oder_nifty()

2. Placing Options Orders in BankNifty

Here, we are placing BankNifty options order. Copy the code and run it. You can give directly the strike price like 37600 and also you can mention CE / PE.

By default, it is set up as PE and strike price as current BankNifty Price. You can also place option order ITM ( In The Money ) or OTM ( Out Of The Money ) by adding 100 points.

#BNF order placement

def option_oder_bnf(lot = 1,strike=None,o_type='CE'):
        
    if strike is None:
        bnf = kite.ltp('NSE', '260105')
        bnf_ltp = bnf['260105']['last_price']

        strike = int(round(bnf_ltp, -2))-100
        
        tradingsymbol = 'BANKNIFTY21SEP'+str(strike)+o_type #manual setup
    
    else:
        tradingsymbol = 'BANKNIFTY21SEP'+str(strike)+o_type
    
    print(tradingsymbol)
    
    kite.place_order(variety='regular', exchange='NFO', tradingsymbol=tradingsymbol,
        transaction_type='SELL', quantity=str(lot*25), product='NRML', order_type='MARKET', price='NONE', validity='DAY',
        disclosed_quantity=None, trigger_price=None, squareoff=None, stoploss=None, trailing_stoploss=None, tag=None)




option_oder_bnf()

Hope This code can help you to place options orders using KITE Connect with Python. If you are facing any issues, please comment below.

Kite Connect API Official DOC: https://kite.trade/docs/pykiteconnect/v3/

Thank you, happy coding & Trading 🙂

Leave a Reply