diff --git a/example.py b/example.py index 8d125e3..054cdf1 100644 --- a/example.py +++ b/example.py @@ -18,3 +18,6 @@ # Market and board info Market("stock", "shares").traded_boards() + +#Index composition +Index("IMOEX").composition() diff --git a/finec/moex.py b/finec/moex.py index b75b85c..3b662e8 100644 --- a/finec/moex.py +++ b/finec/moex.py @@ -79,7 +79,7 @@ "describe", "traded_boards", "Stock", - "Index", # need index composition, as in https://github.com/WLM1ke/apimoex/issues/12 + "Index", "Bond", "Currency", "get_stocks", @@ -326,6 +326,11 @@ class Index(Security): market: str = default("index") default_columns: ClassList = None + def composition(self): + # Implemented as in https://github.com/WLM1ke/apimoex/issues/12 + endpoint = f"/iss/statistics/engines/stock/markets/index/analytics/{self.ticker}" + return get_all(endpoint)['analytics'] + @dataclass class Currency(Security): diff --git a/tests/test_moex.py b/tests/test_moex.py index 145585d..a73d4a2 100644 --- a/tests/test_moex.py +++ b/tests/test_moex.py @@ -274,3 +274,6 @@ def test_usd_rur(): "WAPRICE": 31.1912, } ] + +def test_index_composition(): + assert "SBER" in [d['ticker'] for d in Index("IMOEX").composition()]