Using Futures Data on BankNIFTY Golden Ratio Strategy

If you have followed here from my course of Coding an Algo Trading Bot: BankNIFTY Golden Ratio Strategy, You must have tried broker integrations following the Github Repo I had shared there.

Now, I had integrated the Golden Ratio Button in our Slack and Telegram Channels.

Problem 1:

I know I have shown in the course to use the spot for calculation of Golden Number and use that in BankNIFTY futures but here, What I was doing is taking the data purely from BankNIFTY Futures of Current Month.

Yesterday, The values derived from futures data was absurd!

             date     open      high       low    close   volume

10 2020-10-27 00:00:00+05:30 24311.0 24797.00 23894.85 24741.4 7850350
11 2020-10-28 00:00:00+05:30 23698.0 24794.25 23698.00 24620.0 1139925

As You can see here The low is 23698.00 which means someone got ruined in their AMO order and the orders really got executed at very bad price!

Right? So, to avoid this, I decided to move back to using the spot data only.

Now, Let’s come to the second part.

When we are about to get the range of the first 10 mins - What we were doing was running the program at the 10th minute taking the high and low of the symbol!

That’s it.

Now, there is two way you can get the high and low of the symbol in Kite.

Using the Kite Historical API

def p_candle(token,time_period,candle):
    starting_date=( + datetime.timedelta(days=-15)).strftime("%Y-%m-%d")
    ending_date=( + datetime.timedelta(days=1)).strftime("%Y-%m-%d")
    return zapp['open'].iloc[-1+candle],zapp['high'].iloc[-1+candle],zapp['low'].iloc[-1+candle],zapp['close'].iloc[-1+candle]

The output of zapp will be like -

10 2020-10-28 00:00:00+05:30  11922.6  11929.4  11684.85  11729.6       0
11 2020-10-29 00:00:00+05:30  11633.3  11743.9  11606.75  11670.8       0

As you can see it will read the data from last day if we do - p_open,p_high,p_low,p_close=p_candle(get_insToken(var2.upper(),"NSE"),"day",0)

Using Kite LTP Function

def get_ohlc(var2,exchange="NFO"):
    if(var2=="NIFTY"):var2="NIFTY 50"
    if(var2=="BANKNIFTY"):var2="NIFTY BANK"
        return kite.ohlc(var6)[var6]['ohlc']['open'],kite.ohlc(var6)[var6]['ohlc']['high'],kite.ohlc(var6)[var6]['ohlc']['low'],kite.ohlc(var6)[var6]['ohlc']['close']
        return kite.ohlc(var5)[var5]['ohlc']['open'],kite.ohlc(var5)[var5]['ohlc']['high'],kite.ohlc(var5)[var5]['ohlc']['low'],kite.ohlc(var5)[var5]['ohlc']['close']

Anyways, the problem is the data will not be the same from both the places. The data that comes from Kite LTP function will match with Tradingview.

Now, Zerodha runs some problem that fixes this issue at night time every night. So, We need to use the Kite’s LTP Function only.