No ATM option tick feed from websocket for couple of minutes.

aditya_chauhan
Today on 21st june, at 9:17:58, Bank nifty index was around 33400. I had subscribed Option symbols: BANKNIFTY21JUN34000CE and BANKNIFTY21JUN34000PE along with other 15-20 symbols. I didn't receive at the money option tick data for couple of minutes. It's highly unlikely that there was no change in the LTP.

Below dictionary has the key as time and value has the duration for which mentioned tick data was absent

BANKNIFTY21JUN34000CE tick absence: {'09:17:58': '0:02:40', '09:21:12': '0:02:51', '09:29:26': '0:04:25', '10:47:37': '0:06:19', '13:04:17': '0:08:23'}
BANKNIFTY21JUN34000PE tick absence : {'09:15:43': '0:00:25', '09:16:38': '0:00:44', '09:36:09': '0:01:00', '10:08:31': '0:01:10'}

We can see at 9:17:58, there was no BANKNIFTY21JUN34000CE tick received for 2 minutes and 40 seconds. There have been multiple such instances.

I am also attaching today's websocket feed data which i have stored it. You can cross check the absent tick data.

A lot can happen in 2 minutes and 40 second. Any idea why this happened?
Is it because of other 15-20 symbols i had subscribed? If yes, can i create two different KiteTicker/websocket connection with same APIkey and generated access_token for the day?

Tagged:
  • rakeshr
    I had subscribed Option symbols: BANKNIFTY21JUN34000CE and BANKNIFTY21JUN34000PE along with other 15-20 symbols. I didn't receive at the money option tick data for couple of minutes.
    We just checked chart historical data, which too uses the same WebSocket streaming to form candles. OHLCV value for the above-mentioned period(09:17 - 09:21) for BANKNIFTY21JUN34000CE, are showing fine.
    2021-06-21 09:17:00+05:30,403.05,403.65,375.65,394.05,218850
    2021-06-21 09:18:00+05:30, 394.15, 410.9, 386.35, 407.5, 227100
    2021-06-21 09:19:00+05:30, 402.15, 421.9, 399.1, 416.7, 265500
    2021-06-21 09:20:00+05:30, 416.65, 455.6, 393.7, 433.2, 294000
    2021-06-21 09:21:00+05:30, 434.35, 448.45, 424.25, 447.85, 158600
    You need to check, if there was websocket dis-connection for the mentioned period at your end or you are performing any thread block computation inside on_tick thread.
  • aditya_chauhan
    There was no websocket dis-connection and it was running on google cloud. I am not performing any computation inside on_tick thread. I am storing the tick data in Deque buffers first. Any processing i am doing on these buffers.

    kws =KiteTicker(api_key,access_token, debug=False, root=None, reconnect=True, reconnect_max_tries=300, reconnect_max_delay=60, connect_timeout=30)
    kws.on_ticks=read_from_socket_to_buffer
    kws.on_connect = on_connect
    kws.connect(threaded=True)


    def read_from_socket_to_buffer(ws,message):
    global file_buffer, fast_buffer, hot_buffer # deque buffers from python Collections module
    message1={}
    message1['timestamp']=message[0]['timestamp']
    message1['instrument_token'] = message[0]['instrument_token']
    message1['last_price'] = message[0]['last_price']
    message1['local_sys_time'] = time.ctime() # appending local system time
    message1['symbol']=get_symbol_by_instrument_token(message[0]['instrument_token'])
    #print(message1)
    file_buffer.appendleft(message1)
    fast_buffer.appendleft(message1)
    hot_buffer.appendleft(message1)

    def get_symbol_by_instrument_token(token):
    global token_dict
    return token_dict[token]
  • aditya_chauhan
    9:17:58 is the time when latest tick arrived after 2 minute, 40 seconds. Can you please check the previous 1 minute candles?
  • rakeshr
    9:17:58 is the time when latest tick arrived after 2 minute, 40 seconds. Can you please check the previous 1 minute candles?
    We have checked all minute candles from 09:15 - 09:20. All are showing fine.
    Date, open, High, Low, close, volume
    2021-06-21 09:15:00+05:30, 450, 450, 380.9, 428.9, 241800
    2021-06-21 09:16:00+05:30, 410.2, 422.95, 378.75, 400.2, 210150
    2021-06-21 09:17:00+05:30, 403.05, 403.65, 375.65, 394.05, 218850
    2021-06-21 09:18:00+05:30, 394.15, 410.9, 386.35, 407.5, 227100
    2021-06-21 09:19:00+05:30, 402.15, 421.9, 399.1, 416.7, 265500
    2021-06-21 09:20:00+05:30, 416.65, 455.6, 393.7, 433.2, 294000
  • aditya_chauhan
    @rakeshr Thank you for the quick response. Can you please look at function coded in on_tick thread? Even today(22nd June), I didn't get BANKNIFTY21JUN35100PE tick data for 4 minutes at 9:30.

    This has been happening consistently. I am trading short straddle, where one of the contract LTP doesn't update for 4 minutes and hence there is huge difference between expected profit/loss versus realized profit/loss.


    With one API subscription, is it possible to create two KiteTicker instances on same PC. I am planning to use one ticker for traded two option contract tick and another ticker for storing 100s of banknifty option contracts tick.

  • sujith
    @aditya_chauhan,
    It could be because you are blocking the main thread where ticks are received.
    You can use three websocket connections per api_key.
  • anshuanshu333
    @aditya_chauhan , @sujith can you share code to get the options data for NIFTY and BankNIFTY, i am new to kite connect
  • aditya_chauhan
    @sujith

    I have written a code where i have subscribed 20 above & below banknifty weekly contracts w.r.t. Bank nifty index . I am not doing any calculation in the main thread.
    I have subscribed total 20(this week)+20(next week)+20(next to next week)=60 bank nifty option symbols.

    I am still seeing 4-5 option data every second.



    I am also attaching my code for your reference.
  • sujith
    We don't send ticks for all instruments every second. We send it only when there is a change.
    You can check out FAQs about websockets here.
  • aditya_chauhan
    Here is the python code which i am using to collect the data.
  • Alogji
    Alogji edited June 2021
    this issue happens with me too.
  • aditya_chauhan
    @sujith ,

    out of these 60 subscribed option contracts, 10 will be ATM or near otm and their LTP is most likely to change every second. I am consistently getting at the max 5 ticks every second.
  • sujith
    @aditya_chauhan,
    Please read the FAQs here to know more about the Websocket API behavior.
  • aditya_chauhan
    @sujith Thanks for your prompt reply. I have gone through the websocket related FAQs multiple times and the issue, which i have been facing, has not been discussed as of now.


    Today(25th June), I had subscribed BANKNIFTY2170135100CE and at 11:07:25, I didn't received any ticks for next 1 minute 2 seconds. At that time, Bank nifty index was 35020. It's hard to believe that LTP didn't change for 1 minute as this was ATM option contract.

    Following your recommendation,
    1. I don't do any computation in on_tick thread.
    2. Script was running on Mumbai based google cloud and websocket was not disconnected as I was receiving other option contract tick data.
    3. No computation in main thread.

    If you look at the previous comments, @rakeshr said that candle closed perfectly for him but not for me. Even after following your recommendation, traded tick is not coming for couple of minutes. I understand super OTM contract's price may not change for couple of minutes but this should not be the case with ATM option contracts.

    What is the solution?

    I have already attached full script [data_collection.rar] which I am using to store the tick data. You can find the script's main content below.

    #main function starts here.

    global u
    #login
    name_file_to_be_read="Data_collection" #data will be stored in this file
    api_key = api_key_value()
    access_token = access_token_value()
    u = KiteConnect(api_key=api_key)
    u.set_access_token(access_token)
    get_master_contract()
    print(INITIAL_BANKNIFTY_LTP())
    bank_nifty_subscription_list = BANKNIFTY_sub_symbol_list(20) # list of option contracts subscribed.

    for symbol_to_be_subscribed in bank_nifty_subscription_list:
    token_list_for_subscription.append(get_instrument_by_symbol('NFO', symbol_to_be_subscribed))

    # token_list_for_subscription will be passed to websocket to start streaming these ticks
    token_list_for_subscription.append(get_instrument_by_symbol('NSE', 'NIFTY BANK'))
    token_list_for_subscription.append(get_instrument_by_symbol('NSE', 'INDIA VIX'))

    # Parallel thread which will pop the data from deque buffer and write it in a file.
    t1 = Thread(target=write_to_file_from_file_buffer, args=(name_file_to_be_read + '.txt',))
    t2 = Thread(target=write_raw_data_to_file_from_fast_buffer, args=(name_file_to_be_read + '_raw.txt',))
    t1.start()
    t2.start()
    kws_data = KiteTicker(api_key, access_token, debug=False, root=None, reconnect=True, reconnect_max_tries=300, reconnect_max_delay=60, connect_timeout=30)
    # reconnection is enabled, it will start reconnecting at 2s,4s,8s,16s,32s,60s,60s till 300 times. each trial is timeout after 30s of connection attempt
    kws_data.on_ticks = read_from_socket_to_buffer
    kws_data.on_connect = on_connect
    kws_data.connect(threaded=True)

    kws_data.connect()

    # main function ends here
  • rakeshr
    As, said above the WebSocket ticker is working absolutely fine, and historical data based on these are showing the same. We can't assist with your code as it is outside the scope of KiteConnect.
    Today(25th June), I had subscribed BANKNIFTY2170135100CE and at 11:07:25, I didn't received any ticks for next 1 minute 2 seconds
    {'date': datetime.datetime(2021, 6, 25, 11, 6, tzinfo=tzoffset(None, 19800)), 
    'open': 337.3, 'high': 340.65, 'low': 335.8, 'close': 336, 'volume': 9250}
    {'date': datetime.datetime(2021, 6, 25, 11, 7, tzinfo=tzoffset(None, 19800)),
    'open': 336.15, 'high': 341.95, 'low': 331.8, 'close': 340.95, 'volume': 15675}
    {'date': datetime.datetime(2021, 6, 25, 11, 8, tzinfo=tzoffset(None, 19800)),
    'open': 342, 'high': 345, 'low': 339.4, 'close': 341.75, 'volume': 23350}
Sign In or Register to comment.