tradingapi 0.3.1__tar.gz → 0.3.2__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 (31) hide show
  1. {tradingapi-0.3.1 → tradingapi-0.3.2}/PKG-INFO +1 -1
  2. {tradingapi-0.3.1 → tradingapi-0.3.2}/pyproject.toml +1 -1
  3. {tradingapi-0.3.1 → tradingapi-0.3.2}/tradingapi/fivepaisa.py +30 -39
  4. {tradingapi-0.3.1 → tradingapi-0.3.2}/tradingapi.egg-info/PKG-INFO +1 -1
  5. {tradingapi-0.3.1 → tradingapi-0.3.2}/README.md +0 -0
  6. {tradingapi-0.3.1 → tradingapi-0.3.2}/setup.cfg +0 -0
  7. {tradingapi-0.3.1 → tradingapi-0.3.2}/tests/test_find_option_with_delta.py +0 -0
  8. {tradingapi-0.3.1 → tradingapi-0.3.2}/tradingapi/__init__.py +0 -0
  9. {tradingapi-0.3.1 → tradingapi-0.3.2}/tradingapi/allocation.py +0 -0
  10. {tradingapi-0.3.1 → tradingapi-0.3.2}/tradingapi/attribution.py +0 -0
  11. {tradingapi-0.3.1 → tradingapi-0.3.2}/tradingapi/broker_base.py +0 -0
  12. {tradingapi-0.3.1 → tradingapi-0.3.2}/tradingapi/config/commissions_20241216.yaml +0 -0
  13. {tradingapi-0.3.1 → tradingapi-0.3.2}/tradingapi/config/config_sample.yaml +0 -0
  14. {tradingapi-0.3.1 → tradingapi-0.3.2}/tradingapi/config.py +0 -0
  15. {tradingapi-0.3.1 → tradingapi-0.3.2}/tradingapi/dhan.py +0 -0
  16. {tradingapi-0.3.1 → tradingapi-0.3.2}/tradingapi/error_handling.py +0 -0
  17. {tradingapi-0.3.1 → tradingapi-0.3.2}/tradingapi/exceptions.py +0 -0
  18. {tradingapi-0.3.1 → tradingapi-0.3.2}/tradingapi/flattrade.py +0 -0
  19. {tradingapi-0.3.1 → tradingapi-0.3.2}/tradingapi/globals.py +0 -0
  20. {tradingapi-0.3.1 → tradingapi-0.3.2}/tradingapi/icicidirect.py +0 -0
  21. {tradingapi-0.3.1 → tradingapi-0.3.2}/tradingapi/icicidirect_generate_session.py +0 -0
  22. {tradingapi-0.3.1 → tradingapi-0.3.2}/tradingapi/market_data_exchanges.py +0 -0
  23. {tradingapi-0.3.1 → tradingapi-0.3.2}/tradingapi/proxy_utils.py +0 -0
  24. {tradingapi-0.3.1 → tradingapi-0.3.2}/tradingapi/shoonya.py +0 -0
  25. {tradingapi-0.3.1 → tradingapi-0.3.2}/tradingapi/span.py +0 -0
  26. {tradingapi-0.3.1 → tradingapi-0.3.2}/tradingapi/utils.py +0 -0
  27. {tradingapi-0.3.1 → tradingapi-0.3.2}/tradingapi.egg-info/SOURCES.txt +0 -0
  28. {tradingapi-0.3.1 → tradingapi-0.3.2}/tradingapi.egg-info/dependency_links.txt +0 -0
  29. {tradingapi-0.3.1 → tradingapi-0.3.2}/tradingapi.egg-info/entry_points.txt +0 -0
  30. {tradingapi-0.3.1 → tradingapi-0.3.2}/tradingapi.egg-info/requires.txt +0 -0
  31. {tradingapi-0.3.1 → tradingapi-0.3.2}/tradingapi.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tradingapi
3
- Version: 0.3.1
3
+ Version: 0.3.2
4
4
  Summary: Trade integration with brokers
5
5
  Author-email: Pankaj Sharma <sharma.pankaj.kumar@gmail.com>
6
6
  License-Expression: MIT
@@ -28,7 +28,7 @@ packages = ["tradingapi"]
28
28
 
29
29
  [project]
30
30
  name = "tradingapi"
31
- version = "0.3.1"
31
+ version = "0.3.2"
32
32
  description = "Trade integration with brokers"
33
33
  readme = "README.md"
34
34
  license = "MIT"
@@ -37,60 +37,51 @@ from py5paisa import FivePaisaClient
37
37
 
38
38
 
39
39
  def _patch_py5paisa_for_mom(api) -> None:
40
- """Fix three upstream py5paisa bugs that break multi_order_Margin:
41
-
42
- 1. session is httpx.Client with 5s default timeout. Bump to 10s as a
43
- safety margin (normal MOM responses are sub-second).
44
- 2. self.payload = GENERIC_PAYLOAD is a reference assignment, so each
45
- call accumulates stale body keys across calls; the polluted body
46
- makes the 5paisa server hang past 5s. Reset to a fresh deep copy
47
- before each MOM call.
48
- 3. order_request() does res["body"]["Message"] for MOM, but the MOM
49
- response has no "Message" key KeyError is raised at the subscript,
50
- swallowed by the bare except, and the function silently returns None.
51
- Replace order_request for the MOM case to extract res["body"] directly
52
- without touching "Message".
40
+ """Replace api.multi_order_Margin to bypass three upstream py5paisa bugs:
41
+
42
+ 1. self.payload = GENERIC_PAYLOAD is a reference assignment shared across
43
+ every py5paisa method, so concurrent calls (status, balance, place_order)
44
+ clobber the MOM body between build and POST. Build payload locally.
45
+ 2. order_request() does res["body"]["Message"] for MOM, but MOM responses
46
+ have no "Message" key KeyError is swallowed by a bare except and the
47
+ function silently returns None. POST directly and read body.
48
+ 3. Default 5s read timeout is too tight for SENSEX MOM under load.
49
+ Use a per-call 10s timeout (does not affect other API calls).
53
50
  """
54
51
  if getattr(api, "_tradingapi_patched", False):
55
52
  return
56
53
 
57
54
  import copy
58
- from py5paisa.const import GENERIC_PAYLOAD
55
+ import httpx
56
+ from py5paisa.const import GENERIC_PAYLOAD, HEADERS
59
57
 
60
- try:
61
- api.session.timeout = 10
62
- except Exception:
63
- pass
58
+ # Dedicated session for MOM — never shares the pool with api.session,
59
+ # which other py5paisa calls (balance, order status, etc.) use concurrently.
60
+ mom_session = httpx.Client(verify=False, timeout=10)
64
61
 
65
- original_order_request = api.order_request
62
+ def fixed_multi_order_Margin(**order):
63
+ payload = copy.deepcopy(GENERIC_PAYLOAD)
64
+ payload["body"]["ClientCode"] = api.client_code
65
+ payload["head"]["key"] = api.USER_KEY
66
+ for k, v in order.items():
67
+ payload["body"][k] = v
66
68
 
67
- def safe_order_request(req_type):
68
- if req_type != "MOM":
69
- return original_order_request(req_type)
69
+ token = api.access_token or api.Jwt_token
70
+ headers = dict(HEADERS)
71
+ headers["Authorization"] = f"Bearer {token}"
72
+ headers["5Paisa-API-Uid"] = api.APIUID
70
73
  try:
71
- api.payload["body"]["ClientCode"] = api.client_code
72
- api.payload["head"]["key"] = api.USER_KEY
73
- from py5paisa.const import HEADERS
74
- token = api.access_token or api.Jwt_token
75
- headers = dict(HEADERS)
76
- headers["Authorization"] = f"Bearer {token}"
77
- headers["5Paisa-API-Uid"] = api.APIUID
78
- res = api.session.post(api.MULTIORDERMARGIN_ROUTE, json=api.payload, headers=headers).json()
79
- api.payload = copy.deepcopy(GENERIC_PAYLOAD)
74
+ res = mom_session.post(
75
+ api.MULTIORDERMARGIN_ROUTE,
76
+ json=payload,
77
+ headers=headers,
78
+ ).json()
80
79
  return res.get("body")
81
80
  except Exception as e:
82
81
  from . import trading_logger
83
82
  trading_logger.log_warning("py5paisa MOM request failed", {"error": repr(e)})
84
- api.payload = copy.deepcopy(GENERIC_PAYLOAD)
85
83
  return None
86
84
 
87
- def fixed_multi_order_Margin(**order):
88
- api.payload = copy.deepcopy(GENERIC_PAYLOAD)
89
- for k, v in order.items():
90
- api.payload["body"][k] = v
91
- return safe_order_request("MOM")
92
-
93
- api.order_request = safe_order_request
94
85
  api.multi_order_Margin = fixed_multi_order_Margin
95
86
  api._tradingapi_patched = True
96
87
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tradingapi
3
- Version: 0.3.1
3
+ Version: 0.3.2
4
4
  Summary: Trade integration with brokers
5
5
  Author-email: Pankaj Sharma <sharma.pankaj.kumar@gmail.com>
6
6
  License-Expression: MIT
File without changes
File without changes