efinance
efinance is a free and open-source Python library designed for quickly obtaining stock, fund, and futures data based on Eastmoney. It is actively maintained with frequent minor releases, providing convenience for personal trading system needs. The library simplifies the process of fetching historical and real-time financial market data.
Warnings
- breaking The library relies on web scraping data from Eastmoney. Changes to Eastmoney's website structure or APIs may cause `efinance` functions to break or return incorrect data without warning.
- gotcha The library explicitly states it is 'only for learning and exchange, and must not be used for commercial purposes' (本项目仅供学习交流使用,不得用于商业用途。). Using it for commercial applications may violate their terms or expose you to legal risks.
- gotcha Users may encounter rate limiting or network errors (限流或网络报错) when fetching large amounts of data or making frequent requests, as data is scraped from public sources.
- gotcha Scraped data may not be perfectly real-time or entirely accurate. It's unsuitable for high-frequency trading or applications requiring guaranteed data integrity.
Install
-
pip install efinance
Imports
- efinance
import efinance as ef
- ef.stock
import efinance as ef data = ef.stock.get_quote_history('600519') - ef.fund
import efinance as ef info = ef.fund.get_base_info(['161725', '005827'])
Quickstart
import efinance as ef
# Get historical daily K-line data for a stock (e.g., '600519' for Kweichow Moutai)
stock_code = '600519'
history_data = ef.stock.get_quote_history(stock_code)
print(f"Historical data for {stock_code}:\n{history_data.head()}")
# Get basic information for multiple funds (e.g., '161725', '005827')
fund_codes = ['161725', '005827']
fund_info = ef.fund.get_base_info(fund_codes)
print(f"Basic info for funds {fund_codes}:\n{fund_info.head()}")