Super weird issue.

AAAAAAAAAA
AAAAAAAAAA edited May 2022 in General
I don't even know how to describe this.

Up until now everything was fine, except for super rare kite.positions() timeout error.
However, today that same thing happened again. My entire log is filled with
"
09:17:32 caught get_positions exception

09:17:32HTTPSConnectionPool(host='api.kite.trade', port=443): Read timed out. (read timeout=7) "

error. I am also giving the time out of 5 seconds for whenever an error arises. Here is the code for get_positions()



This is point number 1.

Point 2.

My algo hit the point to buy a position and it even got in the function that houses kite.place_order() method. However, the order was not placed (I had enough margins and everything. I have some print() statements there too and NONE were printed on the console). And instead of logging the error, my code kept on running. No error was reported on the console or in the logs. The only issue was the continuity of the get_positions() exception errors. This is super puzzling to me. How could the algo enter the function AND exit without implementing the API AND not reporting any error? This had happened to me 1 month ago as well, and then repeating only today. Back then, there was also get_positions() issue.

This is very mysterious. My algo, despite running was blind to all the entry positions after 10:15 am, and so no new positions were taken. But as I said, there were no errors reported. There were no changes made to the algo recently and it was running fine. There were no issues yesterday as well.

Please help.

Please note, as per @sujith and @rakeshr suggestions, I am not polling kite.positions(). I only call this once at the very beginning and then AFTER kite.place_order().
  • SRIJAN
    1. There is no issue with positions api. I also fetched it multiple times yesterday, without any error even once.

    2. If the print statements did not execute,then for sure that code block was not executed,so the order placement code also did not trigger.
    You have to check your program.
  • sujith
    @AAAAAAAAAA,
    You may run with debug logs on and see the complete request and response flow with your print statements.

    If you keep polling positions, CDN might think you are spamming so it might be blocking your request or it could be your network issue.
  • AAAAAAAAAA
    AAAAAAAAAA edited May 2022
    @sujith @rakeshr I havent been polling kite.positions() for past 2-3 months now. Only call it once at the beginning and after an order is placed. As I mentioned, this has shown results, however, there are occasions, though rare, when it acts up and throws the error left and right.

    In my previous post you commented it could be a connection pool issue (at the very bottom here https://kite.trade/forum/discussion/11011/error-httpsconnectionpool-host-api-kite-trade-port-443-read-timed-out-read-timeout-7#latest) and I dug further into it and ultimately came up with three possibilities:

    1. Connection pool issue: You suggested to have a custom pool session via requests.Sessions(). Haven't tried it yet but I'll let you know how it goes when I do.
    2. Default timer: After searching the error (Read Timed Out), several posts mentioned that the error is propped up when a connection is made but client has not yet received a response from the server in a set duration. They recommended this command: sudo pip install --default-timeout=100 future, as per https://stackoverflow.com/questions/43298872/how-to-solve-readtimeouterror-httpsconnectionpoolhost-pypi-python-org-port.
    3. Another thing could be the margins function call. I call this function right before kite.place_order() to check whether I have enough margins for the trade. Until yesterday I did not have a try except block on it and it is possible that this API was not working and that resulted in the print statements not getting printed and skipping the function entirely, as the print statements are getting printed above the margins check. Let's see if this helps.

    What do you make of points 1 and 2 though?

    Even though this error does happen that much these days, when it does it is still a big issue because of all the missed entries and exists resulting in damage, as I am sure you can imagine. Please help.
  • sujith
    We see 7-10K requests from your id everyday and we don't see any issue. Everything is 200, maybe try with alternate network.
  • AAAAAAAAAA
    AAAAAAAAAA edited May 2022
    Whats 200?
    7-10k requests in what context? Is it orders? That averages at about 30-70.

    Or are you talking about the number of times on_ticks() method is called? If thats what you say, then yes, but thats only because I have set get_positions() to pass incase of an error. The algo (when these errors happen) mostly remains non-functional. Today it worked as expected, but occasionally it will act up.

    My log from 17 May looks like this:

    Errors all the way. The console still showed the algo to be running, but just printed out this error and did not work.


  • SRIJAN
    SRIJAN edited May 2022
    @AAAAAAAAAA ,

    code 200 means the request was successful.
    7-10k requests/ day means all the HTTP requests combined(GET+POST+PUT+DELETE).
  • sujith
    @AAAAAAAAAA,
    I was referring to number of times get positions API is called everyday by your app.
  • AAAAAAAAAA
    @sujith Thanks for letting me know. I just reviewed the code and it turns out I had mistakenly put get_positions() such that it was getting called with every tick! Yeah, no wonder I got the walls of errors. The requests should dramatically reduce now.
    May I ask in 3-4 days how many positions request my code throws then? Much thanks!
  • AAAAAAAAAA
    @sujith Could you please verify that the number of positions request sent now is less than 100? Thanks so much.
Sign In or Register to comment.