tradx 0.7.5__py3-none-any.whl → 0.7.7__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
@@ -11,6 +11,7 @@ from tradx.baseClass.orderEvent import OrderEvent
|
|
11
11
|
from tradx.baseClass.positionEvent import PositionEvent
|
12
12
|
from tradx.baseClass.tradeEvent import TradeEvent
|
13
13
|
from tradx.baseClass.tradeConversionEvent import TradeConversionEvent
|
14
|
+
from datetime import datetime
|
14
15
|
|
15
16
|
|
16
17
|
class interactiveEngine(InteractiveSocketClient):
|
@@ -91,6 +92,7 @@ class interactiveEngine(InteractiveSocketClient):
|
|
91
92
|
self.funds: int = None
|
92
93
|
self.strategy_to_id: Dict[str, bA] = {}
|
93
94
|
self.position_diary_engine = {}
|
95
|
+
self.isConnected: bool = False
|
94
96
|
self.user_logger = user_logger
|
95
97
|
if user_logger:
|
96
98
|
self.user_logger.info(
|
@@ -124,6 +126,9 @@ class interactiveEngine(InteractiveSocketClient):
|
|
124
126
|
- The disclosed quantity, limit price, and stop price are set to 0.
|
125
127
|
- Logs the response if user_logger is available.
|
126
128
|
"""
|
129
|
+
assert (
|
130
|
+
self.isConnected is True
|
131
|
+
), f"Interactive Engine is not connected, Rejecting order with orderID: {orderUniqueIdentifier}."
|
127
132
|
allowed_exchange_segments = [
|
128
133
|
XTSConnect.EXCHANGE_NSECM,
|
129
134
|
XTSConnect.EXCHANGE_BSECM,
|
@@ -198,6 +203,9 @@ class interactiveEngine(InteractiveSocketClient):
|
|
198
203
|
- The limit price is set to 0.
|
199
204
|
- Logs the response if user_logger is available.
|
200
205
|
"""
|
206
|
+
assert (
|
207
|
+
self.isConnected is True
|
208
|
+
), f"Interactive Engine is not connected, Rejecting order with orderID: {orderUniqueIdentifier}."
|
201
209
|
allowed_exchange_segments = [
|
202
210
|
XTSConnect.EXCHANGE_NSECM,
|
203
211
|
XTSConnect.EXCHANGE_BSECM,
|
@@ -233,7 +241,7 @@ class interactiveEngine(InteractiveSocketClient):
|
|
233
241
|
disclosedQuantity=0,
|
234
242
|
orderQuantity=abs(orderQuantity),
|
235
243
|
limitPrice=0,
|
236
|
-
stopPrice=stopPrice,
|
244
|
+
stopPrice=stopPrice.to_eng_string(),
|
237
245
|
orderUniqueIdentifier=orderUniqueIdentifier,
|
238
246
|
clientID=self.set_iuserID,
|
239
247
|
)
|
@@ -267,6 +275,9 @@ class interactiveEngine(InteractiveSocketClient):
|
|
267
275
|
- If orderQuantity is 0, the function will return immediately without placing an order.
|
268
276
|
- Logs the response of the order placement if user_logger is set.
|
269
277
|
"""
|
278
|
+
assert (
|
279
|
+
self.isConnected is True
|
280
|
+
), f"Interactive Engine is not connected, Rejecting order with orderID: {orderUniqueIdentifier}."
|
270
281
|
allowed_exchange_segments = [
|
271
282
|
XTSConnect.EXCHANGE_NSECM,
|
272
283
|
XTSConnect.EXCHANGE_BSECM,
|
@@ -341,6 +352,9 @@ class interactiveEngine(InteractiveSocketClient):
|
|
341
352
|
- If the order quantity is zero, the function returns immediately without placing an order.
|
342
353
|
- The function logs the response from the order placement if a user logger is available.
|
343
354
|
"""
|
355
|
+
assert (
|
356
|
+
self.isConnected is True
|
357
|
+
), f"Interactive Engine is not connected, Rejecting order with orderID: {orderUniqueIdentifier}."
|
344
358
|
allowed_exchange_segments = [
|
345
359
|
XTSConnect.EXCHANGE_NSECM,
|
346
360
|
XTSConnect.EXCHANGE_BSECM,
|
@@ -366,7 +380,7 @@ class interactiveEngine(InteractiveSocketClient):
|
|
366
380
|
), "exchangeInstrumentID must be an integer"
|
367
381
|
assert isinstance(productType, str), "productType must be a string"
|
368
382
|
assert isinstance(orderQuantity, int), "orderQuantity must be an integer"
|
369
|
-
assert isinstance(limitPrice, Decimal), "limitPrice must be a
|
383
|
+
assert isinstance(limitPrice, Decimal), "limitPrice must be a string"
|
370
384
|
assert isinstance(stopPrice, Decimal), "stopPrice must be a Decimal"
|
371
385
|
assert isinstance(
|
372
386
|
orderUniqueIdentifier, str
|
@@ -386,8 +400,8 @@ class interactiveEngine(InteractiveSocketClient):
|
|
386
400
|
timeInForce=self.xt.VALIDITY_DAY,
|
387
401
|
disclosedQuantity=0,
|
388
402
|
orderQuantity=abs(orderQuantity),
|
389
|
-
limitPrice=limitPrice,
|
390
|
-
stopPrice=stopPrice,
|
403
|
+
limitPrice=limitPrice.to_eng_string(),
|
404
|
+
stopPrice=stopPrice.to_eng_string(),
|
391
405
|
orderUniqueIdentifier=orderUniqueIdentifier,
|
392
406
|
clientID=self.set_iuserID,
|
393
407
|
)
|
@@ -441,7 +455,7 @@ class interactiveEngine(InteractiveSocketClient):
|
|
441
455
|
Returns:
|
442
456
|
None
|
443
457
|
"""
|
444
|
-
|
458
|
+
self.isConnected = True
|
445
459
|
if self.user_logger:
|
446
460
|
self.user_logger.info(
|
447
461
|
"Interactive socket connected successfully!",
|
@@ -515,6 +529,75 @@ class interactiveEngine(InteractiveSocketClient):
|
|
515
529
|
Returns:
|
516
530
|
None
|
517
531
|
"""
|
532
|
+
self.isConnected = False
|
533
|
+
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.")
|
538
|
+
# Log the initiation of the liquidation process
|
539
|
+
if self.user_logger:
|
540
|
+
self.user_logger.info(
|
541
|
+
f"Socket Disconnected, emergency square off triggered.",
|
542
|
+
caller="interactiveEngine.on_disconnect",
|
543
|
+
)
|
544
|
+
|
545
|
+
# Retrieve day-wise positions
|
546
|
+
response = await self.xt.get_position_daywise("*****")
|
547
|
+
|
548
|
+
list_of_exchangeSegment = []
|
549
|
+
|
550
|
+
# Square off any open positions by placing market orders in the opposite direction
|
551
|
+
for i in response["result"]["positionList"]:
|
552
|
+
if int(i["Quantity"]) != 0 and i["ProductType"] != "CNC":
|
553
|
+
orderQuantity = -1 * int(i["Quantity"])
|
554
|
+
list_of_exchangeSegment.append(i["ExchangeSegment"])
|
555
|
+
asyncio.ensure_future(
|
556
|
+
self.xt.place_order(
|
557
|
+
exchangeSegment=i["ExchangeSegment"],
|
558
|
+
exchangeInstrumentID=int(i["ExchangeInstrumentId"]),
|
559
|
+
productType=i["ProductType"],
|
560
|
+
orderType=self.xt.ORDER_TYPE_MARKET,
|
561
|
+
orderSide=(
|
562
|
+
self.xt.TRANSACTION_TYPE_BUY
|
563
|
+
if orderQuantity > 0
|
564
|
+
else self.xt.TRANSACTION_TYPE_SELL
|
565
|
+
),
|
566
|
+
timeInForce=self.xt.VALIDITY_DAY,
|
567
|
+
disclosedQuantity=0,
|
568
|
+
orderQuantity=abs(orderQuantity),
|
569
|
+
limitPrice=0,
|
570
|
+
stopPrice=0,
|
571
|
+
orderUniqueIdentifier="Liquidated",
|
572
|
+
clientID=self.set_iuserID,
|
573
|
+
)
|
574
|
+
).add_done_callback(
|
575
|
+
lambda future: (
|
576
|
+
self.user_logger.info(
|
577
|
+
f"Place Order: {future.result()}",
|
578
|
+
caller="interactiveEngine.on_disconnect",
|
579
|
+
)
|
580
|
+
if self.user_logger
|
581
|
+
else None
|
582
|
+
)
|
583
|
+
)
|
584
|
+
|
585
|
+
# Cancel all open orders for the specified exchange segment
|
586
|
+
for exchangeSegment in list_of_exchangeSegment:
|
587
|
+
|
588
|
+
asyncio.ensure_future(
|
589
|
+
self.xt.cancelall_order(exchangeSegment, 0)
|
590
|
+
).add_done_callback(
|
591
|
+
lambda future: (
|
592
|
+
self.user_logger.info(
|
593
|
+
f"Cancel Order: {future.result()}",
|
594
|
+
caller="interactiveEngine.Liquidate",
|
595
|
+
)
|
596
|
+
if self.user_logger
|
597
|
+
else None
|
598
|
+
)
|
599
|
+
)
|
600
|
+
|
518
601
|
if self.user_logger:
|
519
602
|
self.user_logger.info(
|
520
603
|
"Interactive Socket disconnected!",
|
@@ -1,7 +1,7 @@
|
|
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=
|
4
|
+
tradx/interactiveEngine.py,sha256=p2DSJRP7JEHO7xTurqGbJ1zusNRYD_oot7AASID1tnc,38897
|
5
5
|
tradx/marketDataEngine.py,sha256=QwMWI0kZe5OsFPUcG_J2Kk7-Q_WODmkUM8BBRgIvkTw,35163
|
6
6
|
tradx/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
7
7
|
tradx/baseClass/baseAlgo.py,sha256=LE4ZYb-gLpPMU45ETMg58kRQdGN-Q9wgDhKEasovL-k,20922
|
@@ -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.7.
|
32
|
-
tradx-0.7.
|
33
|
-
tradx-0.7.
|
31
|
+
tradx-0.7.7.dist-info/METADATA,sha256=Kd8L9Aj-uhluQLJ0nzcLZ-q28cifIGaTIkOXcThReoc,2627
|
32
|
+
tradx-0.7.7.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
33
|
+
tradx-0.7.7.dist-info/RECORD,,
|
File without changes
|