while25 0.1.0__py3-none-any.whl

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 (50) hide show
  1. while25/__init__.py +341 -0
  2. while25/_costs/brokers/alpaca.json +96 -0
  3. while25/_costs/brokers/binance.json +34 -0
  4. while25/_costs/brokers/coinbase.json +34 -0
  5. while25/_costs/brokers/ibkr.json +39 -0
  6. while25/_costs/brokers/upstox.json +175 -0
  7. while25/_costs/brokers/zerodha.json +175 -0
  8. while25/_costs/crypto_alpaca.json +27 -0
  9. while25/_costs/global_crypto.json +18 -0
  10. while25/_costs/in_nse_equity.json +238 -0
  11. while25/_costs/in_nse_etf.json +352 -0
  12. while25/_costs/in_nse_fo.json +450 -0
  13. while25/_costs/us_crypto.json +18 -0
  14. while25/_costs/us_equity.json +175 -0
  15. while25/_costs/us_options.json +172 -0
  16. while25/_days.py +123 -0
  17. while25/_figures.py +233 -0
  18. while25/_runtime.py +49 -0
  19. while25/_universes/banknifty.json +80 -0
  20. while25/_universes/ndx100.json +520 -0
  21. while25/_universes/nifty50.json +260 -0
  22. while25/_universes/nifty500.json +2505 -0
  23. while25/_universes/sp500.json +2525 -0
  24. while25/assume.py +263 -0
  25. while25/backtest.py +881 -0
  26. while25/barline.py +160 -0
  27. while25/combo_legs.py +238 -0
  28. while25/errors.py +77 -0
  29. while25/fonts/IBMPlexMono-Regular.ttf +0 -0
  30. while25/fonts/IBMPlexMono-SemiBold.ttf +0 -0
  31. while25/fonts/Inter-Bold.ttf +0 -0
  32. while25/fonts/Inter-Regular.ttf +0 -0
  33. while25/fonts/Inter-SemiBold.ttf +0 -0
  34. while25/fonts/OFL-IBMPlexMono.txt +93 -0
  35. while25/fonts/OFL-Inter.txt +93 -0
  36. while25/future_pick.py +77 -0
  37. while25/inputs.py +215 -0
  38. while25/instruments.py +488 -0
  39. while25/modules.py +397 -0
  40. while25/money.py +24 -0
  41. while25/option_pick.py +221 -0
  42. while25/plots.py +147 -0
  43. while25/report.py +644 -0
  44. while25/ui.py +680 -0
  45. while25/universes.py +70 -0
  46. while25-0.1.0.dist-info/METADATA +3194 -0
  47. while25-0.1.0.dist-info/RECORD +50 -0
  48. while25-0.1.0.dist-info/WHEEL +5 -0
  49. while25-0.1.0.dist-info/licenses/LICENSE +201 -0
  50. while25-0.1.0.dist-info/top_level.txt +1 -0
while25/universes.py ADDED
@@ -0,0 +1,70 @@
1
+ """Index members from the terminal's constituent registry.
2
+
3
+ A pure file read — no engine round trip — of the same JSON the AI's
4
+ list_universe tool reads. Two layouts, checked in order:
5
+
6
+ in-tree $WHILE25_REGISTRY/universes (a source checkout)
7
+ bundled while25/_universes (staged into the package
8
+ by the client's build)
9
+
10
+ Reference data, dated. It is the honest answer to "the S&P 500 members":
11
+ IBKR resolves contracts on demand and holds no catalogue, and a script that
12
+ hard-codes 500 tickers is stale the day it is written.
13
+ """
14
+ from __future__ import annotations
15
+
16
+ import json
17
+ import os
18
+ from pathlib import Path
19
+
20
+ _IN_TREE = None # a test may point this at a directory; else $WHILE25_REGISTRY/universes
21
+ _BUNDLED = Path(__file__).resolve().parent / "_universes"
22
+
23
+
24
+ def _registry(name: str) -> "Path | None":
25
+ """A source checkout's registry folder: the terminal's runtime sets
26
+ WHILE25_REGISTRY; a pip install never does, and reads the bundled copy."""
27
+ root = os.environ.get("WHILE25_REGISTRY")
28
+ return Path(root, name) if root else None
29
+
30
+
31
+ def _dir() -> Path:
32
+ for d in (_IN_TREE or _registry("universes"), _BUNDLED):
33
+ if d and d.is_dir():
34
+ return d
35
+ raise RuntimeError(
36
+ "no constituent registry found — expected "
37
+ f"$WHILE25_REGISTRY/universes (source checkout) or {_BUNDLED} (bundled)"
38
+ )
39
+
40
+
41
+ def universes() -> list[str]:
42
+ """The index ids the registry holds, e.g. ['banknifty', 'ndx100', ...]."""
43
+ return sorted(p.stem for p in _dir().glob("*.json"))
44
+
45
+
46
+ def universe(index: str) -> list[dict]:
47
+ """Members of `index`: [{"symbol", "name", "canonical_id"}, ...].
48
+
49
+ Raises ValueError naming the ids that DO exist — never an empty list,
50
+ which a script would read as "the index has no members".
51
+ """
52
+ key = str(index).strip().lower()
53
+ path = _dir() / f"{key}.json"
54
+ if not path.is_file():
55
+ raise ValueError(
56
+ f"no registry for index {index!r}; available: {', '.join(universes())}")
57
+ doc = json.loads(path.read_text())
58
+ return [dict(symbol=r["symbol"], name=r["name"], canonical_id=r["canonical_id"])
59
+ for r in doc["rows"]]
60
+
61
+
62
+ def universe_info(index: str) -> dict:
63
+ """The registry's own header for `index`: name, country, as_of, source, count."""
64
+ key = str(index).strip().lower()
65
+ path = _dir() / f"{key}.json"
66
+ if not path.is_file():
67
+ raise ValueError(
68
+ f"no registry for index {index!r}; available: {', '.join(universes())}")
69
+ doc = json.loads(path.read_text())
70
+ return {k: doc[k] for k in ("index", "name", "country", "as_of", "source", "count")}