AData Python SDK

repository·main·Indexed 26 days ago

https://github.com/1nchaos/adata

A Python SDK for A-share (Chinese stock market) quantitative trading data. It integrates multiple data sources—including Tonghuashun, Eastmoney, Baidu Gushitong, Tencent Finance, and Sina Finance—to provide high-availability information such as stock codes, historical K-line data, real-time quotes, financial data, ETF and bond information, and market sentiment indicators.

Tokens
2.6K
Snippets
7
Records
16
Agent score
40%

What's inside AData

  1. Understand AData design philosophy

    main

    AData is designed with the following principles:

    1. Focus on Trading Data: The project prioritizes real-time trading/market data over financial statements (which are used only for stock pool filtering) to ensure suitability for quantitative trading and AI training.
    2. Database Compatibility: Functions and dictionaries are designed to follow standard data storage formats, allowing users to easily map data dictionaries to database tables for local storage.
    3. Open Source: The A-share database is permanently free and open-source, specifically focused on quantitative trading.
  2. Publish (upload) modules to PyPI using Twine

    main

    To upload your built packages to the PyPI legacy repository, use the twine upload command pointing to the files in your dist/ directory. You will be prompted to enter your PyPI username and password during the process.

    python -m twine upload --repository-url https://upload.pypi.org/legacy/  dist/*
    # or
    twine upload --repository-url https://upload.pypi.org/legacy/  dist/*
  3. Install Twine for module uploading

    main

    Twine is the tool used to publish modules to PyPI. If it is not already installed, you can install or upgrade it using pip or python -m pip.

    python -m pip install --upgrade twine
    # or
    pip install --upgrade twine
  4. Configure K-line type and Proxy settings

    main

    When using the AData SDK, you can configure the following parameters:

    • k_type: Specifies the K-line type. Options are:

      • 1: Daily (Default)
      • 2: Weekly
      • 3: Monthly
    • Proxy Settings: You can set a global proxy. If the proxy becomes invalid, it can be reset. The required parameters are ip and proxy_url.

  5. Install the AData SDK

    main

    Install the adata package using pip. You can use official PyPI or domestic Chinese mirrors like Aliyun or Tsinghua for faster installation.

    Mirrors:

    • Aliyun (Recommended): http://mirrors.aliyun.com/pypi/simple/
    • Tsinghua: https://pypi.tuna.tsinghua.edu.cn/simple
    • Official: https://pypi.org/simple
  6. Retrieve stock financial data

    main
    Use stock.finance.get_core_index() to retrieve core financial data for a single stock (Source: Eastmoney). This includes detailed data from the three major financial statements.
  7. Retrieve stock market and price data

    main

    Use the stock.market module to access real-time, historical, and technical price data (K-lines), dividends, and capital flows.

    K-line and Price Data:

    • stock.market.get_market(): Get K-line data (Day, Week, Month) for a single stock.
    • stock.market.get_market_min(): Get intraday (minute) price data for a single stock (current day only).
    • stock.market.list_market_current(): Get latest real-time quotes for multiple stocks (Sources: Sina, Tencent).
    • stock.market.get_market_five(): Get Level 2 (5-tier) quotes for a single stock (Sources: Tencent, Baidu).
    • stock.market.get_market_bar(): Get tick-by-tick transaction data (Source: Gushitong).

    Concept and Index Data:

    • stock.market.get_market_concept_ths(): Get K-line data for a Tonghuashun concept (use index_code starting with 8).
    • stock.market.get_market_concept_min_ths(): Get intraday K-line for a Tonghuashun concept.
    • stock.market.get_market_concept_current_ths(): Get real-time quotes for a Tonghuashun concept.
    • stock.market.get_market_concept_east(): Get K-line data for an Eastmoney concept (use index_code starting with BK).
    • stock.market.get_market_concept_min_east(): Get intraday K-line for an Eastmoney concept.
    • stock.market.get_market_concept_current_east(): Get real-time quotes for an Eastmoney concept.
    • stock.market.get_market_index(): Get K-line data (Day, Week, Month) for an index.
    • stock.market.get_market_index_min(): Get intraday K-line for an index.
    • stock.market.get_market_index_current(): Get real-time quotes for an index.

    Dividends and Capital Flow:

    • stock.market.get_dividend(): Get dividend information for a single stock.
    • stock.market.get_capital_flow_min(): Get intraday capital flow for a single stock.
    • stock.market.get_capital_flow(): Get historical daily capital flow for a single stock.
    • stock.market.all_capital_flow_east(): Get capital flow for all Eastmoney concepts over the last N days.
  8. Retrieve ETF and Bond data

    main

    Access information and market data for Exchange Traded Funds (ETFs) and Convertible Bonds.

    ETF (Fund) Data:

    • fund.info.all_etf_exchange_traded_info(): Get all A-share market ETF information (Source: Eastmoney).
    • fund.market.get_market_etf(): Get K-line data (Day, Week, Month) for an ETF (Source: Tonghuashun).
    • fund.market.get_market_etf_min(): Get intraday K-line for an ETF.
    • fund.market.get_market_etf_current(): Get real-time quotes for an ETF.

    Bond Data:

    • bond.info.all_convert_code(): Get all A-share convertible bond codes (Source: Tonghuashun).
    • bond.market.list_market_current(): Get latest real-time quotes for A-share convertible bonds (Source: Sina).
  9. Retrieve A-share stock basic information

    main

    Use the stock.info module to access fundamental stock data, including codes, share capital, industry classifications, and concept/sector information.

    Available Methods:

    • stock.info.all_code(): Get all A-share stock codes.
    • stock.info.get_stock_shares(): Get share capital information for a single stock (Source: Eastmoney).
    • stock.info.get_industry_sw(): Get SW (Shenwan) level 1 and 2 industry classification for a single stock (Source: Baidu).
    • stock.info.all_concept_code_ths(): Get all A-share concept codes from Tonghuashun.
    • stock.info.concept_constituent_ths(): Get constituent stocks for a Tonghuashun concept index (returns stock code and short name).
    • stock.info.get_concept_ths(): Get concepts a single stock belongs to (Source: Tonghuashun).
    • stock.info.all_concept_code_east(): Get all A-share concept codes from Eastmoney.
    • stock.info.concept_constituent_east(): Get constituent stocks for an Eastmoney concept index.
    • stock.info.get_concept_east(): Get concepts a single stock belongs to (Source: Eastmoney).
    • stock.info.get_plate_east(): Get the sector/plate a stock belongs to (includes Industry, Region, and Concepts).
    • stock.info.all_index_code(): Get all A-share market index codes (Source: Tonghuashun).
    • stock.info.index_constituent(): Get the list of constituent stocks for a specific index.
    • stock.info.trade_calendar(): Get stock trading calendar information (Source: Shenzhen Stock Exchange).
  10. Retrieve market sentiment and hot lists

    main

    Use the sentiment module to access market sentiment indicators, Northbound capital flows, and popularity rankings.

    Sentiment and Northbound Capital:

    • sentiment.stock_lifting_last_month(): Get the list of stocks scheduled for lifting restrictions in the last month (Source: Tonghuashun).
    • sentiment.securities_margin(): Get the margin trading and securities lending balance list (Source: Eastmoney).
    • sentiment.north.north_flow_current(): Get current Northbound capital (Shanghai-Hong Kong Connect) inflow (Source: Eastmoney).
    • sentiment.north.north_flow_min(): Get intraday Northbound capital flow.
    • sentiment.north.north_flow(): Get historical Northbound capital inflow.

    Hot Lists and Rankings:

    • sentiment.hot.pop_rank_100_east: Eastmoney popularity top 100 list.
    • sentiment.hot.hot_rank_100_ths(): Tonghuashun popularity top 100 list.
    • sentiment.hot.hot_concept_20_ths(): Tonghuashun top 20 hot concept sectors.
    • sentiment.hot.list_a_list_daily(): Daily Dragon-Tiger list (Source: Eastmoney).
    • sentiment.hot.get_a_list_info(): Detailed information for a specific stock on the Dragon-Tiger list.
    • sentiment.mine.mine_clearance_tdx(): Stock risk/avoidance (mine clearance) information (Source: Tongdaxin).