Implementation:24mlight A Share investment Agent start stock analysis
| 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
- Repository: A_Share_investment_Agent
- File: backend/routers/analysis.py
- Lines: L26-91
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