From c05445cf4a8038cfe8a0ca3e5ff86f830e07a68c Mon Sep 17 00:00:00 2001 From: hiohiohio Date: Fri, 11 Nov 2022 10:14:58 +0900 Subject: [PATCH] feat: support index endpoint (#34) * chore(workflow): update python version * feat: support index endpoint Fixes #33 --- README.md | 1 + jquantsapi/client.py | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/README.md b/README.md index e39863e..a0f6fe9 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,7 @@ J-Quants API の各APIエンドポイントに対応しています。 - get_listed_sections - get_market_segments - get_prices_daily_quotes + - get_indices_topix - get_markets_trades_spec - get_fins_statements - get_fins_announcement diff --git a/jquantsapi/client.py b/jquantsapi/client.py index 341000c..f1cfae8 100644 --- a/jquantsapi/client.py +++ b/jquantsapi/client.py @@ -614,6 +614,42 @@ def get_fins_statements( df.sort_values(["DisclosedUnixTime", "DisclosureNumber"], inplace=True) return df[cols] + def get_indices_topix( + self, + from_yyyymmdd: str = "", + to_yyyymmdd: str = "", + ) -> pd.DataFrame: + """ + TOPIX Daily OHLC + + Args: + from_yyyymmdd: starting point of data period (e.g. 20210901 or 2021-09-01) + to_yyyymmdd: end point of data period (e.g. 20210907 or 2021-09-07) + Returns: + pd.DataFrame: TOPIX Daily OHLC (Sorted by "Date" column) + """ + url = f"{self.JQUANTS_API_BASE}/indices/topix" + params = {} + if from_yyyymmdd != "": + params["from"] = from_yyyymmdd + if to_yyyymmdd != "": + params["to"] = to_yyyymmdd + ret = self._get(url, params) + d = ret.json() + df = pd.DataFrame.from_dict(d["topix"]) + cols = [ + "Date", + "Open", + "High", + "Low", + "Close", + ] + if len(df) == 0: + return pd.DataFrame([], columns=cols) + df.loc[:, "Date"] = pd.to_datetime(df["Date"], format="%Y%m%d") + df.sort_values(["Date"], inplace=True) + return df[cols] + def get_markets_trades_spec( self, section: Union[str, MARKET_API_SECTIONS] = "",