Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Heuristic:HKUDS AI Trader A Share Lot Size Rule

From Leeroopedia




Knowledge Sources
Domains Trading, A_Shares
Last Updated 2026-02-09 14:00 GMT

Overview

Chinese A-share market constraint: all stock trades must be in multiples of 100 shares (1 lot = 100 shares), enforced at the tool level with helpful suggestions for nearest valid amounts.

Description

The Shanghai and Shenzhen stock exchanges require all stock orders to be placed in multiples of 100 shares (one "lot" or "hand"). The AI-Trader system enforces this rule in the buy() and sell() MCP tools by checking amount % 100 != 0 for any symbol ending with .SH or .SZ. When violated, the tool returns a descriptive error with suggestions for the nearest valid quantities (floor and ceiling multiples of 100).

Usage

This heuristic applies to all A-share trading operations. When implementing or modifying trading tools for the Chinese market, always validate lot sizes. LLM agents must be explicitly instructed about this rule in their system prompt to avoid repeated invalid trade attempts.

The Insight (Rule of Thumb)

  • Action: Validate amount % 100 == 0 before executing any A-share buy or sell order.
  • Value: Lot size = 100 shares. Valid amounts: 100, 200, 300, etc.
  • Trade-off: This forces minimum position sizes that may be large relative to the simulated portfolio. With default initial cash of 100,000 CNY, buying 100 shares of an expensive stock (e.g., 600519.SH Moutai at ~1800 CNY) requires 180,000 CNY.
  • Prompt Integration: The A-share system prompt explicitly states this rule to reduce agent errors.

Reasoning

This is a regulatory requirement from the Chinese Securities Regulatory Commission (CSRC). Unlike US markets where fractional shares are possible, Chinese exchanges enforce integer lot sizes. Enforcing this at the tool level (rather than relying solely on the LLM prompt) provides a hard safety net. The suggestion feature (showing nearest valid amounts) helps the LLM self-correct without additional reasoning steps.

Code Evidence

Lot size validation from agent_tools/tool_trade.py:120-128:

# Chinese A-shares trading rule: Must trade in lots of 100 shares
if market == "cn" and amount % 100 != 0:
    return {
        "error": f"Chinese A-shares must be traded in multiples of 100 shares (1 lot = 100 shares). You tried to buy {amount} shares.",
        "symbol": symbol,
        "amount": amount,
        "date": today_date,
        "suggestion": f"Please use {(amount // 100) * 100} or {((amount // 100) + 1) * 100} shares instead.",
    }

Market detection from agent_tools/tool_trade.py:97-100:

# Auto-detect market type based on symbol format
if symbol.endswith((".SH", ".SZ")):
    market = "cn"
else:
    market = "us"

Prompt instruction from prompts/agent_prompt_astock.py:59:

# A-share trading rules (in Chinese):
# "Must trade in multiples of 100 shares (1 lot = 100 shares)"

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment