tradingapi 0.3.1__tar.gz → 0.3.3__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.3}/PKG-INFO +1 -1
- {tradingapi-0.3.1 → tradingapi-0.3.3}/pyproject.toml +1 -1
- {tradingapi-0.3.1 → tradingapi-0.3.3}/tradingapi/fivepaisa.py +30 -39
- {tradingapi-0.3.1 → tradingapi-0.3.3}/tradingapi/utils.py +3 -20
- {tradingapi-0.3.1 → tradingapi-0.3.3}/tradingapi.egg-info/PKG-INFO +1 -1
- {tradingapi-0.3.1 → tradingapi-0.3.3}/README.md +0 -0
- {tradingapi-0.3.1 → tradingapi-0.3.3}/setup.cfg +0 -0
- {tradingapi-0.3.1 → tradingapi-0.3.3}/tests/test_find_option_with_delta.py +0 -0
- {tradingapi-0.3.1 → tradingapi-0.3.3}/tradingapi/__init__.py +0 -0
- {tradingapi-0.3.1 → tradingapi-0.3.3}/tradingapi/allocation.py +0 -0
- {tradingapi-0.3.1 → tradingapi-0.3.3}/tradingapi/attribution.py +0 -0
- {tradingapi-0.3.1 → tradingapi-0.3.3}/tradingapi/broker_base.py +0 -0
- {tradingapi-0.3.1 → tradingapi-0.3.3}/tradingapi/config/commissions_20241216.yaml +0 -0
- {tradingapi-0.3.1 → tradingapi-0.3.3}/tradingapi/config/config_sample.yaml +0 -0
- {tradingapi-0.3.1 → tradingapi-0.3.3}/tradingapi/config.py +0 -0
- {tradingapi-0.3.1 → tradingapi-0.3.3}/tradingapi/dhan.py +0 -0
- {tradingapi-0.3.1 → tradingapi-0.3.3}/tradingapi/error_handling.py +0 -0
- {tradingapi-0.3.1 → tradingapi-0.3.3}/tradingapi/exceptions.py +0 -0
- {tradingapi-0.3.1 → tradingapi-0.3.3}/tradingapi/flattrade.py +0 -0
- {tradingapi-0.3.1 → tradingapi-0.3.3}/tradingapi/globals.py +0 -0
- {tradingapi-0.3.1 → tradingapi-0.3.3}/tradingapi/icicidirect.py +0 -0
- {tradingapi-0.3.1 → tradingapi-0.3.3}/tradingapi/icicidirect_generate_session.py +0 -0
- {tradingapi-0.3.1 → tradingapi-0.3.3}/tradingapi/market_data_exchanges.py +0 -0
- {tradingapi-0.3.1 → tradingapi-0.3.3}/tradingapi/proxy_utils.py +0 -0
- {tradingapi-0.3.1 → tradingapi-0.3.3}/tradingapi/shoonya.py +0 -0
- {tradingapi-0.3.1 → tradingapi-0.3.3}/tradingapi/span.py +0 -0
- {tradingapi-0.3.1 → tradingapi-0.3.3}/tradingapi.egg-info/SOURCES.txt +0 -0
- {tradingapi-0.3.1 → tradingapi-0.3.3}/tradingapi.egg-info/dependency_links.txt +0 -0
- {tradingapi-0.3.1 → tradingapi-0.3.3}/tradingapi.egg-info/entry_points.txt +0 -0
- {tradingapi-0.3.1 → tradingapi-0.3.3}/tradingapi.egg-info/requires.txt +0 -0
- {tradingapi-0.3.1 → tradingapi-0.3.3}/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
|
|
|
@@ -3247,7 +3247,7 @@ def find_option_with_delta(
|
|
|
3247
3247
|
valid_delta_count = 0
|
|
3248
3248
|
nan_delta_count = 0
|
|
3249
3249
|
nan_delta_strikes = [] # track strikes where delta could not be calculated
|
|
3250
|
-
# Cache so seeding sweep + binary search
|
|
3250
|
+
# Cache so seeding sweep + binary search never recompute the same strike.
|
|
3251
3251
|
delta_cache: dict[int, float] = {}
|
|
3252
3252
|
|
|
3253
3253
|
def _delta_at(idx: int) -> float:
|
|
@@ -3296,15 +3296,9 @@ def find_option_with_delta(
|
|
|
3296
3296
|
_consider(idx, ad)
|
|
3297
3297
|
|
|
3298
3298
|
if len(seed_samples) < 2:
|
|
3299
|
-
# Too few seeds; fall through to linear scan over the whole chain.
|
|
3300
|
-
for idx in range(n):
|
|
3301
|
-
d = _delta_at(idx)
|
|
3302
|
-
if math.isnan(d):
|
|
3303
|
-
continue
|
|
3304
|
-
_consider(idx, abs(d))
|
|
3305
3299
|
if best_index < 0:
|
|
3306
3300
|
trading_logger.log_warning(
|
|
3307
|
-
f"find_option_with_delta: no valid option strike found (
|
|
3301
|
+
f"find_option_with_delta: no valid option strike found (seed failure). "
|
|
3308
3302
|
f"price_f={price_f} target_delta={target_delta} return_lower_delta={return_lower_delta} "
|
|
3309
3303
|
f"chain_len={n} strike_range=[{strike_lo}, {strike_hi}] "
|
|
3310
3304
|
f"valid_delta_count={valid_delta_count} nan_delta_count={nan_delta_count} "
|
|
@@ -3333,7 +3327,7 @@ def find_option_with_delta(
|
|
|
3333
3327
|
if math.isnan(d):
|
|
3334
3328
|
alt = _nearest_valid(mid, left, right)
|
|
3335
3329
|
if alt < 0:
|
|
3336
|
-
# Wide NaN band
|
|
3330
|
+
# Wide NaN band: stop here instead of expanding into a full-chain scan.
|
|
3337
3331
|
break
|
|
3338
3332
|
eff_idx = alt
|
|
3339
3333
|
d = delta_cache[alt]
|
|
@@ -3351,17 +3345,6 @@ def find_option_with_delta(
|
|
|
3351
3345
|
else:
|
|
3352
3346
|
right = eff_idx - 1
|
|
3353
3347
|
|
|
3354
|
-
# --- Change 3: linear-scan fallback if binary search failed to land a best ---
|
|
3355
|
-
if best_index < 0:
|
|
3356
|
-
for idx in range(n):
|
|
3357
|
-
if idx in delta_cache:
|
|
3358
|
-
d = delta_cache[idx]
|
|
3359
|
-
else:
|
|
3360
|
-
d = _delta_at(idx)
|
|
3361
|
-
if math.isnan(d):
|
|
3362
|
-
continue
|
|
3363
|
-
_consider(idx, abs(d))
|
|
3364
|
-
|
|
3365
3348
|
if best_index < 0:
|
|
3366
3349
|
trading_logger.log_warning(
|
|
3367
3350
|
f"find_option_with_delta: no valid option strike found. "
|
|
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
|