Skip to content

Commit 646d8fe

Browse files
s-meitomahiohiohio
andauthored
feat: add support for the paid version (#65)
* APIURL変更 * feat: add raw data interfaces (#53) * feat: add raw data interfaces * fix: fix unittest * fix: disable fail-fast for ci test * fix: change raw interface into private * fix: fix poetry.lock (#56) * fix: fix poetry.lock * fix: update poetry.lock * fix: fix dependencies * fix: bump pytest/mypy version * feat: update workflow (#57) * feat: add user-agent header (#58) Co-authored-by: s-meitoma <[email protected]> * fix: adjust dtypes for get_statements_range cache (#63) 有償版対応(β版既存API) test fix make lint * linter fix --------- Co-authored-by: hiohiohio <[email protected]>
1 parent cb5bfef commit 646d8fe

File tree

3 files changed

+172
-25
lines changed

3 files changed

+172
-25
lines changed

jquantsapi/client.py

+11-9
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class Client:
4141
ref. https://jpx.gitbook.io/j-quants-api/
4242
"""
4343

44-
JQUANTS_API_BASE = "https://api.jpx-jquants.com/v1"
44+
JQUANTS_API_BASE = "https://api.jquants.com/v1"
4545
MAX_WORKERS = 5
4646
USER_AGENT = "jqapi-python"
4747
USER_AGENT_VERSION = "0.0.0"
@@ -390,7 +390,7 @@ def get_listed_info(self, code: str = "", date_yyyymmdd: str = "") -> pd.DataFra
390390
cols = constants.LISTED_INFO_COLUMNS
391391
if len(df) == 0:
392392
return pd.DataFrame([], columns=cols)
393-
df["Date"] = pd.to_datetime(df["Date"], format="%Y%m%d")
393+
df["Date"] = pd.to_datetime(df["Date"], format="%Y-%m-%d")
394394
df.sort_values("Code", inplace=True)
395395
return df[cols]
396396

@@ -569,9 +569,11 @@ def get_prices_daily_quotes(
569569
cols = constants.PRICES_DAILY_QUOTES_COLUMNS
570570
if len(df) == 0:
571571
return pd.DataFrame([], columns=cols)
572-
df["Date"] = pd.to_datetime(df["Date"], format="%Y%m%d")
572+
df["Date"] = pd.to_datetime(df["Date"], format="%Y-%m-%d")
573573
df.sort_values(["Code", "Date"], inplace=True)
574-
return df[cols]
574+
df = df.reindex(columns=cols)
575+
576+
return df
575577

576578
def get_price_range(
577579
self,
@@ -595,7 +597,7 @@ def get_price_range(
595597
with ThreadPoolExecutor(max_workers=self.MAX_WORKERS) as executor:
596598
futures = [
597599
executor.submit(
598-
self.get_prices_daily_quotes, date_yyyymmdd=s.strftime("%Y%m%d")
600+
self.get_prices_daily_quotes, date_yyyymmdd=s.strftime("%Y-%m-%d")
599601
)
600602
for s in dates
601603
]
@@ -654,7 +656,7 @@ def get_fins_statements(
654656
df["CurrentFiscalYearEndDate"] = pd.to_datetime(
655657
df["CurrentFiscalYearEndDate"], format="%Y-%m-%d"
656658
)
657-
df.sort_values(["DisclosedUnixTime", "DisclosureNumber"], inplace=True)
659+
df.sort_values(["DisclosureNumber"], inplace=True)
658660
return df[cols]
659661

660662
def _get_indices_topix_raw(
@@ -703,7 +705,7 @@ def get_indices_topix(
703705
cols = constants.INDICES_TOPIX_COLUMNS
704706
if len(df) == 0:
705707
return pd.DataFrame([], columns=cols)
706-
df["Date"] = pd.to_datetime(df["Date"], format="%Y%m%d")
708+
df["Date"] = pd.to_datetime(df["Date"], format="%Y-%m-%d")
707709
df.sort_values(["Date"], inplace=True)
708710
return df[cols]
709711

@@ -815,7 +817,7 @@ def get_statements_range(
815817
cache_dir: CSV形式のキャッシュファイルが存在するディレクトリ
816818
817819
Returns:
818-
pd.DataFrame: 財務情報 (DisclosedUnixTime列、DisclosureNumber列でソートされています)
820+
pd.DataFrame: 財務情報 (DisclosureNumber列でソートされています)
819821
"""
820822
# pre-load id_token
821823
self.get_id_token()
@@ -863,4 +865,4 @@ def get_statements_range(
863865
# write cache file
864866
df.to_csv(f"{cache_dir}/{yyyy}/{cache_file}", index=False)
865867

866-
return pd.concat(buff).sort_values(["DisclosedUnixTime", "DisclosureNumber"])
868+
return pd.concat(buff).sort_values(["DisclosureNumber"])

jquantsapi/constants.py

+156-11
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,10 @@
8989

9090
# ref. ja https://jpx.gitbook.io/j-quants-api/api-reference/prices-api#no
9191
# ref. en https://jpx.gitbook.io/j-quants-api-en/api-reference/prices-api#daily-stock-price-information
92+
9293
PRICES_DAILY_QUOTES_COLUMNS = [
93-
"Code",
9494
"Date",
95+
"Code",
9596
"Open",
9697
"High",
9798
"Low",
@@ -104,6 +105,27 @@
104105
"AdjustmentLow",
105106
"AdjustmentClose",
106107
"AdjustmentVolume",
108+
"MorningOpen",
109+
"MorningHigh",
110+
"MorningLow",
111+
"MorningClose",
112+
"MorningVolume",
113+
"MorningTurnoverValue",
114+
"MorningAdjustmentOpen",
115+
"MorningAdjustmentHigh",
116+
"MorningAdjustmentLow",
117+
"MorningAdjustmentClose",
118+
"MorningAdjustmentVolume",
119+
"AfternoonOpen",
120+
"AfternoonHigh",
121+
"AfternoonLow",
122+
"AfternoonClose",
123+
"AfternoonVolume",
124+
"AfternoonAdjustmentOpen",
125+
"AfternoonAdjustmentHigh",
126+
"AfternoonAdjustmentLow",
127+
"AfternoonAdjustmentClose",
128+
"AfternoonAdjustmentVolume",
107129
]
108130

109131
# ref. ja https://jpx.gitbook.io/j-quants-api/api-reference/indices#notopix
@@ -185,16 +207,139 @@
185207
"MarketCodeNameEnglish",
186208
]
187209
MARKET_SEGMENT_DATA = [
188-
("101", "東証一部", "1st Section"),
189-
("102", "東証二部", "2nd Section"),
190-
("104", "マザーズ", "Mothers"),
191-
("105", "TOKYO PRO MARKET", "TOKYO PRO MARKET"),
192-
("106", "JASDAQ スタンダード", "JASDAQ Standard"),
193-
("107", "JASDAQ グロース", "JASDAQ Growth"),
194-
("109", "その他", "Others"),
195-
("111", "プライム", "Prime"),
196-
("112", "スタンダード", "Standard"),
197-
("113", "グロース", "Growth"),
210+
("0101", "東証一部", "1st Section"),
211+
("0102", "東証二部", "2nd Section"),
212+
("0104", "マザーズ", "Mothers"),
213+
("0105", "TOKYO PRO MARKET", "TOKYO PRO MARKET"),
214+
("0106", "JASDAQ スタンダード", "JASDAQ Standard"),
215+
("0107", "JASDAQ グロース", "JASDAQ Growth"),
216+
("0109", "その他", "Others"),
217+
("0111", "プライム", "Prime"),
218+
("0112", "スタンダード", "Standard"),
219+
("0113", "グロース", "Growth"),
220+
]
221+
222+
# ref ja https://jpx.gitbook.io/j-quants-api/api-reference/finance-api#no
223+
# ref en https://jpx.gitbook.io/j-quants-api-en/api-reference/finance-api#financial-information-for-the-quarter
224+
FINS_STATEMENTS_COLUMNS = [
225+
"DisclosedDate",
226+
"DisclosedTime",
227+
"LocalCode",
228+
"DisclosureNumber",
229+
"TypeOfDocument",
230+
"TypeOfCurrentPeriod",
231+
"CurrentPeriodStartDate",
232+
"CurrentPeriodEndDate",
233+
"CurrentFiscalYearStartDate",
234+
"CurrentFiscalYearEndDate",
235+
"NextFiscalYearStartDate",
236+
"NextFiscalYearEndDate",
237+
"NetSales",
238+
"OperatingProfit",
239+
"OrdinaryProfit",
240+
"Profit",
241+
"EarningsPerShare",
242+
"DilutedEarningsPerShare",
243+
"TotalAssets",
244+
"Equity",
245+
"EquityToAssetRatio",
246+
"BookValuePerShare",
247+
"CashFlowsFromOperatingActivities",
248+
"CashFlowsFromInvestingActivities",
249+
"CashFlowsFromFinancingActivities",
250+
"CashAndEquivalents",
251+
"ResultDividendPerShare1stQuarter",
252+
"ResultDividendPerShare2ndQuarter",
253+
"ResultDividendPerShare3rdQuarter",
254+
"ResultDividendPerShareFiscalYearEnd",
255+
"ResultDividendPerShareAnnual",
256+
"DistributionsPerUnit(REIT)",
257+
"ResultTotalDividendPaidAnnual",
258+
"ResultPayoutRatioAnnual",
259+
"ForecastDividendPerShare1stQuarter",
260+
"ForecastDividendPerShare2ndQuarter",
261+
"ForecastDividendPerShare3rdQuarter",
262+
"ForecastDividendPerShareFiscalYearEnd",
263+
"ForecastDividendPerShareAnnual",
264+
"ForecastDistributionsPerUnit(REIT)",
265+
"ForecastTotalDividendPaidAnnual",
266+
"ForecastPayoutRatioAnnual",
267+
"NextYearForecastDividendPerShare1stQuarter",
268+
"NextYearForecastDividendPerShare2ndQuarter",
269+
"NextYearForecastDividendPerShare3rdQuarter",
270+
"NextYearForecastDividendPerShareFiscalYearEnd",
271+
"NextYearForecastDividendPerShareAnnual",
272+
"NextYearForecastDistributionsPerUnit(REIT)",
273+
"NextYearForecastPayoutRatioAnnual",
274+
"ForecastNetSales2ndQuarter",
275+
"ForecastOperatingProfit2ndQuarter",
276+
"ForecastOrdinaryProfit2ndQuarter",
277+
"ForecastProfit2ndQuarter",
278+
"ForecastEarningsPerShare2ndQuarter",
279+
"NextYearForecastNetSales2ndQuarter",
280+
"NextYearForecastOperatingProfit2ndQuarter",
281+
"NextYearForecastOrdinaryProfit2ndQuarter",
282+
"NextYearForecastProfit2ndQuarter",
283+
"NextYearForecastEarningsPerShare2ndQuarter",
284+
"ForecastNetSales",
285+
"ForecastOperatingProfit",
286+
"ForecastOrdinaryProfit",
287+
"ForecastProfit",
288+
"ForecastEarningsPerShare",
289+
"NextYearForecastNetSales",
290+
"NextYearForecastOperatingProfit",
291+
"NextYearForecastOrdinaryProfit",
292+
"NextYearForecastProfit",
293+
"NextYearForecastEarningsPerShare",
294+
"MaterialChangesInSubsidiaries",
295+
"ChangesBasedOnRevisionsOfAccountingStandard",
296+
"ChangesOtherThanOnesBasedOnRevisionsOfAccountingStandard",
297+
"ChangesInAccountingEstimates",
298+
"RetrospectiveRestatement",
299+
"NumberOfIssuedAndOutstandingSharesAtTheEndOfFiscalYearIncludingTreasuryStock",
300+
"NumberOfTreasuryStockAtTheEndOfFiscalYear",
301+
"AverageNumberOfShares",
302+
"NonConsolidatedNetSales",
303+
"NonConsolidatedOperatingProfit",
304+
"NonConsolidatedOrdinaryProfit",
305+
"NonConsolidatedProfit",
306+
"NonConsolidatedEarningsPerShare",
307+
"NonConsolidatedTotalAssets",
308+
"NonConsolidatedEquity",
309+
"NonConsolidatedEquityToAssetRatio",
310+
"NonConsolidatedBookValuePerShare",
311+
"ForecastNonConsolidatedNetSales2ndQuarter",
312+
"ForecastNonConsolidatedOperatingProfit2ndQuarter",
313+
"ForecastNonConsolidatedOrdinaryProfit2ndQuarter",
314+
"ForecastNonConsolidatedProfit2ndQuarter",
315+
"ForecastNonConsolidatedEarningsPerShare2ndQuarter",
316+
"NextYearForecastNonConsolidatedNetSales2ndQuarter",
317+
"NextYearForecastNonConsolidatedOperatingProfit2ndQuarter",
318+
"NextYearForecastNonConsolidatedOrdinaryProfit2ndQuarter",
319+
"NextYearForecastNonConsolidatedProfit2ndQuarter",
320+
"NextYearForecastNonConsolidatedEarningsPerShare2ndQuarter",
321+
"ForecastNonConsolidatedNetSales",
322+
"ForecastNonConsolidatedOperatingProfit",
323+
"ForecastNonConsolidatedOrdinaryProfit",
324+
"ForecastNonConsolidatedProfit",
325+
"ForecastNonConsolidatedEarningsPerShare",
326+
"NextYearForecastNonConsolidatedNetSales",
327+
"NextYearForecastNonConsolidatedOperatingProfit",
328+
"NextYearForecastNonConsolidatedOrdinaryProfit",
329+
"NextYearForecastNonConsolidatedProfit",
330+
"NextYearForecastNonConsolidatedEarningsPerShare",
331+
]
332+
333+
# ref. ja https://jpx.gitbook.io/j-quants-api/api-reference/finance-api#jue-suan-fa-biao-yu-ding-ri
334+
# ref. en https://jpx.gitbook.io/j-quants-api-en/api-reference/finance-api#schedule-of-financial-announcement
335+
FINS_ANNOUNCEMENT_COLUMNS = [
336+
"Code",
337+
"Date",
338+
"CompanyName",
339+
"FiscalYear",
340+
"SectorName",
341+
"FiscalQuarter",
342+
"Section",
198343
]
199344

200345
# ref ja https://jpx.gitbook.io/j-quants-api/api-reference/finance-api#no

tests/test_client.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -308,10 +308,10 @@ def test_get_price_range():
308308

309309
# 呼び出しの履歴と、get_prices_daily_quotes()が呼ばれた際の年月日8桁の引数を比較
310310
assert mock.mock_calls == [
311-
call.get_prices_daily_quotes(date_yyyymmdd="20200227"),
312-
call.get_prices_daily_quotes(date_yyyymmdd="20200228"),
313-
call.get_prices_daily_quotes(date_yyyymmdd="20200229"),
314-
call.get_prices_daily_quotes(date_yyyymmdd="20200301"),
315-
call.get_prices_daily_quotes(date_yyyymmdd="20200302"),
311+
call.get_prices_daily_quotes(date_yyyymmdd="2020-02-27"),
312+
call.get_prices_daily_quotes(date_yyyymmdd="2020-02-28"),
313+
call.get_prices_daily_quotes(date_yyyymmdd="2020-02-29"),
314+
call.get_prices_daily_quotes(date_yyyymmdd="2020-03-01"),
315+
call.get_prices_daily_quotes(date_yyyymmdd="2020-03-02"),
316316
]
317317
mock.reset_mock()

0 commit comments

Comments
 (0)