Skip to content

Commit

Permalink
feat: support index endpoint (#34)
Browse files Browse the repository at this point in the history
* chore(workflow): update python version

* feat: support index endpoint
Fixes #33
  • Loading branch information
hiohiohio authored Nov 11, 2022
1 parent c511deb commit c05445c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 36 additions & 0 deletions jquantsapi/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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] = "",
Expand Down

0 comments on commit c05445c

Please sign in to comment.