vortex-api 2.1.8b2__tar.gz → 2.1.8b4__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.
- {vortex_api-2.1.8b2/vortex_api.egg-info → vortex_api-2.1.8b4}/PKG-INFO +1 -1
- {vortex_api-2.1.8b2 → vortex_api-2.1.8b4}/pyproject.toml +1 -1
- vortex_api-2.1.8b4/vortex_api/__version__.py +1 -0
- {vortex_api-2.1.8b2 → vortex_api-2.1.8b4}/vortex_api/api.py +1 -1
- {vortex_api-2.1.8b2 → vortex_api-2.1.8b4}/vortex_api/instruments.py +207 -28
- {vortex_api-2.1.8b2 → vortex_api-2.1.8b4/vortex_api.egg-info}/PKG-INFO +1 -1
- vortex_api-2.1.8b2/vortex_api/__version__.py +0 -1
- {vortex_api-2.1.8b2 → vortex_api-2.1.8b4}/LICENSE +0 -0
- {vortex_api-2.1.8b2 → vortex_api-2.1.8b4}/README.md +0 -0
- {vortex_api-2.1.8b2 → vortex_api-2.1.8b4}/setup.cfg +0 -0
- {vortex_api-2.1.8b2 → vortex_api-2.1.8b4}/vortex_api/__init__.py +0 -0
- {vortex_api-2.1.8b2 → vortex_api-2.1.8b4}/vortex_api/backtest/__init__.py +0 -0
- {vortex_api-2.1.8b2 → vortex_api-2.1.8b4}/vortex_api/backtest/_backtestingpy.py +0 -0
- {vortex_api-2.1.8b2 → vortex_api-2.1.8b4}/vortex_api/backtest/_backtrader.py +0 -0
- {vortex_api-2.1.8b2 → vortex_api-2.1.8b4}/vortex_api/backtest/_common.py +0 -0
- {vortex_api-2.1.8b2 → vortex_api-2.1.8b4}/vortex_api/backtest/_vectorbt.py +0 -0
- {vortex_api-2.1.8b2 → vortex_api-2.1.8b4}/vortex_api/vortex_feed.py +0 -0
- {vortex_api-2.1.8b2 → vortex_api-2.1.8b4}/vortex_api.egg-info/SOURCES.txt +0 -0
- {vortex_api-2.1.8b2 → vortex_api-2.1.8b4}/vortex_api.egg-info/dependency_links.txt +0 -0
- {vortex_api-2.1.8b2 → vortex_api-2.1.8b4}/vortex_api.egg-info/requires.txt +0 -0
- {vortex_api-2.1.8b2 → vortex_api-2.1.8b4}/vortex_api.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "2.1.8b4"
|
|
@@ -649,7 +649,7 @@ class VortexAPI:
|
|
|
649
649
|
https://vortex.rupeezy.in/docs/latest/historical/#fetch-price-quotes
|
|
650
650
|
|
|
651
651
|
Args:
|
|
652
|
-
instrument(list): List of
|
|
652
|
+
instrument(list): List of instrument tickers. The items should be like ( "NSE:RELIANCE", "NSE:NIFTYIDX")
|
|
653
653
|
mode(Constants.QuoteModes): Quote mode. Can be ["ltp","ohlcv", "full"]. LTP quotes just give the last trade price, ohlc give open, high, low, close and volume, full mode also gives depth.
|
|
654
654
|
|
|
655
655
|
Returns:
|
|
@@ -20,6 +20,33 @@ Typical use::
|
|
|
20
20
|
|
|
21
21
|
# All option contracts under NIFTY
|
|
22
22
|
chain = client.instruments.all_by_underlying("NSE_FO", "NIFTY")
|
|
23
|
+
|
|
24
|
+
Environment variables (all optional — the SDK works with zero config)
|
|
25
|
+
---------------------------------------------------------------------
|
|
26
|
+
|
|
27
|
+
The SDK reads these at ``InstrumentManager()`` construction so that infra
|
|
28
|
+
changes (mounting a shared volume, switching to an internal mirror, etc.)
|
|
29
|
+
take effect immediately on the next pod restart — no code change required.
|
|
30
|
+
|
|
31
|
+
``PYVORTEX_CACHE_DIR``
|
|
32
|
+
Directory for the on-disk cache. Set this when running in containers
|
|
33
|
+
with read-only root filesystems or when you want to point at a shared
|
|
34
|
+
volume (e.g. EFS) so the entire fleet shares one ``master.csv``.
|
|
35
|
+
Default: ``$XDG_CACHE_HOME/pyvortex`` or ``~/.cache/pyvortex`` or
|
|
36
|
+
``/tmp/pyvortex`` (first writable wins).
|
|
37
|
+
|
|
38
|
+
``PYVORTEX_MASTER_URL``
|
|
39
|
+
Override the URL used to download ``master.csv``. Point this at an
|
|
40
|
+
internal S3 mirror or pre-warmed CDN to keep fleet-wide traffic off
|
|
41
|
+
the public origin. Default: ``https://static.rupeezy.in/master.csv``.
|
|
42
|
+
|
|
43
|
+
``PYVORTEX_REVALIDATE_SECONDS``
|
|
44
|
+
How long (in seconds) to trust the disk cache before issuing a
|
|
45
|
+
conditional GET. Default: 900 (15 minutes). Set to ``0`` to revalidate
|
|
46
|
+
on every load.
|
|
47
|
+
|
|
48
|
+
``PYVORTEX_REQUEST_TIMEOUT``
|
|
49
|
+
HTTP request timeout in seconds for the master download. Default: 30.
|
|
23
50
|
"""
|
|
24
51
|
|
|
25
52
|
from __future__ import annotations
|
|
@@ -40,11 +67,34 @@ import requests
|
|
|
40
67
|
|
|
41
68
|
DEFAULT_MASTER_URL = "https://static.rupeezy.in/master.csv"
|
|
42
69
|
DEFAULT_REVALIDATE_AFTER_SECONDS = 15 * 60 # how long to trust disk before conditional GET
|
|
70
|
+
DEFAULT_REQUEST_TIMEOUT_SECONDS = 30.0
|
|
43
71
|
_IST_OFFSET = datetime.timedelta(hours=5, minutes=30)
|
|
44
72
|
|
|
45
73
|
logger = logging.getLogger(__name__)
|
|
46
74
|
|
|
47
75
|
|
|
76
|
+
def _env_int(name: str, default: int) -> int:
|
|
77
|
+
raw = os.environ.get(name)
|
|
78
|
+
if raw is None or raw == "":
|
|
79
|
+
return default
|
|
80
|
+
try:
|
|
81
|
+
return int(raw)
|
|
82
|
+
except ValueError:
|
|
83
|
+
logger.warning("pyvortex: ignoring invalid %s=%r (expected int)", name, raw)
|
|
84
|
+
return default
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def _env_float(name: str, default: float) -> float:
|
|
88
|
+
raw = os.environ.get(name)
|
|
89
|
+
if raw is None or raw == "":
|
|
90
|
+
return default
|
|
91
|
+
try:
|
|
92
|
+
return float(raw)
|
|
93
|
+
except ValueError:
|
|
94
|
+
logger.warning("pyvortex: ignoring invalid %s=%r (expected float)", name, raw)
|
|
95
|
+
return default
|
|
96
|
+
|
|
97
|
+
|
|
48
98
|
class InstrumentNotFound(Exception):
|
|
49
99
|
"""Raised when a lookup cannot find the requested instrument."""
|
|
50
100
|
|
|
@@ -97,41 +147,87 @@ def _now_ist() -> datetime.datetime:
|
|
|
97
147
|
|
|
98
148
|
|
|
99
149
|
def _default_cache_path() -> str:
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
)
|
|
103
|
-
|
|
150
|
+
"""Resolve where to cache ``master.csv``.
|
|
151
|
+
|
|
152
|
+
Resolution order (first usable wins):
|
|
153
|
+
|
|
154
|
+
1. ``$PYVORTEX_CACHE_DIR`` — explicit override, recommended for containers
|
|
155
|
+
and multi-process deployments where you want to point at a shared volume.
|
|
156
|
+
2. ``$XDG_CACHE_HOME`` — standard XDG location.
|
|
157
|
+
3. ``~/.cache`` — only if ``$HOME`` is set and not ``/``.
|
|
158
|
+
4. ``/tmp`` — last-resort fallback for containers/serverless where the
|
|
159
|
+
above are unavailable. Survives the process but not the container.
|
|
160
|
+
"""
|
|
161
|
+
explicit = os.environ.get("PYVORTEX_CACHE_DIR")
|
|
162
|
+
if explicit:
|
|
163
|
+
return os.path.join(explicit, "master.csv")
|
|
164
|
+
|
|
165
|
+
xdg = os.environ.get("XDG_CACHE_HOME")
|
|
166
|
+
if xdg:
|
|
167
|
+
return os.path.join(xdg, "pyvortex", "master.csv")
|
|
168
|
+
|
|
169
|
+
home = os.environ.get("HOME")
|
|
170
|
+
if home and home not in ("/", ""):
|
|
171
|
+
expanded = os.path.expanduser("~")
|
|
172
|
+
# ``expanduser`` returns ``~`` verbatim when no home can be resolved
|
|
173
|
+
# (e.g. distroless container, no /etc/passwd entry). Guard against that.
|
|
174
|
+
if expanded != "~":
|
|
175
|
+
return os.path.join(expanded, ".cache", "pyvortex", "master.csv")
|
|
176
|
+
|
|
177
|
+
return os.path.join(tempfile.gettempdir(), "pyvortex", "master.csv")
|
|
104
178
|
|
|
105
179
|
|
|
106
180
|
class InstrumentManager:
|
|
107
181
|
"""Thread-safe, lazily-loaded instruments cache.
|
|
108
182
|
|
|
109
183
|
Args:
|
|
110
|
-
master_url: Override the master CSV URL
|
|
111
|
-
|
|
112
|
-
|
|
184
|
+
master_url: Override the master CSV URL. Falls back to the
|
|
185
|
+
``PYVORTEX_MASTER_URL`` env var, then to the public default.
|
|
186
|
+
cache_path: Where to persist the downloaded master file. Falls back to
|
|
187
|
+
the ``PYVORTEX_CACHE_DIR`` env var, then to ``~/.cache/pyvortex/master.csv``
|
|
188
|
+
(or ``/tmp/pyvortex/master.csv`` if HOME isn't writable).
|
|
113
189
|
enable_disk_cache: If ``False``, every load re-downloads. Default ``True``.
|
|
114
|
-
|
|
190
|
+
Mostly useful for tests; in production prefer mounting a writable
|
|
191
|
+
volume and letting the cache do its job.
|
|
192
|
+
request_timeout: HTTP request timeout in seconds. Falls back to
|
|
193
|
+
``PYVORTEX_REQUEST_TIMEOUT``. Default 30.
|
|
115
194
|
revalidate_after_seconds: How long to trust the disk cache without
|
|
116
|
-
re-checking the server.
|
|
117
|
-
issues a conditional GET using ``If-None-Match`` / ``If-Modified-Since``.
|
|
118
|
-
A ``304`` response keeps the disk cache; a ``200`` swaps it in.
|
|
195
|
+
re-checking the server. Falls back to ``PYVORTEX_REVALIDATE_SECONDS``.
|
|
119
196
|
Default 900 (15 minutes). Set to 0 to revalidate on every load.
|
|
197
|
+
|
|
198
|
+
Explicit Python arguments always win over env vars; env vars win over
|
|
199
|
+
built-in defaults. This lets operators tune behaviour from the pod spec
|
|
200
|
+
while still letting tests pass explicit values.
|
|
120
201
|
"""
|
|
121
202
|
|
|
122
203
|
def __init__(
|
|
123
204
|
self,
|
|
124
|
-
master_url: str =
|
|
205
|
+
master_url: Optional[str] = None,
|
|
125
206
|
cache_path: Optional[str] = None,
|
|
126
|
-
enable_disk_cache: bool =
|
|
127
|
-
request_timeout: float =
|
|
128
|
-
revalidate_after_seconds: int =
|
|
207
|
+
enable_disk_cache: Optional[bool] = None,
|
|
208
|
+
request_timeout: Optional[float] = None,
|
|
209
|
+
revalidate_after_seconds: Optional[int] = None,
|
|
129
210
|
) -> None:
|
|
130
|
-
self._master_url =
|
|
211
|
+
self._master_url = (
|
|
212
|
+
master_url
|
|
213
|
+
or os.environ.get("PYVORTEX_MASTER_URL")
|
|
214
|
+
or DEFAULT_MASTER_URL
|
|
215
|
+
)
|
|
131
216
|
self._cache_path = cache_path or _default_cache_path()
|
|
132
217
|
self._meta_path = self._cache_path + ".meta.json"
|
|
133
|
-
|
|
134
|
-
self.
|
|
218
|
+
|
|
219
|
+
self._enable_disk_cache = True if enable_disk_cache is None else bool(enable_disk_cache)
|
|
220
|
+
|
|
221
|
+
self._request_timeout = (
|
|
222
|
+
request_timeout
|
|
223
|
+
if request_timeout is not None
|
|
224
|
+
else _env_float("PYVORTEX_REQUEST_TIMEOUT", DEFAULT_REQUEST_TIMEOUT_SECONDS)
|
|
225
|
+
)
|
|
226
|
+
|
|
227
|
+
if revalidate_after_seconds is None:
|
|
228
|
+
revalidate_after_seconds = _env_int(
|
|
229
|
+
"PYVORTEX_REVALIDATE_SECONDS", DEFAULT_REVALIDATE_AFTER_SECONDS
|
|
230
|
+
)
|
|
135
231
|
self._revalidate_after_seconds = max(0, int(revalidate_after_seconds))
|
|
136
232
|
|
|
137
233
|
self._lock = threading.RLock()
|
|
@@ -141,6 +237,13 @@ class InstrumentManager:
|
|
|
141
237
|
self._last_loaded_at: Optional[datetime.datetime] = None
|
|
142
238
|
self._loaded = False
|
|
143
239
|
|
|
240
|
+
# Container-safety: if the configured cache path can't be written
|
|
241
|
+
# (read-only rootfs is common on EKS / Cloud Run / Lambda), we transparently
|
|
242
|
+
# fall back to a path under the OS temp dir. The fallback is computed
|
|
243
|
+
# lazily and remembered so we don't spam logs.
|
|
244
|
+
self._disk_disabled = False # set True if even the /tmp fallback fails
|
|
245
|
+
self._fallback_announced = False
|
|
246
|
+
|
|
144
247
|
# ------------------------------------------------------------------ Public
|
|
145
248
|
|
|
146
249
|
def load(self, force: bool = False) -> int:
|
|
@@ -176,15 +279,25 @@ class InstrumentManager:
|
|
|
176
279
|
|
|
177
280
|
# (3) Otherwise issue a conditional GET.
|
|
178
281
|
if csv_text is None:
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
282
|
+
try:
|
|
283
|
+
csv_text, new_meta = self._conditional_download(meta)
|
|
284
|
+
except requests.RequestException as exc:
|
|
285
|
+
# Network down but we have a usable disk cache — serve stale.
|
|
286
|
+
logger.warning(
|
|
287
|
+
"pyvortex: conditional refresh of instruments failed (%s). "
|
|
288
|
+
"Serving stale copy from disk cache (%s).",
|
|
289
|
+
exc, self._cache_path,
|
|
290
|
+
)
|
|
182
291
|
csv_text = self._read_disk_cache()
|
|
183
|
-
self._touch_meta(meta, new_meta)
|
|
184
292
|
else:
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
293
|
+
if csv_text is None:
|
|
294
|
+
# 304 path — disk is still current.
|
|
295
|
+
csv_text = self._read_disk_cache()
|
|
296
|
+
self._touch_meta(meta, new_meta)
|
|
297
|
+
else:
|
|
298
|
+
# 200 path — write through.
|
|
299
|
+
self._write_disk_cache(csv_text)
|
|
300
|
+
self._write_meta(new_meta)
|
|
188
301
|
|
|
189
302
|
if csv_text is None:
|
|
190
303
|
# (4) No usable disk cache, or force=True.
|
|
@@ -277,7 +390,16 @@ class InstrumentManager:
|
|
|
277
390
|
return None
|
|
278
391
|
|
|
279
392
|
def _write_disk_cache(self, csv_text: str) -> None:
|
|
280
|
-
|
|
393
|
+
try:
|
|
394
|
+
new_path = self._atomic_write_with_fallback(self._cache_path, csv_text)
|
|
395
|
+
except OSError:
|
|
396
|
+
# The fallback helper already emitted a one-time warning explaining
|
|
397
|
+
# what happened. Disk cache is now disabled; in-memory still works.
|
|
398
|
+
return
|
|
399
|
+
if new_path != self._cache_path:
|
|
400
|
+
# Disk cache moved — repoint everything so future loads use it.
|
|
401
|
+
self._cache_path = new_path
|
|
402
|
+
self._meta_path = new_path + ".meta.json"
|
|
281
403
|
|
|
282
404
|
def _read_meta(self) -> Optional[Dict[str, str]]:
|
|
283
405
|
if not os.path.exists(self._meta_path):
|
|
@@ -292,10 +414,12 @@ class InstrumentManager:
|
|
|
292
414
|
return None
|
|
293
415
|
|
|
294
416
|
def _write_meta(self, meta: Dict[str, str]) -> None:
|
|
417
|
+
# Meta is small; on failure we silently skip it. Without meta the next
|
|
418
|
+
# process will lose conditional-GET capability but still works correctly.
|
|
295
419
|
try:
|
|
296
|
-
self.
|
|
420
|
+
self._atomic_write_with_fallback(self._meta_path, json.dumps(meta))
|
|
297
421
|
except OSError as exc:
|
|
298
|
-
logger.
|
|
422
|
+
logger.debug("Skipping instruments meta write (%s): %s", self._meta_path, exc)
|
|
299
423
|
|
|
300
424
|
def _touch_meta(self, old: Dict[str, str], new: Dict[str, str]) -> None:
|
|
301
425
|
"""Merge ``new`` validation timestamp / headers into ``old`` and persist."""
|
|
@@ -319,6 +443,61 @@ class InstrumentManager:
|
|
|
319
443
|
pass
|
|
320
444
|
raise
|
|
321
445
|
|
|
446
|
+
def _atomic_write_with_fallback(self, path: str, text: str) -> str:
|
|
447
|
+
"""Atomic write with auto-fallback to ``/tmp`` on read-only filesystems.
|
|
448
|
+
|
|
449
|
+
Returns the path that was actually written. If even the fallback fails,
|
|
450
|
+
the disk cache is disabled for this manager and a one-time warning is
|
|
451
|
+
emitted; subsequent loads still work from memory.
|
|
452
|
+
"""
|
|
453
|
+
try:
|
|
454
|
+
self._atomic_write(path, text)
|
|
455
|
+
return path
|
|
456
|
+
except OSError as primary_exc:
|
|
457
|
+
# Try /tmp as a fallback — this covers EKS readOnlyRootFilesystem,
|
|
458
|
+
# Cloud Run, Lambda, and similar locked-down container setups.
|
|
459
|
+
fallback_dir = os.path.join(tempfile.gettempdir(), "pyvortex")
|
|
460
|
+
fallback_path = os.path.join(
|
|
461
|
+
fallback_dir, os.path.basename(path)
|
|
462
|
+
)
|
|
463
|
+
if fallback_path == path:
|
|
464
|
+
# Already trying /tmp — give up gracefully.
|
|
465
|
+
self._announce_disk_disabled(path, primary_exc)
|
|
466
|
+
raise
|
|
467
|
+
try:
|
|
468
|
+
self._atomic_write(fallback_path, text)
|
|
469
|
+
except OSError as fallback_exc:
|
|
470
|
+
self._announce_disk_disabled(path, fallback_exc)
|
|
471
|
+
raise
|
|
472
|
+
self._announce_fallback(path, fallback_path, primary_exc)
|
|
473
|
+
return fallback_path
|
|
474
|
+
|
|
475
|
+
def _announce_fallback(
|
|
476
|
+
self, original: str, fallback: str, exc: OSError
|
|
477
|
+
) -> None:
|
|
478
|
+
if self._fallback_announced:
|
|
479
|
+
return
|
|
480
|
+
self._fallback_announced = True
|
|
481
|
+
logger.warning(
|
|
482
|
+
"pyvortex: cannot write instruments cache to %s (%s). "
|
|
483
|
+
"Falling back to %s for the rest of this process. "
|
|
484
|
+
"To silence this warning in containers, set "
|
|
485
|
+
"PYVORTEX_CACHE_DIR=/tmp/pyvortex (or any writable path).",
|
|
486
|
+
original, exc, fallback,
|
|
487
|
+
)
|
|
488
|
+
|
|
489
|
+
def _announce_disk_disabled(self, path: str, exc: OSError) -> None:
|
|
490
|
+
if self._disk_disabled:
|
|
491
|
+
return
|
|
492
|
+
self._disk_disabled = True
|
|
493
|
+
logger.warning(
|
|
494
|
+
"pyvortex: disk cache disabled (could not write to %s or its fallback: %s). "
|
|
495
|
+
"Instruments will be loaded into memory only — expect a fresh download "
|
|
496
|
+
"from %s every time this process starts. To fix, mount a writable "
|
|
497
|
+
"volume and set PYVORTEX_CACHE_DIR to point at it.",
|
|
498
|
+
path, exc, self._master_url,
|
|
499
|
+
)
|
|
500
|
+
|
|
322
501
|
# ---- freshness ----
|
|
323
502
|
|
|
324
503
|
def _within_revalidation_cooldown(self, meta: Dict[str, str]) -> bool:
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "2.1.8b2"
|
|
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
|