Did everything work properly today from 9:15 to 9:20?

KamalChhirang
KamalChhirang edited February 5 in General
I encountered a very strange issue today.

Around 09:15:36, the get positions API seemed to return last_price as 0 for all my positions. “https://api.kite.trade/portfolio/positions”

Between 09:19 and 09:20, the get quote API seemed to return incorrect values which caused my function to malfunction. During the same period, the Kite Web application was also unresponsive for 10-20 seconds.


Unfortunately, I could not log the data that the Kite API returned. I only log the results when I get an error from the Kite API (such as timeout). But this was not an error, the results were probably returned and they were wrong. I have been using the Kite API for 3 years, and this has never happened to me before. I either get an error or the results returned are accurate. But not today


I am 90% confident that these problems were caused by some issue in the Kite API. 10%, maybe there was some bug in my code. If something went wrong with the Kite API, maybe other users also experienced some trouble or you recorded some errors on your end.


@HowUTrade you are also a power user, did you face any problems today?



Tagged:
  • KamalChhirang
    I am consistently getting this response when fetching prices at least one time between 09:15 to 09:16 in last 4-5 trading days. Please fix it @rakeshr @sujith

    504 Gateway Time-out

    The server didn't respond in time.
  • sujith
    @KamalChhirang,
    Is this Quote or LTP API?
  • KamalChhirang
    KamalChhirang edited February 6
    Quote API. @sujith

    My code froze for a few seconds because of this, which messed up a lot of things today.

    Today, I added a timeout to the code (HTTP API). What value of timeout is good? I am using 0.8 seconds, but it also seems too much. Usually, Kite API takes 0.2 seconds with 700 symbols. But during peak hours, it also takes more time like 0.4, 0.6 seconds.

    I am using 0.8 seconds for quote API with 700 symbols

    and 0.4 second timeout for calls like get Holding, get Positions, getMaring etc.
  • Bharathi352
    I am also getting 504 error from past 2 days between 9:15 to 9:20 AM .

    Error :
    quote3 = kite.quote(inst3)
    File "/home/ubuntu/python_env_v/lib/python3.10/site-packages/kiteconnect/connect.py", line 581, in quote
    data = self._get("market.quote", params={"i": ins})
    File "/home/ubuntu/python_env_v/lib/python3.10/site-packages/kiteconnect/connect.py", line 851, in _get
    return self._request(route, "GET", url_args=url_args, params=params, is_json=is_json)
    File "/home/ubuntu/python_env_v/lib/python3.10/site-packages/kiteconnect/connect.py", line 916, in _request
    raise ex.DataException("Couldn't parse the JSON response received from the server: {content}".format(
    kiteconnect.exceptions.DataException: Couldn't parse the JSON response received from the server: b"

    504 Gateway Time-out

    \nThe server didn't respond in time.\n\n"
  • sujith
    We have informed the team to take a look at this.
  • msjai003
    I also encounter the similar problem - NFO:NIFTY24FEBFUT Failed : Request failed (kt-quotes).
  • MAG
    For those complaining about 504 errors, I assume you trying to make the kite.quote API call again and again multiple times in a continuous loop. Is that right?
  • KamalChhirang
    KamalChhirang edited February 7
    @MAG Hmmm, kinda. I have multiple scripts running, so yeah, making a lot of kite.quote API calls again and again. Is this the reason for the error? Is it related to IP address or Kite API? I mean, I have subscription to 7 Kite APIs, but only use 1 IP address (on GCP). If it is related to API, I can use a queue and use all 7 APIs to make calls one by one. So 1 API doesn't make too many calls in 1 minute. If it is related to IP address, I guess I have to reduce the amount of calls somehow or use two different GCP servers.

    I am not using WebSocket, because there is a chance it disconnects and I cannot afford to fetch outdated prices. Also, I don't know why, but websocket is slower than the quote API to me. I compared the speed using the timestamp provided in the quote data. I know quote is just a snapshot of websocket data, but maybe I am unable to implement it properly. If I compare the timestamp of 500 scripts in quote vs websocket prices. The timestamp is same in some companies and in some companies quote data has more recent timestamp. There is no example of how to properly save prices inside on_ticks function in Python. I use thread to save them.
  • MAG
    There are multiple things here which i need to go over one by one so I will give a proper detailed response later in the day after market close.
  • Rini
    call to kite.holdings() failing consistently today.
  • sujith
    @Rini,
    Can you create a new thread with complete debug logs? We will check and get back to you.
  • sujith
    @KamalChhirang,
    You can check the example[Kite Connect example to receive and store tick in database async] here for Websocket API usage. Might be old example but I hope you can get the gist of it.
  • msjai003
    NSE:NIFTY BANK Failed : HTTPSConnectionPool(host='api.kite.trade', port=443): Read timed out. (read timeout=7)
    NSE:NIFTY BANK Failed : HTTPSConnectionPool(host='api.kite.trade', port=443): Max retries exceeded with url: /quote/ltp?i=NSE%3ANIFTY+BANK (Caused by NewConnectionError(': Failed to establish a new connection: [Errno
    11001] getaddrinfo failed'))
  • KamalChhirang
    KamalChhirang edited February 7
    @sujith Please try to run this simple code once. It compares the timestamp of quote vs websocket, and quote wins everytime.

    I am not updating a database, but updating a global variable. It is supposed to be equally fast or faster, I assume.

    Not even once socket was faster for even a single tick.

    Websocket vs Quote speed compare code

    Here are the results on my GCP VM:
    Round 1 :  Counter({'draw': 48, 'quoteIsFaster': 31})
    Round 2 : Counter({'draw': 60, 'quoteIsFaster': 19})
    Round 3 : Counter({'quoteIsFaster': 47, 'draw': 32})
    Round 4 : Counter({'draw': 40, 'quoteIsFaster': 39})
    Round 5 : Counter({'draw': 53, 'quoteIsFaster': 26})
    Round 6 : Counter({'quoteIsFaster': 45, 'draw': 34})
    Round 7 : Counter({'draw': 43, 'quoteIsFaster': 36})
    Round 8 : Counter({'quoteIsFaster': 43, 'draw': 36})
    Round 9 : Counter({'quoteIsFaster': 58, 'draw': 21})
    Round 10 : Counter({'draw': 41, 'quoteIsFaster': 38})
  • ANL
    @KamalChhirang WebSocket is faster than any API. As you know, the Quote API is just a snap of WebSocket streaming. You can connect WebSocket with a simple dictionary and then fetch the live updates. Don't put any heavy computations inside the on_ticks; it will lag the performance. If you manage these setups efficiently, then you can manage everything without any errors. I have been doing this for many months, and I have not gotten any errors. The APIs are heavily loaded, except WebSocket. My entire program is based only on WebSocket.
  • ANL
    in addition+
    Hmmm, kinda. I have multiple scripts running, so yeah, making a lot of kite.quote API calls again and again. Is this the reason for the error? Is it related to IP address or Kite API? I mean, I have subscription to 7 Kite APIs, but only use 1 IP address (on GCP). If it is related to API, I can use a queue and use all 7 APIs to make calls one by one. So 1 API doesn't make too many calls in 1 minute. If it is related to IP address, I guess I have to reduce the amount of calls somehow or use two different GCP servers.
    If you are using multiple API apps for calling the kite.quote API or Rest API, then it will not be sufficient for your entire work. You can use only one API app to connect with one efficient database and fetch data as quickly as possible for your entire program.
Sign In or Register to comment.