SuperAPI AI Directory

jqdatasdk

Data & analytics

View repository

Updated 10-16 01:56

About this skill

jqdatasdk JoinQuant data retrieval

Task Objective

  • This Skill is used to: obtain A-share market data, financial indicators, and factor data through the JoinQuant data interface
  • Capabilities include: real-time quotes, historical K-line, financial data, indicator data, stock information, factor data
  • Trigger conditions: when the user mentions JoinQuant, jqdata, jqdatasdk, or needs to obtain A-share data, financial information, or factor data

Differences from joinquant-strategy: This skill islocal Python library(import jqdatasdk), used to pull JoinQuant data in a local environment;joinquant-strategy is oriented towardJoinQuant official website strategy environment(backtesting/simulation/research,import jqdata), and the APIs are slightly different. The two cannot be mixed (jqdatasdk cannot be imported in official website strategies).

Prerequisites

  • Dependency description: install the jqdatasdk library (already included in dependency)
  • Credential configuration: need to configure the JoinQuant account Token (environment variable: JQDATA_TOKEN) or login username and password (environment variables: JQDATA_USERNAME, JQDATA_PASSWORD)
  • Account application: visit https://www.joinquant.com/ to register an account and obtain an API Token (see references/jqdatasdk_quickstart.md for details)

Operation Steps

  • Standard process:
    1. Determine data requirements — the agent understands the user's intent (quotes/K-line/financials/factors, etc.)
    2. Call the corresponding script — select the script according to the data type
    3. Parse results — the agent analyzes the returned JSON-format data
  • Script call mapping:
    • Quotes/K-line/real-time data → python scripts/market_data.py --type price --code 000001.XSHE --start 2024-01-01 --end 2024-01-31
    • Financial data/indicators/valuation → python scripts/financial_data.py --type fundamentals --code 000001.XSHE --statDate 2024
    • Stock list/information → python scripts/stock_info.py --type all_securities --security_type stock
    • Factor data → python scripts/factor_data.py --code 000001.XSHE --factor valuation --start 2024-01-01 --end 2024-01-31
  • Optional branches:
    • When data for multiple stocks is needed: use the --code parameter separated by commas
    • When a specific frequency is needed: use the --frequency parameter (1min/5min/15min/30min/60min/120min/daily/weekly/monthly)
    • When the price type needs to be adjusted: use the --fq_ref_date parameter or directly specify the adjustment type

Usage Examples

  • Example 1: Obtain daily K-line data for a stock
    • Scenario/input: the user says "view the K-line data of Ping An Bank for the last month"
    • Expected output: return OHLCV data such as date, opening price, highest price, lowest price, closing price, and trading volume
    • Key point: call python scripts/market_data.py --type price --code 000001.XSHE --start 2024-03-01 --end 2024-03-31 --frequency daily
  • Example 2: Query financial indicators
    • Scenario/input: the user says "obtain China Merchants Bank's financial indicators for 2023"
    • Expected output: return financial indicators such as PE, PB, ROE, operating revenue, and net profit
    • Key point: call python scripts/financial_data.py --type indicators --code 600036.XSHG --statDate 2023
  • Example 3: Obtain factor data
    • Scenario/input: the user says "query Kweichow Moutai's valuation factors"
    • Expected output: return valuation factor data such as price-to-earnings ratio, price-to-book ratio, and market value
    • Key point: call python scripts/factor_data.py --code 600519.XSHG --factor valuation --start 2024-01-01 --end 2024-03-31

Quick Reference

Common Code Examples

import jqdatasdk as jq
import pandas as pd

# 认证(需先设置环境变量 JQDATA_TOKEN 或 JQDATA_USERNAME/JQDATA_PASSWORD)
jq.auth(os.environ.get('JQDATA_USERNAME', ''), os.environ.get('JQDATA_PASSWORD', ''))
# 或使用 Token: jq.auth(token='your_token')

# 获取日K线数据
df = jq.get_price('000001.XSHE', start_date='2024-01-01', end_date='2024-12-31',
                  frequency='daily', fields=['open', 'high', 'low', 'close', 'volume'])

# 获取财务数据
q = jq.query(jq.valuation).filter(jq.valuation.code == '000001.XSHE')
fundamentals = jq.get_fundamentals(q, date='2024-01-01')

Resource Index

  • Scripts:
    • scripts/market_data.py (Purpose and parameters: retrieve market data/K-line/real-time data, supports --type/--code/--start/--end/--frequency/--count)
    • scripts/financial_data.py (Purpose and parameters: retrieve financial/indicator/valuation data, supports --type/--code/--statDate/--columns)
    • scripts/stock_info.py (Purpose and parameters: retrieve stock list/information, supports --type/--security_type/--code)
    • scripts/factor_data.py (Purpose and parameters: retrieve factor data, supports --code/--factor/--start/--end)
  • References:

Notes

  • Script execution requires configuring a JoinQuant account Token or login username and password; credential configuration must be completed before first use
  • JoinQuant stock code format: Shanghai market is XXXXXX.XSHG, Shenzhen market is XXXXXX.XSHE
  • Some data (such as financial data) may be delayed; it is recommended to retrieve it outside trading hours 9:30-15:00
  • The script returns data in JSON format, and the agent is responsible for parsing and converting it into a user-friendly display
  • There are call frequency limits; avoid making a large number of requests in a short period (see the official JoinQuant documentation for details)
  • For first use, it is recommended to first read jqdatasdk_quickstart.md to complete authentication configuration