efinance Documentation

repository·main·Indexed 26 days ago

https://github.com/micro-sheep/efinance

A free, open-source Python library (version 0.5.9) used to fetch financial data for stocks, funds, and futures based on Eastmoney. It provides modules for retrieving historical K-line data, real-time quotes, Dragon-Tiger List data, quarterly company performance, fund flow, and convertible bond information to support the development of personal trading systems.

Tokens
5.7K
Snippets
41
Records
64
Agent score
86%

What's inside efinance

  1. Overview of efinance

    main

    efinance is a free and open-source Python library designed to retrieve data for stocks, funds, and futures. It is intended to help developers easily acquire financial data to support personal trading systems.

    Note: This project is for learning and exchange purposes only and must not be used for commercial purposes.

    If you encounter rate limiting or network errors (such as connection timeouts), you may consider using TickFlow as an alternative data source.

  2. Build documentation using pdoc

    main

    You can also use pdoc to build and view efinance documentation. This method will open the documentation in a browser interface.

    # Install dependencies
    pip install pdoc
    git clone https://github.com/Micro-sheep/efinance
    
    # Generate and view documentation
    cd efinance
    pdoc . -d numpy
  3. Install efinance using Docker

    main

    To run efinance in a containerized environment, follow these steps to clone the repository, build the image, and run it interactively:

    1. Clone the repository.
    2. Navigate to the project root.
    3. Build the Docker image using the local Dockerfile.
    4. Run the container in interactive mode. Using --rm will automatically remove the container after it exits.
    # 克隆代码
    git clone https://github.com/Micro-sheep/efinance
    # 切换工作目录为该项目的根目录
    cd efinance
    # 构建镜像(-t 指定构建后生成的镜像名称 . 指定 build 的对象是当前工作目录下的 dockerfile)
    docker build -t efinance . --no-cache
    # 以交互的方式运行镜像(运行之后自动删除容器,如不想删除 则可去掉 --rm)
    docker run --rm -it efinance
  4. Build documentation using Sphinx

    main

    To build the efinance documentation locally using Sphinx, clone the repository, install the required dependencies, and run the sphinx-build command. By default, this generates English documentation. To generate Chinese documentation, use the -D language=zh flag.

    # Clone the repository
    git clone https://github.com/Micro-sheep/efinance
    
    # Generate English documentation
    cd efinance/docs
    pip install -r requirements.txt --upgrade
    sphinx-build . ./build -b html
    
    # OR: Generate Chinese documentation
    sphinx-build . ./build -b html -D language=zh
  5. Get K-line data for ETFs

    main

    Use ef.stock.get_quote_history(etf_code) to retrieve historical K-line data for ETFs using their specific ETF code (e.g., '513050').

    import efinance as ef
    etf_code = '513050'
    df = ef.stock.get_quote_history(etf_code)
  6. Get convertible bond realtime quotes with ef.bond.get_realtime_quotes()

    main

    Use ef.bond.get_realtime_quotes() to retrieve real-time market quotes for all convertible bonds. The output includes bond code, name, price change, latest price, high/low, volume, turnover, and market type.

    import efinance as ef
    >>> ef.bond.get_realtime_quotes()
  7. Get fund historical net value information

    main

    Use ef.fund.get_quote_history(fund_code) to retrieve historical net value data for a specific fund. The returned data includes date, unit net value, cumulative net value, and price change percentage.

    import efinance as ef
    # Returns historical net value for fund '161725'
    ef.fund.get_quote_history('161725')
  8. Get exchange futures basic information

    main

    Use ef.futures.get_futures_base_info() to retrieve basic information for futures contracts, including futures code, name, market ID, and exchange type.

    import efinance as ef
    # Returns basic info for futures contracts
    ef.futures.get_futures_base_info()