JoinQuant jqdatasdk

repository·master·Indexed 23 days ago

https://github.com/joinquant/jqdatasdk

A Python SDK provided by JoinQuant (JQData) for accessing professional-grade financial market data for quantitative research and trading. It supports price and volume data across multiple frequencies (daily to tick-level), research data, specialized factors, and risk models. The SDK features the JQDataClient for authentication and data queries, returning results as Python dictionaries, pandas.Series, or pandas.DataFrame objects.

Tokens
1.1K
Snippets
2
Records
11
Agent score
30%

What's inside jqdatasdk

  1. Overview of JQData services and data types

    master

    JQData provides professional quantitative research data services, including:

    • Price and Volume Data: Supports annual, monthly, weekly, minute, and second-level (Tick) bar data.
    • Research Data: Includes instrument information and various derivative indicators.
    • Specialized Factors: Alpha factors, technical indicators, JQ-specific factors, and minute-level fund flows.
    • Risk Models: CNE5 and CNE6 risk models for stock portfolio requirements.

    For a complete list of available data interfaces and update schedules, refer to the JQData API Documentation.

  2. Authenticate and fetch data with jqdatasdk

    master

    To use the SDK, you must first authenticate using your JoinQuant website credentials via jqdatasdk.auth(). Once authenticated, you can use functions like get_price() to retrieve market data. For example, get_price supports various market symbols and timeframes.

    import jqdatasdk
    
    # 登录认证
    # username and password are your JoinQuant website credentials
    jqdatasdk.auth(username, password)
    
    # 获取数据
    # Example: Get price data for a specific stock
    jqdatasdk.get_price("000001.XSHE", start_date="2017-01-01", end_date="2017-12-31")
  3. Initialize the JQDataClient

    master

    The JQDataClient is the primary entrypoint for the SDK. You can obtain a singleton instance using JQDataClient.instance(), which automatically attempts to authenticate using credentials provided via environment variables. Alternatively, you can instantiate the class directly by providing host, port, username, and password (or a token).

    Authentication via Environment Variables The instance() method looks for the following environment variables (prefixed with JQDATA_ or JQDATASDK_):

    • USERNAME (or USER, ACCOUNT, MOB)
    • PASSWORD (or PASSWD)
    • HOST
    • PORT

    Direct Instantiation If you prefer not to use environment variables, pass credentials directly to the constructor.

  4. Configure JQDataClient via environment variables

    master

    The SDK supports configuring connection parameters via environment variables. This is useful for containerized environments or CI/CD pipelines. The SDK checks for prefixes JQDATA_ or JQDATASDK_ followed by the parameter name in uppercase.

    Supported variables:

    • JQDATA_USERNAME / JQDATA_USER / JQDATA_ACCOUNT / JQDATA_MOB
    • JQDATA_PASSWORD / JQDATA_PASSWD
    • JQDATA_HOST
    • JQDATA_PORT
  5. Handle JQData connection and response errors

    master

    The SDK raises several types of exceptions:

    • ResponseError: Raised when the server returns an error status in a successful transport response.
    • socket_error: A tuple of (TTransportException, socket.error, ProtocolError) representing underlying network/transport issues.

    If a connection is closed due to high data volume, you may see the specific error message: "连接被关闭,请减少数据查询量或检查网络后重试" (Connection closed, please reduce query volume or check network and retry).

  6. Use JQDataClient for data queries

    master
    Once authenticated, you can call any market data method directly on the JQDataClient instance. The client uses __getattr__ to map method calls to the underlying Thrift service. The SDK automatically handles data conversion, transforming raw responses into Python dictionaries, pandas.Series, or pandas.DataFrame objects based on the data_type returned by the server.