get_ohlcv_by_codes_for_period#
- pyqqq.data.us_stocks.get_ohlcv_by_codes_for_period(tickers: List[str] | str, start_date: date, end_date: date, ascending: bool = True, adjusted: bool = True) Dict[str, DataFrame] | DataFrame [source]#
지정된 티커와 기간에 대한 미국 주식의 OHLCV 데이터를 조회합니다.
이 함수는 하나 이상의 티커와 시작 날짜, 종료 날짜를 지정하여 해당 기간 동안의 OHLCV 데이터를 API를 통해 요청합니다. 단일 티커를 문자열로 전달하면 해당 티커의 DataFrame을 반환하고, 티커 리스트를 전달하면 각 티커별로 DataFrame을 포함하는 딕셔너리를 반환합니다.
- Parameters:
tickers (Union[List[str], str]) – 조회할 티커 또는 티커들의 리스트.
start_date (dtm.date) – 조회할 기간의 시작 날짜.
end_date (dtm.date) – 조회할 기간의 종료 날짜.
ascending (bool) – 날짜 오름차순 여부. 기본값은 True.
adjusted (bool) – 수정 주가 여부. 기본값은 True.
- Returns:
단일 티커 입력시: 해당 티커의 OHLCV 데이터를 포함하는 DataFrame
티커 리스트 입력시: 티커를 키로 하고, 해당 티커의 OHLCV 데이터를 포함하는 DataFrame을 값으로 하는 딕셔너리
DataFrame의 컬럼은 다음과 같습니다:
open (float): 시가
high (float): 고가
low (float): 저가
close (float): 종가
volume (int): 거래량
- Return type:
Union[Dict[str, pd.DataFrame], pd.DataFrame]
- Raises:
HTTPError – API 요청이 실패했을 때 발생
Examples
>>> # 단일 티커 조회 >>> df = get_ohlcv_by_codes_for_period('AAPL', dtm.date(2024, 5, 7), dtm.date(2024, 5, 9)) >>> print(df) open high low close volume date 2024-05-07 173.5 174.2 172.3 173.8 55234123 2024-05-08 173.9 174.8 173.1 174.2 48521234 2024-05-09 174.3 175.1 173.8 174.9 52145678
>>> # 복수 티커 조회 >>> dfs = get_ohlcv_by_codes_for_period(['AAPL', 'MSFT'], dtm.date(2024, 5, 7), dtm.date(2024, 5, 9)) >>> print(dfs['AAPL']) open high low close volume date 2024-05-07 173.5 174.2 172.3 173.8 55234123 2024-05-08 173.9 174.8 173.1 174.2 48521234 2024-05-09 174.3 175.1 173.8 174.9 52145678