mpquant/ashare

repository·main·Indexed 25 days ago

https://github.com/mpquant/ashare

A lightweight, single-file Python API for retrieving real-time and historical A-share market data in pandas DataFrame format. It supports daily, weekly, monthly, and minute-level frequencies with automatic failover between Sina and Tencent data sources.

Tokens
327
Snippets
1
Records
3
Agent score
37%

What's inside ashare

  1. Install and use Ashare

    main
    Ashare is a lightweight API for real-time A-share market data. It is designed to be portable: the entire library consists of a single file Ashare.py. To use it, simply include Ashare.py in your project directory and import it using from Ashare import *.
    from Ashare import *
  2. Integrate Ashare with MyTT for technical analysis

    main
    Ashare's DataFrame output is compatible with technical analysis libraries like MyTT. You can extract price series from the DataFrame (e.g., df.close.values) and pass them into MyTT functions to calculate indicators like Moving Averages (MA) or Bollinger Bands (BOLL).
  3. Get stock price data with get_price()

    main

    The get_price() function is the primary interface for retrieving market data. It returns data in a pandas.DataFrame format.

    Supported Stock Code Formats:

    • TongdaXun/Flush/JoinQuant styles: sh000001, sz399006, sh600519.
    • Standardized formats: 000001.XSHG, 399006.XSHE, 600519.XSHG.

    Parameters:

    • code (str): The stock identifier.
    • frequency (str): The data interval. Supported values include:
      • Daily: '1d'
      • Weekly: '1w'
      • Monthly: '1M'
      • Minute-level: '1m', '5m', '15m', '30m', '60m'
    • count (int): Number of data points to retrieve (counting backwards from the most recent).
    • end_date (str, optional): The end date for historical data (e.g., '2021-04-30').