tradx 0.7.13__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.
tradx/interactiveEngine.py
CHANGED
@@ -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
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
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
|
-
|
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
|
@@ -167,6 +168,10 @@ class marketDataEngine(MarketDataSocketClient):
|
|
167
168
|
caller="marketDataEngine.__init__",
|
168
169
|
)
|
169
170
|
|
171
|
+
async def on_event_instrument_change_partial(self, data):
|
172
|
+
"""On receiving message code 1105:Instrument Change partial"""
|
173
|
+
return
|
174
|
+
|
170
175
|
async def initialize(self) -> None:
|
171
176
|
"""
|
172
177
|
Asynchronously initializes the market data engine.
|
@@ -251,13 +256,29 @@ class marketDataEngine(MarketDataSocketClient):
|
|
251
256
|
Returns:
|
252
257
|
None
|
253
258
|
"""
|
254
|
-
|
259
|
+
self.isConnected = True
|
255
260
|
if self.user_logger:
|
256
261
|
self.user_logger.info(
|
257
262
|
"Market Data Socket connected successfully!",
|
258
263
|
caller="marketDataEngine.on_connect",
|
259
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
|
+
)
|
260
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")
|
261
282
|
async def on_disconnect(self) -> None:
|
262
283
|
"""
|
263
284
|
Handles the event when the market data socket gets disconnected.
|
@@ -267,12 +288,38 @@ class marketDataEngine(MarketDataSocketClient):
|
|
267
288
|
Returns:
|
268
289
|
None
|
269
290
|
"""
|
270
|
-
|
291
|
+
self.isConnected = False
|
271
292
|
if self.user_logger:
|
272
293
|
self.user_logger.info(
|
273
294
|
"Market Data Socket disconnected!",
|
274
295
|
caller="marketDataEngine.on_disconnect",
|
275
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
|
+
)
|
276
323
|
|
277
324
|
async def on_message(self, xts_message: Any) -> None:
|
278
325
|
"""
|
@@ -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=
|
5
|
-
tradx/marketDataEngine.py,sha256=
|
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.
|
32
|
-
tradx-0.
|
33
|
-
tradx-0.
|
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
|