# Best Practices for Using daily_stock_analysis: Complete Setup Guide

> Master the daily_stock_analysis setup guide. Learn best practices for environment variables, dependencies, and running your stock analysis jobs effectively. Get started today

- Repository: [mumu/daily_stock_analysis](https://github.com/ZhuLinsen/daily_stock_analysis)
- Tags: best-practices
- Published: 2026-04-30

---

**Configure your environment variables in a `.env` file, install Python 3.11+ dependencies, and execute the [`main.py`](https://github.com/ZhuLinsen/daily_stock_analysis/blob/main/main.py) entry point to run stock analysis as a CLI job, FastAPI service, or scheduled task.**

The `daily_stock_analysis` repository by ZhuLinsen is a Python-based platform for end-to-end analysis of A-share, Hong Kong, and US stocks. It aggregates market data, technical indicators, fundamentals, news sentiment, and LLM-powered insights into a unified pipeline. This guide covers the essential configuration steps and architectural patterns required to deploy the system effectively.

## 1. Prepare Your Runtime Environment

### 1.1 Configure Environment Variables

All application settings are loaded from environment variables managed through a singleton `Config` object in [`src/config.py`](https://github.com/ZhuLinsen/daily_stock_analysis/blob/main/src/config.py). Start by copying the example configuration file:

```bash
cp .env.example .env

```

Populate the following minimal required variables:

| Variable | Purpose | Example |
|----------|---------|---------|
| `STOCK_LIST` | Comma-separated stock codes (uppercase) | `600519,000001,300750` |
| `LITELLM_MODEL` | LLM provider/model format | `gemini/gemini-3-flash-preview` |
| `GEMINI_API_KEYS` | API keys for load balancing (comma-separated) | `key1,key2` |
| `PROXY_HOST` / `PROXY_PORT` | Optional proxy for data sources | `127.0.0.1` / `10809` |

The configuration loader automatically appends domestic financial domains to `NO_PROXY` when a proxy is configured, preventing accidental proxying of Chinese data sources like Tushare. This logic is implemented in [`src/config.py`](https://github.com/ZhuLinsen/daily_stock_analysis/blob/main/src/config.py) at lines 1000–1025.

### 1.2 Install Python Dependencies

The project requires Python 3.11 or newer. Create an isolated environment and install pinned dependencies:

```bash
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

```

## 2. Understand the Core Architecture

The platform follows a layered architecture with clear separation of concerns:

| Layer | Responsibility | Main Modules |
|-------|--------------|--------------|
| **Configuration** | Environment loading and validation | [`src/config.py`](https://github.com/ZhuLinsen/daily_stock_analysis/blob/main/src/config.py) |
| **Data Fetching** | Unified interface with fallback and caching | `data_provider/*` |
| **Analysis Pipeline** | Orchestrates technical and fundamental analysis | [`src/core/pipeline.py`](https://github.com/ZhuLinsen/daily_stock_analysis/blob/main/src/core/pipeline.py) |
| **LLM & Agent** | Multi-model support via LiteLLM | [`src/config.py`](https://github.com/ZhuLinsen/daily_stock_analysis/blob/main/src/config.py), [`src/analyzer.py`](https://github.com/ZhuLinsen/daily_stock_analysis/blob/main/src/analyzer.py), `src/agent/*` |
| **Notification** | Multi-channel alerts (Feishu, Telegram, Email, etc.) | [`src/notification.py`](https://github.com/ZhuLinsen/daily_stock_analysis/blob/main/src/notification.py) |
| **Web UI/API** | FastAPI backend and optional React frontend | [`server.py`](https://github.com/ZhuLinsen/daily_stock_analysis/blob/main/server.py), [`webui.py`](https://github.com/ZhuLinsen/daily_stock_analysis/blob/main/webui.py) |
| **Scheduler** | Daily task execution and monitoring | [`src/scheduler.py`](https://github.com/ZhuLinsen/daily_stock_analysis/blob/main/src/scheduler.py) |

The primary entry point is [`main.py`](https://github.com/ZhuLinsen/daily_stock_analysis/blob/main/main.py), which parses CLI arguments, builds the pipeline via [`src/core/pipeline.py`](https://github.com/ZhuLinsen/daily_stock_analysis/blob/main/src/core/pipeline.py), and determines the execution mode.

## 3. Configure Data Provider Fallback

The `DataFetcherManager` in `data_provider/*` implements a unified interface for multiple data sources including yfinance, Tushare, and Tickflow. Configure multiple API keys in your `.env` file to enable automatic fallback and load balancing across providers.

## 4. Optimize LLM Configuration

The system uses LiteLLM for provider-agnostic LLM calls with multi-model fallback support. Define your primary model in `LITELLM_MODEL` and provide comma-separated keys in provider-specific variables (e.g., `GEMINI_API_KEYS`, `OPENAI_API_KEYS`) to enable automatic key rotation. Temperature and other generation parameters are resolved through the configuration layer in [`src/config.py`](https://github.com/ZhuLinsen/daily_stock_analysis/blob/main/src/config.py).

## 5. Select Your Execution Mode

### 5.1 CLI Execution

Run one-off analysis jobs directly from the command line. The [`main.py`](https://github.com/ZhuLinsen/daily_stock_analysis/blob/main/main.py) script handles argument parsing and pipeline initialization for single executions.

### 5.2 FastAPI Service

Deploy the analyzer as a REST API using [`server.py`](https://github.com/ZhuLinsen/daily_stock_analysis/blob/main/server.py). This mode provides HTTP endpoints for on-demand analysis requests and integrates with the optional React frontend in `apps/dsa-web/`.

### 5.3 Scheduled Daily Tasks

Use [`src/scheduler.py`](https://github.com/ZhuLinsen/daily_stock_analysis/blob/main/src/scheduler.py) to run the pipeline on a daily schedule. This module supports background event monitoring and is designed for production deployment where automated daily stock reports are required.

## 6. Set Up Notification Channels

Configure notification channels in your `.env` file to receive alerts via Feishu webhooks, WeChat, Telegram bots, Email, or Discord. The [`src/notification.py`](https://github.com/ZhuLinsen/daily_stock_analysis/blob/main/src/notification.py) module handles message formatting including markdown-to-image conversion when rich formatting is required by the target platform.

## Summary

- **Environment Configuration**: Copy `.env.example` to `.env` and set `STOCK_LIST`, `LITELLM_MODEL`, and API keys before running
- **Proxy Handling**: The system automatically excludes domestic financial domains from proxy routing when `PROXY_HOST` is configured
- **Data Resilience**: The `DataFetcherManager` provides automatic fallback across yfinance, Tushare, and Tickflow providers
- **Execution Flexibility**: Run as CLI jobs ([`main.py`](https://github.com/ZhuLinsen/daily_stock_analysis/blob/main/main.py)), FastAPI services ([`server.py`](https://github.com/ZhuLinsen/daily_stock_analysis/blob/main/server.py)), or scheduled tasks ([`src/scheduler.py`](https://github.com/ZhuLinsen/daily_stock_analysis/blob/main/src/scheduler.py))
- **LLM Reliability**: Use comma-separated API keys for load balancing and configure multi-model fallback for resilient LLM operations

## Frequently Asked Questions

### What Python version is required for daily_stock_analysis?

The project requires **Python 3.11 or newer**. Dependencies are pinned in [`requirements.txt`](https://github.com/ZhuLinsen/daily_stock_analysis/blob/main/requirements.txt) to ensure compatibility with this version.

### How does the system handle proxy configurations for Chinese data sources?

When you set `PROXY_HOST` and `PROXY_PORT`, the configuration loader in [`src/config.py`](https://github.com/ZhuLinsen/daily_stock_analysis/blob/main/src/config.py) (lines 1000–1025) automatically appends domestic financial domains to the `NO_PROXY` environment variable. This prevents Tushare and other Chinese data providers from being routed through your proxy, avoiding connection issues while still allowing international sources like yfinance to use the proxy.

### Can I use multiple LLM providers simultaneously?

Yes. The system supports **multi-model fallback** via LiteLLM. Configure your primary model in `LITELLM_MODEL` and provide multiple API keys (comma-separated) in provider-specific variables like `GEMINI_API_KEYS` or `OPENAI_API_KEYS`. The implementation in [`src/config.py`](https://github.com/ZhuLinsen/daily_stock_analysis/blob/main/src/config.py) and [`src/analyzer.py`](https://github.com/ZhuLinsen/daily_stock_analysis/blob/main/src/analyzer.py) handles automatic key rotation and provider fallback if the primary model fails.

### Which notification channels are supported?

The platform supports **Feishu (Lark) webhooks**, **WeChat**, **Telegram bots**, **Email (SMTP)**, and **Discord**. Configure the relevant environment variables (e.g., `FEISHU_WEBHOOK_URL`, `TELEGRAM_BOT_TOKEN`) in your `.env` file. The [`src/notification.py`](https://github.com/ZhuLinsen/daily_stock_analysis/blob/main/src/notification.py) module automatically converts markdown reports to images when the notification channel requires visual formatting instead of raw text.