tradx 0.8__py3-none-any.whl → 0.8.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -520,7 +520,26 @@ class interactiveEngine(InteractiveSocketClient):
520
520
  self.user_logger.info(
521
521
  f"logged out! {data}", caller="interactiveEngine.on_messagelogout"
522
522
  )
523
+ async def reconnect(self):
524
+ try:
525
+ # Initialize and connect OrderSocket_io object
526
+ self.socket = OrderSocket_io(
527
+ self.set_interactiveToken,
528
+ self.set_iuserID,
529
+ self._root,
530
+ self,
531
+ )
532
+ # Log successful login
533
+ if self.user_logger:
534
+ self.user_logger.info(
535
+ f"Login successful.", caller="interactiveEngine.reconnect"
536
+ )
523
537
 
538
+ await self.socket.connect()
539
+
540
+ except Exception as e:
541
+ if self.user_logger:
542
+ self.user_logger.error(e, caller="interactiveEngine.reconnect")
524
543
  async def on_disconnect(self) -> None:
525
544
  """
526
545
  Callback for handling disconnection events.
@@ -530,11 +549,37 @@ class interactiveEngine(InteractiveSocketClient):
530
549
  None
531
550
  """
532
551
  self.isConnected = False
552
+ if self.user_logger:
553
+ self.user_logger.info(
554
+ "Interactive Socket disconnected!",
555
+ caller="interactiveEngine.on_disconnect",
556
+ )
533
557
  current_time = datetime.now().time()
534
- if current_time.hour < 15 or (
535
- current_time.hour == 15 and current_time.minute < 12
536
- ):
537
- print("Socket Disconnected, emergency square off triggered.")
558
+ cnt: int = 0
559
+ if current_time < datetime.strptime("15:20", "%H:%M").time():
560
+ while not self.isConnected and cnt < 3:
561
+ print("Attempting to reconnect as the time is before 3:20 PM and isConnected is False for interactive Socket.")
562
+ if self.user_logger:
563
+ self.user_logger.info(
564
+ "Attempting to reconnect as the time is before 3:20 PM and isConnected is False.",
565
+ caller="interactiveEngine.on_disconnect",
566
+ )
567
+ await self.reconnect()
568
+ await asyncio.sleep(3)
569
+ cnt += 1
570
+ if not self.isConnected and self.user_logger:
571
+ print( f"Reconnection attempt {cnt} failed for interactive socket. Retrying...")
572
+ self.user_logger.warning(
573
+ f"Reconnection attempt {cnt} failed. Retrying...",
574
+ caller="interactiveEngine.on_disconnect",
575
+ )
576
+ if cnt >= 3:
577
+ if self.user_logger:
578
+ self.user_logger.error(
579
+ f"Reconnection attempts failed. Please check the network connection.",
580
+ caller="interactiveEngine.on_disconnect",
581
+ )
582
+ print("Interactive Socket reconnection failed, emergency square off triggered.")
538
583
  # Log the initiation of the liquidation process
539
584
  if self.user_logger:
540
585
  self.user_logger.info(
@@ -598,11 +643,7 @@ class interactiveEngine(InteractiveSocketClient):
598
643
  )
599
644
  )
600
645
 
601
- if self.user_logger:
602
- self.user_logger.info(
603
- "Interactive Socket disconnected!",
604
- caller="interactiveEngine.on_disconnect",
605
- )
646
+
606
647
 
607
648
  async def on_trade(self, xts_message: str) -> None:
608
649
  """
tradx/marketDataEngine.py CHANGED
@@ -148,6 +148,7 @@ class marketDataEngine(MarketDataSocketClient):
148
148
  assert api_password, "API password is required"
149
149
  assert source, "Source is required"
150
150
  assert root, "Root is required"
151
+ self.isConnected: bool = False
151
152
  self._api_key: str = api_key
152
153
  self._api_password: str = api_password
153
154
  self._source: str = source
@@ -255,13 +256,29 @@ class marketDataEngine(MarketDataSocketClient):
255
256
  Returns:
256
257
  None
257
258
  """
258
-
259
+ self.isConnected = True
259
260
  if self.user_logger:
260
261
  self.user_logger.info(
261
262
  "Market Data Socket connected successfully!",
262
263
  caller="marketDataEngine.on_connect",
263
264
  )
265
+ async def reconnect(self):
266
+ try:
267
+ # Initialize and connect OrderSocket_io object
268
+ self.socket = MDSocket_io(
269
+ self.set_marketDataToken, self.set_userID, self._root, self
270
+ )
271
+ # Log successful login
272
+ if self.user_logger:
273
+ self.user_logger.info(
274
+ f"Login successful.", caller="marketDataEngine.reconnect"
275
+ )
264
276
 
277
+ await self.socket.connect()
278
+
279
+ except Exception as e:
280
+ if self.user_logger:
281
+ self.user_logger.error(e, caller="marketDataEngine.reconnect")
265
282
  async def on_disconnect(self) -> None:
266
283
  """
267
284
  Handles the event when the market data socket gets disconnected.
@@ -271,12 +288,38 @@ class marketDataEngine(MarketDataSocketClient):
271
288
  Returns:
272
289
  None
273
290
  """
274
-
291
+ self.isConnected = False
275
292
  if self.user_logger:
276
293
  self.user_logger.info(
277
294
  "Market Data Socket disconnected!",
278
295
  caller="marketDataEngine.on_disconnect",
279
296
  )
297
+ current_time = datetime.now().time()
298
+ cnt: int = 0
299
+ if current_time < datetime.strptime("15:20", "%H:%M").time():
300
+ while not self.isConnected and cnt < 3:
301
+ print("Attempting to reconnect as the time is before 3:20 PM and isConnected is False for market data socket.")
302
+ if self.user_logger:
303
+ self.user_logger.info(
304
+ "Attempting to reconnect as the time is before 3:20 PM and isConnected is False.",
305
+ caller="marketDataEngine.on_disconnect",
306
+ )
307
+ await self.reconnect()
308
+ await asyncio.sleep(3)
309
+ cnt += 1
310
+ if not self.isConnected and self.user_logger:
311
+ print(f"Reconnection attempt {cnt} failed for market data socket. Retrying...")
312
+ self.user_logger.warning(
313
+ f"Reconnection attempt {cnt} failed. Retrying...",
314
+ caller="marketDataEngine.on_disconnect",
315
+ )
316
+ if cnt >= 3:
317
+ print("Reconnection attempts failed for market data socket. Please check the network connection.",)
318
+ if self.user_logger:
319
+ self.user_logger.error(
320
+ f"Reconnection attempts failed. Please check the network connection.",
321
+ caller="marketDataEngine.on_disconnect",
322
+ )
280
323
 
281
324
  async def on_message(self, xts_message: Any) -> None:
282
325
  """
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tradx
3
- Version: 0.8
3
+ Version: 0.8.1
4
4
  Summary: A Package Designed to simplify strategy development on package xts-api-client
5
5
  Author-email: "jatin.kumawat" <jatin.kumawat@rmoneyindia.com>
6
6
  Requires-Python: >=3.12
@@ -1,8 +1,8 @@
1
1
  tradx/__init__.py,sha256=MlWuula4lJZLPYPi4d5ZE9yoJnYWtgbZ0QsgWdWPwU0,53
2
2
  tradx/algoContainer.py,sha256=1IkVCIF_gXIby8z3pDdlVeUablh-PZVZ1EawyCB7oUs,3807
3
3
  tradx/dualHashMap.py,sha256=XsidIc3aMvpVGOvdfV7lOeZaLCWAD5i180BGyAfdYXE,1737
4
- tradx/interactiveEngine.py,sha256=ln7dT_S0HaFHA36AW5P0o6svYGSLlmBThheIhJQ6D34,38912
5
- tradx/marketDataEngine.py,sha256=Fh4nsxDiG6LfTH7XdWyRmldp8Zq1TXQH_VuGaFMpQ7Y,37783
4
+ tradx/interactiveEngine.py,sha256=EuUkHInDgb8NCEAlGWsoVXA4KtA7KYDj_42qXu4mAso,40828
5
+ tradx/marketDataEngine.py,sha256=NsMEI4tdyLxpyAP2QiKFkn2mywXxTV9yekEbcTFFk44,39994
6
6
  tradx/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
7
  tradx/baseClass/baseAlgo.py,sha256=eUfFNlTB7rwgIt8pbU3qj7SlD5jOCgpnL4jXXFJQqa8,21012
8
8
  tradx/baseClass/candleData.py,sha256=tS-iAoRGwK2xVSvrqmNZPYeB63qD53oPPHaUDfJBWkk,2947
@@ -28,6 +28,6 @@ tradx/baseClass/tradeEvent.py,sha256=djunJW5AzjeMfJZVMlrFprplB7vrYBi-mmaR1TA0MK4
28
28
  tradx/constants/holidays.py,sha256=B4ee4bPFy-gBTKN6-G68Idf1n6HxoRcx72O92zSobcE,1200
29
29
  tradx/logger/logger.py,sha256=DfrjzwYkujTq7arksNTPcQeioXnwT1xgN659blhreog,3232
30
30
  tradx/logger/logger2.py,sha256=ebJ-qqnpnCqvyx1Cz1-kGGULtkH-hfrK6UNfa0bSlH8,2654
31
- tradx-0.8.dist-info/METADATA,sha256=EhAFeqqzHVHnFMIAjFyB3rhHRLJZvDJMcKI0Jc84I98,2626
32
- tradx-0.8.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
33
- tradx-0.8.dist-info/RECORD,,
31
+ tradx-0.8.1.dist-info/METADATA,sha256=4lOHDdAjn-AupLoQHGSGrkUZ1RXfGz8fGQdUopW1FdE,2628
32
+ tradx-0.8.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
33
+ tradx-0.8.1.dist-info/RECORD,,
File without changes