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.
- {tradingapi-0.3.1 → tradingapi-0.3.2}/PKG-INFO +1 -1
- {tradingapi-0.3.1 → tradingapi-0.3.2}/pyproject.toml +1 -1
- {tradingapi-0.3.1 → tradingapi-0.3.2}/tradingapi/fivepaisa.py +30 -39
- {tradingapi-0.3.1 → tradingapi-0.3.2}/tradingapi.egg-info/PKG-INFO +1 -1
- {tradingapi-0.3.1 → tradingapi-0.3.2}/README.md +0 -0
- {tradingapi-0.3.1 → tradingapi-0.3.2}/setup.cfg +0 -0
- {tradingapi-0.3.1 → tradingapi-0.3.2}/tests/test_find_option_with_delta.py +0 -0
- {tradingapi-0.3.1 → tradingapi-0.3.2}/tradingapi/__init__.py +0 -0
- {tradingapi-0.3.1 → tradingapi-0.3.2}/tradingapi/allocation.py +0 -0
- {tradingapi-0.3.1 → tradingapi-0.3.2}/tradingapi/attribution.py +0 -0
- {tradingapi-0.3.1 → tradingapi-0.3.2}/tradingapi/broker_base.py +0 -0
- {tradingapi-0.3.1 → tradingapi-0.3.2}/tradingapi/config/commissions_20241216.yaml +0 -0
- {tradingapi-0.3.1 → tradingapi-0.3.2}/tradingapi/config/config_sample.yaml +0 -0
- {tradingapi-0.3.1 → tradingapi-0.3.2}/tradingapi/config.py +0 -0
- {tradingapi-0.3.1 → tradingapi-0.3.2}/tradingapi/dhan.py +0 -0
- {tradingapi-0.3.1 → tradingapi-0.3.2}/tradingapi/error_handling.py +0 -0
- {tradingapi-0.3.1 → tradingapi-0.3.2}/tradingapi/exceptions.py +0 -0
- {tradingapi-0.3.1 → tradingapi-0.3.2}/tradingapi/flattrade.py +0 -0
- {tradingapi-0.3.1 → tradingapi-0.3.2}/tradingapi/globals.py +0 -0
- {tradingapi-0.3.1 → tradingapi-0.3.2}/tradingapi/icicidirect.py +0 -0
- {tradingapi-0.3.1 → tradingapi-0.3.2}/tradingapi/icicidirect_generate_session.py +0 -0
- {tradingapi-0.3.1 → tradingapi-0.3.2}/tradingapi/market_data_exchanges.py +0 -0
- {tradingapi-0.3.1 → tradingapi-0.3.2}/tradingapi/proxy_utils.py +0 -0
- {tradingapi-0.3.1 → tradingapi-0.3.2}/tradingapi/shoonya.py +0 -0
- {tradingapi-0.3.1 → tradingapi-0.3.2}/tradingapi/span.py +0 -0
- {tradingapi-0.3.1 → tradingapi-0.3.2}/tradingapi/utils.py +0 -0
- {tradingapi-0.3.1 → tradingapi-0.3.2}/tradingapi.egg-info/SOURCES.txt +0 -0
- {tradingapi-0.3.1 → tradingapi-0.3.2}/tradingapi.egg-info/dependency_links.txt +0 -0
- {tradingapi-0.3.1 → tradingapi-0.3.2}/tradingapi.egg-info/entry_points.txt +0 -0
- {tradingapi-0.3.1 → tradingapi-0.3.2}/tradingapi.egg-info/requires.txt +0 -0
- {tradingapi-0.3.1 → tradingapi-0.3.2}/tradingapi.egg-info/top_level.txt +0 -0
|
@@ -37,60 +37,51 @@ from py5paisa import FivePaisaClient
|
|
|
37
37
|
|
|
38
38
|
|
|
39
39
|
def _patch_py5paisa_for_mom(api) -> None:
|
|
40
|
-
"""
|
|
41
|
-
|
|
42
|
-
1.
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
3.
|
|
49
|
-
|
|
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
|
-
|
|
55
|
+
import httpx
|
|
56
|
+
from py5paisa.const import GENERIC_PAYLOAD, HEADERS
|
|
59
57
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
-
|
|
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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|