Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:24mlight A Share investment Agent start stock analysis

From Leeroopedia
Knowledge Sources
Domains Backend_Engineering, API_Design
Last Updated 2026-10-10 14:00 GMT

Overview

Concrete FastAPI endpoint for triggering asynchronous stock analysis via POST request with ThreadPoolExecutor execution and run ID tracking, provided by the A_Share_investment_Agent repository.

Description

The start_stock_analysis function is a FastAPI route handler at POST /api/analysis/start. It receives a StockAnalysisRequest, generates a UUID run_id, submits execute_stock_analysis to the thread pool via api_state._executor.submit(), registers the task and run, and returns an ApiResponse[StockAnalysisResponse] with the run_id and "running" status.

Usage

Import when you need to:

  • Expose stock analysis as an async REST API endpoint
  • Trigger background analysis from a frontend application

Code Reference

Source Location

Signature

@router.post("/start", response_model=ApiResponse[StockAnalysisResponse])
async def start_stock_analysis(request: StockAnalysisRequest):
    """Start stock analysis task in background thread pool."""

Import

# This is a FastAPI route, registered via:
from backend.routers import analysis
app.include_router(analysis.router)

I/O Contract

Inputs

Name Type Required Description
request.ticker str Yes Stock code (e.g., "002848")
request.show_reasoning bool No Show reasoning (default: True)
request.num_of_news int No News count 1-100 (default: 5)
request.initial_capital float No Initial capital (default: 100000)
request.initial_position int No Initial position (default: 0)

Outputs

Name Type Description
return ApiResponse[StockAnalysisResponse] {success, message, data: {run_id, ticker, status, message, submitted_at}}

Usage Examples

API Call

# Start analysis
curl -X POST http://localhost:8000/api/analysis/start \
  -H "Content-Type: application/json" \
  -d '{"ticker": "002848", "show_reasoning": true, "num_of_news": 5}'

# Response:
# {"success": true, "data": {"run_id": "uuid-...", "status": "running", ...}}

Status Polling

# Check status
curl http://localhost:8000/api/analysis/{run_id}/status

# Get results (when completed)
curl http://localhost:8000/api/analysis/{run_id}/result

Related Pages

Implements Principle

Requires Environment

Page Connections

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