NFO:NIFTY24MAY22400PE HTTPSConnectionPool(host='api.kite.trade', port=443): Read timed out. (read ti

shrixyz
NFO:NIFTY24MAY22400PE HTTPSConnectionPool(host='api.kite.trade', port=443): Read timed out. (read timeout=40)
I am using the : 'kite.ltp' to get price for a symbol

I am getting this error so frequently that it prevents any processing.

I tried ping to the 'api.kite.trade' server and i got:
ping api.kite.trade

Pinging api.kite.trade [2606:4700:8d73:3271:7bd7:b45:6810:2132] with 32 bytes of data:
Reply from 2606:4700:8d73:3271:7bd7:b45:6810:2132: time=59ms
Request timed out.
Request timed out.
Request timed out.

Ping statistics for 2606:4700:8d73:3271:7bd7:b45:6810:2132:
Packets: Sent = 4, Received = 1, Lost = 3 (75% loss),
Approximate round trip times in milli-seconds:
Minimum = 59ms, Maximum = 59ms, Average = 59ms

Please suggest a solution.
Thanks
Shridhar
Tagged:
  • sujith
    How often do you call this endpoint?
  • shrixyz
    10 calls after every 6 seconds. It has always been fine and this has started very recently. I think the ping statistics is relevant, packets are lost and time taken is 59ms which is quite high. Ping to google.com resulted in no packets lost and 6ms time.
  • shrixyz
    I tried tracert to api;kite.trade and to google.com:

    tracert api.kite.trade

    Tracing route to api.kite.trade [2606:4700:8d73:3271:7bd7:5d:6810:2132]
    over a maximum of 30 hops:

    1 2 ms 1 ms 1 ms 2405:201:1e:b831:6a14:1ff:fe19:eaf6
    2 * * * Request timed out.
    3 4 ms 3 ms 3 ms 2405:203:400:100:172:31:0:238
    4 * 14 ms 22 ms 2400:cb00:202:3::a29e:e27a
    5 31 ms 8 ms * 2400:cb00:202:3::a29e:e27a
    6 5 ms 5 ms 7 ms 2400:cb00:579:3::
    7 48 ms 12 ms 44 ms 2606:4700:8d73:3271:7bd7:5d:6810:2132

    tracert google.com

    Tracing route to google.com [2404:6800:4009:826::200e]
    over a maximum of 30 hops:

    1 2 ms 1 ms 1 ms 2405:201:1e:b831:6a14:1ff:fe19:eaf6
    2 * * * Request timed out.
    3 5 ms 3 ms 4 ms 2405:203:400:100:172:31:0:238
    4 8 ms * 5 ms 2001:4860:1:1::3c8
    5 6 ms 6 ms 7 ms 2404:6800:80b3::1
    6 6 ms 5 ms 5 ms 2001:4860:0:1::17d2
    7 4 ms 5 ms 6 ms 2001:4860:0:1::8710
    8 6 ms 7 ms 5 ms 2001:4860:0:1::3fe5
    9 6 ms 6 ms 4 ms 2001:4860:0:1::547f
  • sujith
    Maybe you are getting blocked by cloudflare, if that is your frequency then better to use Websocket API.
  • shrixyz
    I also noticed, when these errors occur, Kite web too fails to update chart. Example : if i want to change from Nifty to Banknifty chart, then Kite web takes a long time to bring up the chart.
    I have the code running for many years now. I cant modify it to websocket api.
  • shrixyz
    I tried Websockets, the ltp call returned:
    b'\x00\x01\x00\x08\x00\r\x80\x01\x00\x01h\x8c'
    I referred to Kite Websocket documentation, it says: LTP. Packet contains only the last traded price (8 bytes).
    But, i am unable to extract ltp from the bytearray.

    Could you please advise how i can get ltp from it. Any code/documentation will be helpful.
  • rakeshr
    b'\x00\x01\x00\x08\x00\r\x80\x01\x00\x01h\x8c'
    These are binary data. You can use any of our official client's websocket streams.
  • shrixyz
    I had been using kite to get ltp. But it keeps timing out, hence i was advised to use sockets. If you could just guide me about the bytestream structure for 'ltp' that would be great. Example bytestream: :b'\x00\x01\x00\x08\x00\r\x80\x01\x00\x01h\x8c'
  • sujith
    You can know more about packet structure here.
  • sujith
    If you want to reinvent the parsing bit that is already there then you can view ticker code of pykiteconnect.
  • shrixyz
    Thanks, got it. Below is my code snippet in case some user needs it.

    rmessage = b'\x00\x01\x00\x08\x00\x03\xe9\t\x00#`r'
    b_id = rmessage[-7:-4]
    b_ltp = rmessage[-3:]
    id = (int.from_bytes(b_id, byteorder='big'))
    ltp = (int.from_bytes(b_ltp, byteorder='big') / 100)
    print(id, ltp)

    Output: 256265 23184.5
Sign In or Register to comment.