ReadTimeoutError just after the market start!

mdalvi
2019-02-04 09:15:12,280 __main__ CRITICAL ReadTimeout(ReadTimeoutError("HTTPSConnectionPool(host='api.kite.trade', port=443): Read timed out. (read timeout=7)"))
Let me know what is supposed to be done so I could continue in 'exception' block!
except ReadTimeout:
?
Is re-instantiation of kite object a way to go? Also, what'sup with the error?
  • rakeshr
    rakeshr edited July 8
    @mdalvi
    We are already looking to timeout error.For time being you can handle timeout exception in your code.
    from requests.exceptions import ReadTimeout
    except ReadTimeout:
    pass
  • mdalvi
    mdalvi edited February 2019
    from kiteconnect import KiteConnect
    from requests.exceptions import ReadTimeout


    class Kite(object):
    def __init__(self, **kite_credentials):
    self.kite = KiteConnect(**kite_credentials, debug=True)

    def exec(self, func_name, **kwargs):

    while True:
    try:
    return getattr(self.kite, func_name)(**kwargs)
    except ReadTimeout:
    pass
    is this an acceptable approach?
  • rakeshr
    @mdalvi
    Yeah, this is correct.
  • Srik
    I got the same issue on June 14th. Is this issue fixed or we still need to go with the same workaround?
  • rakeshr
    @Srik
    I got the same issue on June 14th. Is this issue fixed or we still need to go with the same workaround?
    In which of the APIs request, did you got TimeoutError?
  • Srik
    I’m getting this on order_history. I got it even today. Connection is getting disconnected often because of this.
  • Srik
    Traceback (most recent call
    order = pyTrade.order_history(order_id=stockCtx['orderId'])
    File "build\bdist.win-amd64\egg\kiteconnect\connect.py", line 387, in order_history

    File "build\bdist.win-amd64\egg\kiteconnect\connect.py", line 697, in _get

    File "build\bdist.win-amd64\egg\kiteconnect\connect.py", line 745, in _request

    requests.exceptions.ConnectionError: HTTPSConnectionPool(host='api.kite.trade', port=443): Read timed out.
  • rakeshr
    @Srik
    We checked for multiple order_history API response at our end, not able to reproduce Timeout exception at any instance. Make sure that you have added proper delay between multiple API calls.
  • Srik
    I’m calling this API once in a tick. Is it ok?
  • sujith
    We don't recommend polling API for listening to the status of an order. You can use postbacks API or order updates on the websockets.
  • Srik
    Can you please point to an example for post back and web socket methods for getting the order status?
  • Srik
    Srik edited June 2019
    In the websocket call back on_order_update(ws,data), argument data is same as that of order_history return value? I mean the structure.
  • sujith
    You will receive a payload same as the postback response. You can check out the documentation here.
  • Srik
    Whether the data will be of the order whose status is changed or entire day’s orders.
  • Srik
    Also I see that I don’t get the call back posted after reconnection if the state changed during disconnection time. How to handle this.
  • rakeshr
    rakeshr edited June 2019
    @Srik
    Whether the data will be of the order whose status is changed or entire day’s orders
    .
    It's only for the order whose order_status is changed, while WebSocket code is running.
    Also I see that I don’t get the call back posted after reconnection if the state changed during disconnection time. How to handle this.
    Post back status is received only for orders whose status is changed during your WebSocket code running.
    In case of disconnection, once you reconnect, you can fetch complete orderbook once and check change status for required order, check the documentation here.
  • harshtock
    @rakeshr

    is this error same as above ReadTimeout? is the same exception to be used for this (except ReadTimeout)?
    Traceback (most recent call last):
    File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 421, in _make_request
    six.raise_from(e, None)
    File "<string>", line 3, in raise_from
    File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 416, in _make_request
    httplib_response = conn.getresponse()
    File "/usr/lib64/python3.6/http/client.py", line 1354, in getresponse
    response.begin()
    File "/usr/lib64/python3.6/http/client.py", line 307, in begin
    version, status, reason = self._read_status()
    File "/usr/lib64/python3.6/http/client.py", line 268, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
    File "/usr/lib64/python3.6/socket.py", line 586, in readinto
    return self._sock.recv_into(b)
    File "/usr/local/lib/python3.6/site-packages/urllib3/contrib/pyopenssl.py", line 326, in recv_into
    raise timeout("The read operation timed out")
    socket.timeout: The read operation timed out
  • rakeshr
    @harshtock
    socket.timeout: The read operation timed out
    No, this is socket timeout, earlier one is requests Timeout. You can use something as below to handle socket timeout.
    import socket
    try:
    ....
    except socket.timeout:
    ...
Sign In or Register to comment.