upstox / upstox-python

Official Python SDK for accessing Upstox API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

My websocket connection keeps on closing every 1 minutes.

moodid opened this issue · comments

= connection is CONNECTING

Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Key: 9Xv4qCwtS9uDndJVVtOnyw==
Sec-WebSocket-Version: 13
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits
User-Agent: Python/3.11 websockets/11.0.3
< HTTP/1.1 101 Switching Protocols
< Date: Tue, 10 Oct 2023 05:53:47 GMT
< Connection: upgrade
< Sec-WebSocket-Extensions: permessage-deflate
< Sec-WebSocket-Accept:
< Upgrade: WebSocket
< CF-Cache-Status: DYNAMIC
< Strict-Transport-Security: max-age=0; includeSubDomains
= connection is OPEN
Connection established
< PING '' [0 bytes]
PONG '' [0 bytes]
BINARY 7b 22 67 75 69 64 22 3a 20 22 73 6f 6d 65 67 75 ... 31 30 33 36 22 5d 7d 7d [497 bytes]
< BINARY 12 b7 04 0a 13 4e 53 45 5f 45 51 7c 49 4e 45 37 ... 0a 18 a4 9c 98 c1 b1 31 [10243 bytes]
< BINARY 08 01 12 be 04 0a 13 4e 53 45 5f 45 51 7c 49 4e ... 0a 18 b0 9c 98 c1 b1 31 [1736 bytes]
< BINARY 08 01 12 bd 04 0a 13 4e 53 45 5f 45 51 7c 49 4e ... 01 18 dc 9e 98 c1 b1 31 [3408 bytes]
< BINARY 08 01 12 b7 04 0a 13 4e 53 45 5f 45 51 7c 49 4e ... 01 18 88 a1 98 c1 b1 31 [4548 bytes]
< BINARY 08 01 12 b5 04 0a 13 4e 53 45 5f 45 51 7c 49 4e ... 01 18 b4 a3 98 c1 b1 31 [3443 bytes]
< BINARY 08 01 12 b1 04 0a 13 4e 53 45 5f 45 51 7c 49 4e ... 01 18 e1 a5 98 c1 b1 31 [573 bytes]
< BINARY 08 01 12 b7 04 0a 13 4e 53 45 5f 45 51 7c 49 4e ... 06 18 8d a8 98 c1 b1 31 [3975 bytes]
< BINARY 08 01 12 b5 04 0a 13 4e 53 45 5f 45 51 7c 49 4e ... 05 18 b8 aa 98 c1 b1 31 [2847 bytes]
< BINARY 08 01 12 b7 04 0a 13 4e 53 45 5f 45 51 7c 49 4e ... 02 18 e4 ac 98 c1 b1 31 [3446 bytes]
< BINARY 08 01 12 b2 04 0a 13 4e 53 45 5f 45 51 7c 49 4e ... 06 18 91 af 98 c1 b1 31 [2262 bytes]
< BINARY 08 01 12 b7 04 0a 13 4e 53 45 5f 45 51 7c 49 4e ... 07 18 bd b1 98 c1 b1 31 [6248 bytes]
< BINARY 08 01 12 b2 04 0a 13 4e 53 45 5f 45 51 7c 49 4e ... 02 18 e9 b3 98 c1 b1 31 [2873 bytes]
< BINARY 08 01 12 af 04 0a 13 4e 53 45 5f 45 51 7c 49 4e ... 03 18 94 b6 98 c1 b1 31 [1136 bytes]
< BINARY 08 01 12 b5 04 0a 13 4e 53 45 5f 45 51 7c 49 4e ... 02 18 c1 b8 98 c1 b1 31 [3423 bytes]
< BINARY 08 01 12 b7 04 0a 13 4e 53 45 5f 45 51 7c 49 4e ... 0a 18 ed ba 98 c1 b1 31 [6280 bytes]
< PING '' [0 bytes]
PONG '' [0 bytes]
< BINARY 08 01 12 b0 04 0a 13 4e 53 45 5f 45 51 7c 49 4e ... 05 18 99 bd 98 c1 b1 31 [572 bytes]
< BINARY 08 01 12 b7 04 0a 13 4e 53 45 5f 45 51 7c 49 4e ... 01 18 c5 bf 98 c1 b1 31 [3983 bytes]
< BINARY 08 01 12 b2 04 0a 13 4e 53 45 5f 45 51 7c 49 4e ... 01 18 f1 c1 98 c1 b1 31 [3977 bytes]
< BINARY 08 01 12 bd 04 0a 13 4e 53 45 5f 45 51 7c 49 4e ... 03 18 9d c4 98 c1 b1 31 [2309 bytes]
< BINARY 08 01 12 b3 04 0a 13 4e 53 45 5f 45 51 7c 49 4e ... 06 18 c9 c6 98 c1 b1 31 [1137 bytes]
< BINARY 08 01 12 b7 04 0a 13 4e 53 45 5f 45 51 7c 49 4e ... 02 18 f5 c8 98 c1 b1 31 [5702 bytes]
< BINARY 08 01 12 b3 04 0a 13 4e 53 45 5f 45 51 7c 49 4e ... 02 18 a1 cb 98 c1 b1 31 [3437 bytes]
< BINARY 08 01 12 ba 04 0a 13 4e 53 45 5f 45 51 7c 49 4e ... 01 18 cd cd 98 c1 b1 31 [2287 bytes]
< BINARY 08 01 12 b7 04 0a 13 4e 53 45 5f 45 51 7c 49 4e ... 25 18 f9 cf 98 c1 b1 31 [3989 bytes]
< BINARY 08 01 12 b3 04 0a 13 4e 53 45 5f 45 51 7c 49 4e ... 0b 18 a5 d2 98 c1 b1 31 [5699 bytes]
< BINARY 08 01 12 b3 04 0a 13 4e 53 45 5f 45 51 7c 49 4e ... 0b 18 d1 d4 98 c1 b1 31 [1727 bytes]
< BINARY 08 01 12 b7 04 0a 13 4e 53 45 5f 45 51 7c 49 4e ... 01 18 fd d6 98 c1 b1 31 [3995 bytes]
< BINARY 08 01 12 b3 04 0a 13 4e 53 45 5f 45 51 7c 49 4e ... 01 18 a8 d9 98 c1 b1 31 [2846 bytes]
< BINARY 08 01 12 b3 04 0a 13 4e 53 45 5f 45 51 7c 49 4e ... 0b 18 d5 db 98 c1 b1 31 [3998 bytes]
< BINARY 08 01 12 b0 04 0a 13 4e 53 45 5f 45 51 7c 49 4e ... 16 18 81 de 98 c1 b1 31 [1135 bytes]
< BINARY 08 01 12 b7 04 0a 13 4e 53 45 5f 45 51 7c 49 4e ... 02 18 ac e0 98 c1 b1 31 [7416 bytes]
< BINARY 08 01 12 b3 04 0a 13 4e 53 45 5f 45 51 7c 49 4e ... 01 18 d8 e2 98 c1 b1 31 [4004 bytes]
< CLOSE 1000 (OK) [2 bytes]
= connection is CLOSING
CLOSE 1000 (OK) [2 bytes]
= connection is CLOSED


ConnectionClosedOK Traceback (most recent call last)
Cell In[41], line 45
43 nest_asyncio.apply()
44 loop = asyncio.get_event_loop()
---> 45 loop.run_until_complete(fetch_market_data(dfinstrument["Join"].to_list()))
46 #except Exception as e:
47 #logger_monitor("Exception when calling Main: %s\n" % e,True)
48 #continue
49 print("Trading End")

File ~\miniconda3\Lib\site-packages\nest_asyncio.py:90, in _patch_loop..run_until_complete(self, future)
87 if not f.done():
88 raise RuntimeError(
89 'Event loop stopped before Future completed.')
---> 90 return f.result()

File ~\miniconda3\Lib\asyncio\futures.py:203, in Future.result(self)
201 self.__log_traceback = False
202 if self._exception is not None:
--> 203 raise self._exception.with_traceback(self._exception_tb)
204 return self._result

File ~\miniconda3\Lib\asyncio\tasks.py:267, in Task.__step(failed resolving arguments)
263 try:
264 if exc is None:
265 # We use the send method directly, because coroutines
266 # don't have __iter__ and __next__ methods.
--> 267 result = coro.send(None)
268 else:
269 result = coro.throw(exc)

Cell In[32], line 42, in fetch_market_data(Instrument)
40 await asyncio.sleep(60 - time() % 60)
41 else:
---> 42 message = await websocket.recv()
43 decoded_data = decode_protobuf(message)
44 # Convert the decoded data to a dictionary

File ~\miniconda3\Lib\site-packages\websockets\legacy\protocol.py:568, in WebSocketCommonProtocol.recv(self)
564 return None # type: ignore
565 else:
566 # Wait until the connection is closed to raise
567 # ConnectionClosed with the correct code and reason.
--> 568 await self.ensure_open()
570 # Pop a message from the queue.
571 message = self.messages.popleft()

File ~\miniconda3\Lib\site-packages\websockets\legacy\protocol.py:935, in WebSocketCommonProtocol.ensure_open(self)
932 return
934 if self.state is State.CLOSED:
--> 935 raise self.connection_closed_exc()
937 if self.state is State.CLOSING:
938 # If we started the closing handshake, wait for its completion to
939 # get the proper close code and reason. self.close_connection_task
940 # will complete within 4 or 5 * close_timeout after close(). The
941 # CLOSING state also occurs when failing the connection. In that
942 # case self.close_connection_task will complete even faster.
943 await asyncio.shield(self.close_connection_task)

ConnectionClosedOK: received 1000 (OK); then sent 1000 (OK)

I'm also facing the same issue.

I'm also facing the same issue.

Hi Tushark28,

Sorry my laptop crashed so could not reply did you find the solution to this issue.

@tushark28 @moodid

For prompt responses to your questions and concerns, we recommend visiting our community forum at https://community.upstox.com/. Our API experts and technical team actively participate in this forum, making it the ideal place for all inquiries related to Upstox APIs.

Thank you!