FinanceDataReader Documentation

repository·master·Indexed 23 days ago

https://github.com/financedata/financedatareader

An open-source financial data reader (crawler) for fetching stock listings, historical prices, indexes, exchange rates, and cryptocurrency data. It provides a Python API featuring DataReader, StockListing, and SnapDataReader, as well as a CLI tool ('fdr') for querying data in CSV, JSON, and Markdown formats. Supported sources include KRX, NASDAQ, NYSE, Yahoo Finance, and FRED.

Tokens
6.3K
Snippets
13
Records
54
Agent score
77%

What's inside FinanceDataReader

  1. Identify stock identifiers for price data retrieval

    master

    When retrieving price data, the format of the identifier depends on the market:

    Domestic (Korean) Stocks

    Use the 6-digit short code.

    • Example: '005930' (Samsung Electronics), '215600' (ShinlaGen).
    • You can find the full list of codes by calling fdr.StockListing('KRX').

    US Stocks

    Use the Ticker symbol.

    • Example: 'AAPL' (Apple), 'AMZN' (Amazon), 'GOOG' (Google).
    • You can find the full list of NASDAQ tickers by calling fdr.StockListing('NASDAQ').
  2. Use FinanceDataReader CLI

    master

    The fdr command allows you to query financial data directly from your terminal.

    Run without installation (using uvx):

    uvx --from finance-datareader fdr price AAPL --start 2024

    Run after installing via uv tool:

    uv tool install finance-datareader
    # Then use the 'fdr' command directly
  3. Use cached KRX listing data for faster access

    master

    If you want to avoid direct requests to KRX and instead use pre-cached CSV data from the fdr_krx_data_cache repository, use the following classes:

    • KrxMarcapListingCache(market): Cached market capitalization and listing data.
    • KrxStockListingCache(market): Cached descriptive information.
    • KrxDelistingCache(market, start, end): Cached delisting data.
  4. Use NaverSnapReader for specialized ticker queries

    master

    The NaverSnapReader class allows querying specific Naver-based data using a specialized ticker string format.

    Ticker Formats:

    1. Financial Statements: NAVER/FINSTATE[/options]/CODE

      • Options follow a - separator.
      • fin_type options: 0, 1, 2, 3, 4.
      • freq options: Y (Year), Q (Quarter), A (All).
      • Examples: NAVER/FINSTATE/005930, NAVER/FINSTATE-Q/005930, NAVER/FINSTATE-Q1/005930.
    2. Investor Trends: NAVER/INVESTORS/CODE

      • Example: NAVER/INVESTORS/005930.
  5. Get listed stock symbols by exchange using StockListing

    master

    Use fdr.StockListing(symbol) to retrieve a list of all stocks currently listed on a specific exchange. The function returns a pandas DataFrame containing the stock information.

    Available exchange symbols include:

    SymbolExchangeNotes
    KRXKRX TotalIncludes KOSPI, KOSDAQ, and KONEX
    KOSPIKOSPI
    KOSDAQKOSDAQ
    KONEXKONEX
    NASDAQNASDAQ
    NYSENYSE
    AMEXAMEX
    S&P500S&P 500Components of the S&P 500 index
    SSEShanghai Stock Exchange
    SZSEShenzhen Stock Exchange
    HKEXHong Kong Stock Exchange
    TSETokyo Stock Exchange
    HOSEHo Chi Minh City Stock Exchange
    ETF/KRKorean ETFs
  6. Fetch historical price data with DataReader()

    master

    Use fdr.DataReader(symbol, start_date, end_date) to retrieve historical price data for stocks, indices, commodities, currencies, and cryptocurrencies.

    Supported data types include:

    • Indices: KOSPI (KS11), KOSDAQ (KQ11), Dow Jones (DJI), S&P500 (S&P500), etc.
    • Stocks: KRX stocks (e.g., '005930'), US stocks (e.g., 'AAPL').
    • Commodities: WTI Crude Oil (CL=F), Gold (GC=F), etc.
    • Currencies: Forex pairs (e.g., 'USD/KRW') and Cryptocurrencies (e.g., 'BTC/USD').
    • FRED Data: Economic indicators (e.g., 'FRED:M2').

    You can fetch multiple symbols at once by providing a comma-separated string.

  7. Retrieve snapshots and financial statements with SnapDataReader()

    master

    Use fdr.SnapDataReader(path) to fetch non-time-series data such as index constituents or financial statements.

    Index Constituents:

    • KRX/INDEX/LIST: List of all KRX indices.
    • KRX/INDEX/STOCK/{index_code}: List of stocks within a specific index (e.g., 'KRX/INDEX/STOCK/1001' for KOSPI).

    Financial Statements (via NAVER):

    • NAVER/FINSTATE/{symbol}: Annual financial statements.
    • NAVER/FINSTATE-Q/{symbol}: Quarterly financial statements.
    • Use suffixes like -1Y, -2Y, -3Y, -4Y for specific years or K-IFRS/K-GAAP variations (e.g., NAVER/FINSTATE-1Y/005930).
  8. Get stock listings with StockListing()

    master

    Use fdr.StockListing(market) to retrieve lists of available stocks and indices for various markets. This is useful for discovering symbols.

    Supported markets:

    • KRX Markets: 'KRX', 'KOSPI', 'KOSDAQ', 'KONEX'. Use -DESC suffix (e.g., 'KRX-DESC') for descriptive lists including funds.
    • Special KRX Lists: 'KRX-DELISTING' (delisted stocks), 'KRX-ADMIN' (managed stocks).
    • US Markets: 'S&P500', 'NASDAQ', 'NYSE'.
    • Global Markets: 'SSE' (Shanghai), 'SZSE' (Shenzhen), 'HKEX' (Hong Kong), 'TSE' (Tokyo), 'HOSE' (Ho Chi Minh).
    • ETFs: 'ETF/KR' for Korean ETFs.
  9. Read price data with DataReader()

    master

    Use fdr.DataReader(symbol, start, end) to fetch historical price data. The symbol can be a stock ticker (e.g., 'AAPL', '068270'), an index (e.g., 'KS11', 'DJI'), a currency pair (e.g., 'USD/KRW'), or a cryptocurrency (e.g., 'BTC/KRW').

    If end is not provided, it defaults to the current date.

    import FinanceDataReader as fdr
    
    # 애플(AAPL), 2017-01-01 ~ 현재
    df = fdr.DataReader('AAPL', '2017')
    
    # 셀트리온(068270), 2017-01-01 ~ 2018-05-30
    df = fdr.DataReader('068270', '2017-01-01', '2018-05-30')
    
    # KS11 (KOSPI 지수), 2015-01-01~현재
    df = fdr.DataReader('KS11', '2015')
    
    # 다우지수, 2015년~현재
    df = fdr.DataReader('DJI', '2015-01-01')
    
    # 원달러 환율, 1995-01-01 ~ 현재
    df = fdr.DataReader('USD/KRW', '1995')
    
    # 비트코인 원화 가격 (빗썸), 2016년~현재
    df = fdr.DataReader('BTC/KRW', '2016')