refactor: 缠论引擎迁入 chan/ 分层解耦,指标外置
将核心结构、指标与分析拆到 chan/{core,indicators,analysis,pipeline};
根目录保留兼容 shim;strategies 改为从 chan 包导入;买卖点经 bsp_macd 与 MACD 接合。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -8,42 +8,58 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
|
||||
|
||||
## Core Architecture
|
||||
|
||||
### Chan Theory Engine (`Chan*.py`)
|
||||
### Chan Theory Engine (`chan/` package)
|
||||
|
||||
Data processing pipeline (each step feeds the next):
|
||||
引擎已分层解耦;根目录 `Chan*.py` / `TF_DF.py` 仅为兼容旧 import 的 shim。新代码优先:
|
||||
|
||||
1. **`ChanKLU.py`** — Raw K-line unit with TA indicators (EMA, MACD, RSI, Bollinger Bands) and candlestick pattern recognition (`Chan_KLU_PATTERN`)
|
||||
2. **`ChanKLC.py`** — Combined K-line: inclusion processing (包含处理), fractal (分型) detection. Linked-list structure with `.next`/`.pre` pointers
|
||||
3. **`ChanBI.py`** — Stroke (笔): basic trend unit connecting alternating fractals
|
||||
4. **`ChanSBI.py`** — Special Stroke: aggregates multiple BI into higher-level units with fractal detection, feeds into SEG
|
||||
5. **`ChanSEG.py`** — Segment (线段): built from SBI strokes
|
||||
6. **`ChanZS.py`** / **`ChanBIZS.py`** — Center/pivot (中枢): consolidation zones (segment-level and stroke-level)
|
||||
7. **`ChanBSP.py`** — Buy/Sell points (买卖点): Type 1/2/3 signals
|
||||
8. **`ChanLun.py`** — Main orchestrator: ties all steps together, entry point
|
||||
9. **`TF_DF.py`** — Timeframe-aware DataFrame processor: resamples data, runs the full pipeline per timeframe, handles multi-timeframe analysis
|
||||
```python
|
||||
from chan import ChanLun, TF_DF
|
||||
from chan.indicators import IndicatorEngine, IndicatorStore
|
||||
from chan.analysis.bsp_macd import confirm_bsp, bi_macd_area
|
||||
```
|
||||
|
||||
| 层 | 路径 | 职责 |
|
||||
|----|------|------|
|
||||
| **core** | `chan/core/` | 纯结构:KLU→KLC→BI→SBI→SEG→ZS→BSP 几何;不依赖 talib/指标参数 |
|
||||
| **indicators** | `chan/indicators/` | `IndicatorConfig` / `IndicatorEngine` / `IndicatorStore`;MACD/EMA/BB/RSI 外置计算 |
|
||||
| **analysis** | `chan/analysis/` | 结构+指标接合:`ChanMACD`、`bsp_macd`(ConfirmedBSP)、Zone/Classifier 等 |
|
||||
| **pipeline** | `chan/pipeline/` | `TF_DF` / `ChanLun` 编排:先指标再结构,可选 attach 兼容 |
|
||||
|
||||
流水线:
|
||||
|
||||
1. **`chan/core/ChanKLU.py`** — K 线单元(OHLCV + 结构链);指标字段仅兼容挂载
|
||||
2. **`chan/core/ChanKLC.py`** — 合并 K 线:包含处理、分型
|
||||
3. **`chan/core/ChanBI.py`** — 笔
|
||||
4. **`chan/core/ChanSBI.py`** — 特征笔
|
||||
5. **`chan/core/ChanSEG.py`** — 线段
|
||||
6. **`chan/core/ChanZS.py`** / **`ChanBIZS.py`** — 中枢
|
||||
7. **`chan/core/ChanBSP.py`** — 几何买卖点
|
||||
8. **`chan/analysis/bsp_macd.py`** — 买卖点 × MACD 背驰 → `ConfirmedBSP`
|
||||
9. **`chan/pipeline/ChanLun.py`** / **`TF_DF.py`** — 多周期/单周期编排
|
||||
|
||||
### Support modules
|
||||
|
||||
- **`ChanEnum.py`** — All enumerations: K-line types, fractal types, MACD states, buy/sell point types, EMA position/semantic states, K-line patterns
|
||||
- **`ChanCTime.py`** — Chan theory time utility: auto-adaptive day understanding (e.g. crypto 24h vs stock market hours)
|
||||
- **`ChanMACD.py`** / **`ChanMACDHistSet.py`** / **`ChanMACDSeg.py`** / **`ChanMACDUnitTF.py`** — MACD state analysis and divergence detection
|
||||
- **`ChanPY.py`** — Consolidation (盘整) analysis
|
||||
- **`ChanHeng.py`** — Sideways market analysis
|
||||
- **`Chan_FX_Box.py`** — Fractal box (分型箱体) detection
|
||||
- **`ChanLun_Classifier.py`** — Standalone classifier script: runs full pipeline and classifies market states
|
||||
- **`chan/core/ChanEnum.py`** — 枚举
|
||||
- **`chan/core/ChanCTime.py`** — 时间工具
|
||||
- **`chan/analysis/ChanMACD*.py`** — MACD 状态/段分析(读 KLU 上兼容指标或 Store)
|
||||
- **`chan/analysis/ChanZone.py`** / **`ChanHeng.py`** / **`ChanLun_Classifier.py`** 等 — 分析扩展
|
||||
- **`chan/analysis/ChanPY.py`** — 外部 chan.py 桥接(与本包名冲突已隔离)
|
||||
|
||||
### Services
|
||||
|
||||
- **`data_provider/`** — FastAPI data service: fetches crypto data from Binance via CCXT, caches to CSV, serves REST API + WebSocket. Synthesizes derived timeframes (e.g. 5m/15m/4h from 1m/1h base). Port 9009.
|
||||
- **`web/`** — Flask web UI for interactive chart visualization with Chan theory overlays. Port 8123.
|
||||
- **`web/`** — Flask web UI for interactive chart visualization with Chan theory overlays. Port 8123.(本重构分支不改 web)
|
||||
- **`strategies/`** — Freqtrade trading strategies using the Chan theory engine (53 strategies)
|
||||
- **`config/`** — Freqtrade JSON config files per pair/timeframe
|
||||
|
||||
### Data Flow
|
||||
|
||||
```
|
||||
Exchange (CCXT) → data_provider (CSV cache) → Freqtrade → Strategy → ChanLun → TF_DF
|
||||
→ KLU → KLC → BI → SBI → SEG → ZS → BSP
|
||||
Exchange (CCXT) → data_provider (CSV cache) → Freqtrade → Strategy
|
||||
→ ChanLun / TF_DF
|
||||
→ IndicatorEngine → IndicatorStore
|
||||
→ KLU → KLC → BI → SBI → SEG → ZS → 几何 BSP
|
||||
→ analysis.bsp_macd → ConfirmedBSP
|
||||
```
|
||||
|
||||
## Common Commands
|
||||
|
||||
Reference in New Issue
Block a user