quantplay 2.1.129__tar.gz → 2.1.131__tar.gz

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.
Files changed (91) hide show
  1. {quantplay-2.1.129 → quantplay-2.1.131}/PKG-INFO +1 -1
  2. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/broker/jainam_xts.py +73 -16
  3. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/broker/xts.py +3 -2
  4. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay.egg-info/PKG-INFO +1 -1
  5. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay.egg-info/SOURCES.txt +1 -0
  6. {quantplay-2.1.129 → quantplay-2.1.131}/setup.py +1 -1
  7. quantplay-2.1.131/tests/test_jainam_xts.py +109 -0
  8. {quantplay-2.1.129 → quantplay-2.1.131}/README.md +0 -0
  9. {quantplay-2.1.129 → quantplay-2.1.131}/pyproject.toml +0 -0
  10. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/__init__.py +0 -0
  11. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/broker/__init__.py +0 -0
  12. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/broker/aliceblue.py +0 -0
  13. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/broker/aliceblue_utils/__init__.py +0 -0
  14. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/broker/aliceblue_utils/aliceblue_oauth.py +0 -0
  15. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/broker/aliceblue_v2.py +0 -0
  16. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/broker/angelone.py +0 -0
  17. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/broker/angelone_utils/__init__.py +0 -0
  18. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/broker/angelone_utils/angeloneWS.py +0 -0
  19. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/broker/auto_login/__init__.py +0 -0
  20. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/broker/auto_login/aliceblue.py +0 -0
  21. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/broker/breeze/__init__.py +0 -0
  22. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/broker/breeze/breeze_utils.py +0 -0
  23. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/broker/broker_factory.py +0 -0
  24. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/broker/dhan.py +0 -0
  25. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/broker/finvasia_utils/__init__.py +0 -0
  26. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/broker/finvasia_utils/fa_noren.py +0 -0
  27. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/broker/finvasia_utils/finvasia_oauth.py +0 -0
  28. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/broker/five_paisa.py +0 -0
  29. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/broker/flattrade.py +0 -0
  30. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/broker/ft_utils/__init__.py +0 -0
  31. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/broker/ft_utils/flattrade_utils.py +0 -0
  32. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/broker/ft_utils/ft_noren.py +0 -0
  33. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/broker/generics/__init__.py +0 -0
  34. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/broker/generics/broker.py +0 -0
  35. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/broker/icici_direct.py +0 -0
  36. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/broker/iifl_xts.py +0 -0
  37. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/broker/kite_utils.py +0 -0
  38. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/broker/kotak.py +0 -0
  39. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/broker/kotak_utils/__init__.py +0 -0
  40. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/broker/kotak_utils/kotak_ws.py +0 -0
  41. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/broker/kotak_utils/kotak_ws_lib.py +0 -0
  42. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/broker/motilal.py +0 -0
  43. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/broker/noren.py +0 -0
  44. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/broker/shoonya.py +0 -0
  45. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/broker/uplink/__init__.py +0 -0
  46. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/broker/uplink/uplink_utils.py +0 -0
  47. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/broker/upstox.py +0 -0
  48. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/broker/xts_utils/Connect.py +0 -0
  49. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/broker/xts_utils/Exception.py +0 -0
  50. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/broker/xts_utils/InteractiveSocketClient.py +0 -0
  51. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/broker/xts_utils/__init__.py +0 -0
  52. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/broker/xts_utils_v2/ConnectV2.py +0 -0
  53. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/broker/xts_utils_v2/InteractiveSocketClientV2.py +0 -0
  54. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/broker/xts_utils_v2/__init__.py +0 -0
  55. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/broker/zerodha.py +0 -0
  56. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/core/__init__.py +0 -0
  57. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/core/strategy.py +0 -0
  58. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/exception/__init__.py +0 -0
  59. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/exception/exceptions.py +0 -0
  60. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/indicator/__init__.py +0 -0
  61. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/indicator/iv.py +0 -0
  62. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/model/__init__.py +0 -0
  63. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/model/broker.py +0 -0
  64. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/model/broker_response.py +0 -0
  65. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/model/generics.py +0 -0
  66. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/model/instrument_data.py +0 -0
  67. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/model/order_event.py +0 -0
  68. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/py.typed +0 -0
  69. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/strategy/__init__.py +0 -0
  70. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/strategy/iv_spike.py +0 -0
  71. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/strategy/obuy.py +0 -0
  72. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/utils/__init__.py +0 -0
  73. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/utils/caching.py +0 -0
  74. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/utils/constant.py +0 -0
  75. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/utils/exchange.py +0 -0
  76. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/utils/number_utils.py +0 -0
  77. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/utils/pickle_utils.py +0 -0
  78. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/utils/selenium_utils.py +0 -0
  79. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/wrapper/__init__.py +0 -0
  80. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/wrapper/aws/__init__.py +0 -0
  81. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/wrapper/aws/s3.py +0 -0
  82. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay/wrapper/redis.py +0 -0
  83. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay.egg-info/dependency_links.txt +0 -0
  84. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay.egg-info/requires.txt +0 -0
  85. {quantplay-2.1.129 → quantplay-2.1.131}/quantplay.egg-info/top_level.txt +0 -0
  86. {quantplay-2.1.129 → quantplay-2.1.131}/setup.cfg +0 -0
  87. {quantplay-2.1.129 → quantplay-2.1.131}/tests/__init__.py +0 -0
  88. {quantplay-2.1.129 → quantplay-2.1.131}/tests/conftest.py +0 -0
  89. {quantplay-2.1.129 → quantplay-2.1.131}/tests/wrapper/__init__.py +0 -0
  90. {quantplay-2.1.129 → quantplay-2.1.131}/tests/wrapper/aws/__init__.py +0 -0
  91. {quantplay-2.1.129 → quantplay-2.1.131}/tests/wrapper/aws/s3_test.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: quantplay
3
- Version: 2.1.129
3
+ Version: 2.1.131
4
4
  Summary: This python package will be stored in AWS CodeArtifact
5
5
  Home-page:
6
6
  Author:
@@ -8,7 +8,12 @@ from quantplay.broker.xts_utils_v2.ConnectV2 import XTSConnectV2
8
8
  from quantplay.broker.xts_utils_v2.InteractiveSocketClientV2 import (
9
9
  OrderSocket_io_V2,
10
10
  )
11
- from quantplay.exception.exceptions import InvalidArgumentException, TokenException
11
+ from quantplay.exception.exceptions import (
12
+ BrokerException,
13
+ InvalidArgumentException,
14
+ TokenException,
15
+ )
16
+ from quantplay.utils.constant import Constants
12
17
 
13
18
  XTS_ROOT_URL_MAP = {
14
19
  "A": "https://smpa.jainam.in:6543",
@@ -45,11 +50,17 @@ XTS_LOGIN_URL_MAP = {
45
50
  # - orders/positions work fine because they use dealer endpoints with
46
51
  # clientID=None, which returns all sub-client orders
47
52
  #
48
- # FIX: For type C dealers, we discover the sub-client ID by fetching
49
- # the dealer orderbook after login and extracting the ClientID from
50
- # the most recent order. This is stored as self.dealer_client_id and
51
- # used for place_order, modify_order, cancel_order instead of
52
- # self.ClientID.
53
+ # FIX: For type C dealers we resolve the sub-client ID from the login
54
+ # response, which carries it in `clientCodes` (e.g. ["JSR129"]). It is
55
+ # stored as self.dealer_client_id and used for place_order,
56
+ # modify_order and cancel_order instead of self.ClientID.
57
+ #
58
+ # Sessions restored from a stored token have no login response, so we
59
+ # fall back to reading the ClientID off the dealer orderbook. That
60
+ # fallback cannot work before the first order of the day exists, so it
61
+ # is retried lazily on each write rather than only at construction.
62
+ # If neither source resolves, writes raise instead of falling back to
63
+ # the dealer ID — XTS accepts that value and then drops the order.
53
64
  #
54
65
  class Jainam(XTS):
55
66
  def __init__(
@@ -68,6 +79,9 @@ class Jainam(XTS):
68
79
  ) -> None:
69
80
  self.XTS_type = XTS_type
70
81
 
82
+ # Set before super().__init__() because login() runs inside it.
83
+ self._login_client_code: str | None = None
84
+
71
85
  # XTS type C dealers route through the broker's own infra; an
72
86
  # outbound proxy is unnecessary and just adds latency/failure modes.
73
87
  if XTS_type == "C":
@@ -95,25 +109,51 @@ class Jainam(XTS):
95
109
 
96
110
  self.dealer_client_id: str | None = None
97
111
  if is_dealer and XTS_type == "C":
98
- self._discover_sub_client()
112
+ self._resolve_sub_client()
99
113
 
100
114
  self.ORDER_POLLING_INTERVAL = 5
101
115
 
102
116
  @property
103
117
  def order_client_id(self) -> str:
104
- """Type C: use sub-client ID. Type B: use ***** (from self.ClientID)."""
105
- if self.XTS_type == "C" and self.dealer_client_id:
106
- return self.dealer_client_id
107
- return self.ClientID
118
+ """Client ID for write operations.
119
+
120
+ Type C dealer: the sub-client ID. Type B: ***** (from self.ClientID).
121
+ """
122
+ if self.XTS_type != "C" or not self.is_dealer:
123
+ return self.ClientID
124
+
125
+ if not self.dealer_client_id:
126
+ # Construction-time resolution fails when the session is restored
127
+ # from a token and the dealer orderbook is still empty, which is
128
+ # every morning before the first order. Retry rather than spend
129
+ # the whole session on a client ID the broker will drop.
130
+ self._resolve_sub_client()
131
+
132
+ if not self.dealer_client_id:
133
+ raise BrokerException(
134
+ f"Jainam type C dealer [{self.ClientID}]: sub-client code could not "
135
+ "be resolved from the login response or the dealer orderbook. "
136
+ "Refusing to place the order with the dealer ID, which XTS accepts "
137
+ "and then silently drops."
138
+ )
108
139
 
109
- def _discover_sub_client(self) -> None:
110
- """For type C dealers, discover the sub-client ID from the orderbook.
140
+ return self.dealer_client_id
141
+
142
+ def _resolve_sub_client(self) -> None:
143
+ """Resolve the type C sub-client ID.
111
144
 
112
145
  XTS type C silently drops orders placed with clientID=<dealer_id>.
113
146
  The actual trading client (e.g. "JSR129") is a sub-account mapped
114
- under the dealer. We find it by fetching the dealer orderbook and
115
- extracting the ClientID from the most recent order.
147
+ under the dealer.
148
+
149
+ The login response carries it in `clientCodes`. Sessions restored
150
+ from a stored token have no login response, so fall back to reading
151
+ the ClientID off the most recent order in the dealer orderbook.
116
152
  """
153
+ if self._login_client_code:
154
+ self.dealer_client_id = self._login_client_code
155
+ return
156
+
117
157
  try:
118
158
  resp = self.wrapper.get_dealer_orderbook()
119
159
  if (
@@ -128,7 +168,17 @@ class Jainam(XTS):
128
168
  )
129
169
  self.dealer_client_id = latest.get("ClientID")
130
170
  except Exception:
131
- pass # No orders yet or API error — fall back to dealer ID
171
+ Constants.logger.warning(
172
+ f"[JAINAM_SUB_CLIENT_LOOKUP_FAILED] dealer [{self.ClientID}] "
173
+ f"orderbook lookup failed: {traceback.format_exc()}"
174
+ )
175
+
176
+ if not self.dealer_client_id:
177
+ Constants.logger.warning(
178
+ f"[JAINAM_SUB_CLIENT_UNRESOLVED] dealer [{self.ClientID}] has no "
179
+ "client code from login and no orders in the dealer orderbook; "
180
+ "writes will fail until one resolves."
181
+ )
132
182
 
133
183
  def login(
134
184
  self, api_key: str, api_secret: str, md_api_key: str, md_api_secret: str
@@ -164,6 +214,13 @@ class Jainam(XTS):
164
214
 
165
215
  self.ClientID = xt_core_response["result"]["userID"]
166
216
 
217
+ # Type C dealers must place orders as the sub-client mapped under
218
+ # the dealer, never as the dealer itself. The login response is the
219
+ # only source for it that works before the day's first order.
220
+ client_codes: list[str] = xt_core_response["result"].get("clientCodes") or []
221
+ if client_codes:
222
+ self._login_client_code = client_codes[0]
223
+
167
224
  except TokenException:
168
225
  raise
169
226
 
@@ -1,3 +1,4 @@
1
+ import uuid
1
2
  import codecs
2
3
  import json
3
4
  import pickle
@@ -665,8 +666,8 @@ class XTS(Broker):
665
666
  if trigger_price is None:
666
667
  trigger_price = 0
667
668
 
668
- if tag is None:
669
- tag = ""
669
+ if not tag:
670
+ tag = str(uuid.uuid4())[:8]
670
671
 
671
672
  with self._proxied():
672
673
  api_response = self.wrapper.place_order(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: quantplay
3
- Version: 2.1.129
3
+ Version: 2.1.131
4
4
  Summary: This python package will be stored in AWS CodeArtifact
5
5
  Home-page:
6
6
  Author:
@@ -83,6 +83,7 @@ quantplay/wrapper/aws/__init__.py
83
83
  quantplay/wrapper/aws/s3.py
84
84
  tests/__init__.py
85
85
  tests/conftest.py
86
+ tests/test_jainam_xts.py
86
87
  tests/wrapper/__init__.py
87
88
  tests/wrapper/aws/__init__.py
88
89
  tests/wrapper/aws/s3_test.py
@@ -21,7 +21,7 @@ requirements = [
21
21
  setup(
22
22
  name="quantplay",
23
23
  long_description=Path("README.md").read_text(),
24
- version="2.1.129",
24
+ version="2.1.131",
25
25
  install_requires=requirements,
26
26
  tests_require=[],
27
27
  packages=find_packages(),
@@ -0,0 +1,109 @@
1
+ from typing import Any
2
+ from unittest.mock import MagicMock
3
+
4
+ import pytest
5
+
6
+ from quantplay.broker.jainam_xts import Jainam
7
+ from quantplay.exception.exceptions import BrokerException
8
+
9
+ DEALER_ID = "JSR129A42"
10
+ SUB_CLIENT_ID = "JSR129"
11
+
12
+
13
+ def build_jainam(
14
+ XTS_type: str = "C",
15
+ is_dealer: bool = True,
16
+ login_client_code: str | None = None,
17
+ orderbook: dict[str, Any] | None = None,
18
+ ) -> tuple[Jainam, MagicMock]:
19
+ """A Jainam instance with login/instrument loading bypassed.
20
+
21
+ Jainam.__init__ logs in to the broker and downloads the instrument
22
+ master, so the client-ID resolution is exercised on a bare instance.
23
+ """
24
+ broker = object.__new__(Jainam)
25
+ broker.XTS_type = XTS_type # type: ignore[assignment]
26
+ broker.is_dealer = is_dealer
27
+ broker.ClientID = "*****" if XTS_type == "B" else DEALER_ID
28
+ broker._login_client_code = login_client_code # pyright: ignore[reportPrivateUsage]
29
+ broker.dealer_client_id = None
30
+
31
+ wrapper = MagicMock()
32
+ wrapper.get_dealer_orderbook.return_value = orderbook or {
33
+ "type": "success",
34
+ "result": [],
35
+ }
36
+ broker.wrapper = wrapper
37
+
38
+ return broker, wrapper
39
+
40
+
41
+ def test_login_client_code_is_preferred_over_the_orderbook():
42
+ broker, wrapper = build_jainam(login_client_code=SUB_CLIENT_ID)
43
+
44
+ assert broker.order_client_id == SUB_CLIENT_ID
45
+ wrapper.get_dealer_orderbook.assert_not_called()
46
+
47
+
48
+ def test_falls_back_to_orderbook_when_login_gave_no_client_code():
49
+ broker, _ = build_jainam(
50
+ orderbook={
51
+ "type": "success",
52
+ "result": [
53
+ {"AppOrderID": 1, "ClientID": "OLD123"},
54
+ {"AppOrderID": 9, "ClientID": SUB_CLIENT_ID},
55
+ ],
56
+ }
57
+ )
58
+
59
+ assert broker.order_client_id == SUB_CLIENT_ID
60
+
61
+
62
+ def test_raises_rather_than_placing_as_the_dealer():
63
+ """The dealer ID is accepted by XTS and then silently dropped.
64
+
65
+ Reproduces the 2026-08-07 outage: PMS started pre-open, the dealer
66
+ orderbook was empty, and every copy order was placed as the dealer
67
+ and discarded by the gateway.
68
+ """
69
+ broker, _ = build_jainam()
70
+
71
+ with pytest.raises(BrokerException) as excinfo:
72
+ _ = broker.order_client_id
73
+
74
+ assert DEALER_ID in str(excinfo.value)
75
+
76
+
77
+ def test_resolution_is_retried_after_an_empty_orderbook():
78
+ broker, wrapper = build_jainam()
79
+
80
+ with pytest.raises(BrokerException):
81
+ _ = broker.order_client_id
82
+
83
+ # The day's first order now exists, so a later write resolves.
84
+ wrapper.get_dealer_orderbook.return_value = {
85
+ "type": "success",
86
+ "result": [{"AppOrderID": 1, "ClientID": SUB_CLIENT_ID}],
87
+ }
88
+
89
+ assert broker.order_client_id == SUB_CLIENT_ID
90
+
91
+
92
+ def test_orderbook_errors_do_not_escape_as_api_errors():
93
+ broker, wrapper = build_jainam()
94
+ wrapper.get_dealer_orderbook.side_effect = RuntimeError("XTS 500")
95
+
96
+ with pytest.raises(BrokerException):
97
+ _ = broker.order_client_id
98
+
99
+
100
+ def test_type_b_dealer_still_places_as_masked_client():
101
+ broker, _ = build_jainam(XTS_type="B")
102
+
103
+ assert broker.order_client_id == "*****"
104
+
105
+
106
+ def test_type_c_non_dealer_places_as_itself():
107
+ broker, _ = build_jainam(is_dealer=False)
108
+
109
+ assert broker.order_client_id == DEALER_ID
File without changes
File without changes
File without changes