# Stock Server

## 中文概要

Stock Server 是一个股票研究与交易工程平台，覆盖行情可视化、策略配置与回测、盘前扫描、券商接入、模拟与实盘执行，以及交易日志和组合分析。

系统以 Vue 3 / TypeScript 构建交互界面，以 Node.js 多服务和共享业务包组织后端，结合 HTTP/2 流式通信、MongoDB 与 SQLite 管理任务和数据。AutoTrading 承载研究与交易服务，WorthInvesting 提供独立分析前端，另有复用 Web 界面的 Electron 桌面应用工程。

工程重点包括：保存回测任务的配置与数据范围；区分监控信号、订单回报与持仓状态；跟踪实时行情连接和数据时效；按职责划分服务，并区分 Paper / Live 环境。

### 主要能力

- 行情分析：股票与行业热力图、个股图表、K 线及多维指标展示。
- 策略研究：参数配置、历史回测、任务暂停与恢复、结果及交易明细查询。
- 实时监控：证券信息、盘前候选、扫描批次记录和行情订阅。
- 交易执行：LongBridge / IBKR 接入，模拟与实盘任务、订单和持仓管理。
- 复盘分析：交易日志、投资组合、分析模板、筛选条件及结果查询。

### 技术实现亮点

- 图表组件：扩展 TradingView Lightweight Charts，将指标、Tooltip、行情回放与 tick 更新封装为可复用的 Vue 组件。
- 服务基座：通过 ServerBootstrap 与 Action 注册组织普通请求、SSE 流、健康检查和错误响应；用共享领域模型减少服务间重复定义。
- 回测任务：分离配置、计算过程与结果记录，支持创建、暂停、恢复和结果查询，让参数、执行过程和结果可以关联复查。
- 券商适配：围绕 IBKR Gateway / TWS API 和 Node API 处理连接状态、错误事件与订阅；LongBridge、OKX 通过独立服务接入。
- 工作流集成：TradeLog 可选择 n8n 代理或嵌入式东方财富交易端，组织持仓查询、交易请求、会话检查与成交导入。具体自动化行为取决于工作流配置和实际部署。

### 简短介绍

连接行情、策略回测与交易执行的工程平台。以 Vue 3、TypeScript 和 Node.js 多服务实现研究、监控、订单与复盘流程，关注任务可追溯、异步状态和模拟 / 实盘边界。

## English overview

Stock Server is a stock research and trading engineering platform covering market visualization, strategy configuration and backtesting, premarket scanning, broker integration, paper and live execution, trade logs, and portfolio analysis.

Vue 3 and TypeScript power the interfaces, while Node.js services and shared business packages organize the backend. HTTP/2 streaming, MongoDB, and SQLite support task and data management. AutoTrading hosts research and execution services; WorthInvesting provides a separate analysis frontend. The codebase also includes Electron desktop application tooling that reuses the Web interface.

Engineering priorities include retaining backtest configurations and data ranges; distinguishing signals, order events, and positions; observing quote-stream health and data freshness; and separating service responsibilities and paper/live environments.

### Core capabilities

- Market analysis: stock and sector heatmaps, individual charts, candlesticks, and configurable visualization metrics.
- Strategy research: parameters, historical backtests, task pause/resume, results, and trade details.
- Monitoring: security reference data, premarket candidates, scan records, and quote subscriptions.
- Execution: LongBridge / IBKR integration and paper/live task, order, and position management.
- Review: trade logs, portfolios, analysis templates, filters, and result queries.

### Implementation highlights

- Chart components: extend TradingView Lightweight Charts with reusable Vue interfaces for indicators, tooltips, market replay, and tick updates.
- Service foundation: ServerBootstrap and Action registration organize requests, SSE streams, health checks, and error responses; shared domain models reduce duplication across services.
- Backtest tasks: separate configurations, computation, and result records, with create, pause, resume, and query operations that keep parameters, execution, and results traceable.
- Broker adapters: organize connection state, errors, and subscriptions around IBKR Gateway / TWS API and the Node API; separate services integrate LongBridge and OKX.
- Workflow integration: TradeLog can use an n8n proxy or an embedded East Money interface for position queries, trading requests, session checks, and execution imports. Automation behavior depends on workflow configuration and deployment.

### Short description

A platform connecting market data, strategy backtesting, and trade execution. Vue 3, TypeScript, and Node.js services support research, monitoring, orders, and review, with an emphasis on task traceability, asynchronous state, and paper/live boundaries.

---

本概要为软件项目介绍，不提供投资建议或收益承诺。回测、模拟与实盘结果不可混同；券商功能需要相应数据权限和账户授权。

This is a software project overview, not investment advice or a return guarantee. Backtest, paper, and live results are distinct. Broker features require appropriate data permissions and account authorization.
