Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Part II: Productization

🇺🇸 English    |    🇨🇳 中文

🇺🇸 English

📦 Code Changes: View Diff

Core Objective: Upgrade the core matching engine into a complete trading system with Account System, Fund Transfer, and Security Authentication.


1. Review: Achievements of Part I

ChapterTopicKey Achievement
0x01GenesisMinimal Matching Prototype
0x02-03Floats & DecimalsFinancial Grade Precision
0x04BTree OrderBookO(log n) Matching
0x05-06User BalanceLocking/Unlocking
0x07Testing Framework100K Order Baseline
0x08Multi-Thread Pipeline4-Thread Concurrency
0x09Gateway & PersistenceGateway, TDengine, WebSocket

2. Gap Analysis: From Engine to System

DimensionCurrent StateTarget State
IdentityRaw user_idAPI Key Signature
AccountsSingle BalanceFunding + Spot Dual-Account
FundsManual deposit()Deposit/Withdraw/Transfer
EconomicsZero FeeMaker/Taker Fees

3. Blueprint for Part II

0x0A ─── Account System & Security
        ├── 0x0A-a: Account System (exchange_info + DB)
        ├── 0x0A-b: ID Specification (Asset/Symbol Naming)
        └── 0x0A-c: Authentication (API Key Middleware)

0x0B ─── Fund System & Transfers
        ├── Funding/Spot Dual-Account Structure
        └── Deposit/Withdraw API

0x0C ─── Economic Model
        └── Fee Calculation & Deduction

0x0D ─── Snapshot & Recovery
        └── Graceful Shutdown & State Restoration

4. Tech Stack Choices

ComponentChoicePurpose
PostgreSQL 18Account/Asset/SymbolRelational Config Data
TDengineOrders/Trades/K-LinesTime-Series Trading Data
sqlxRust PG DriverAsync + Compile-time Check

5. Design Principles

PrincipleDescription
Minimal External DepsAuth/Transfer logic is cohesive
AuditabilityAll fund changes must have event logs
ProgressiveSystem remains runnable after each module
Backward CompatibleReuse Core types from Part I



🇨🇳 中文

📦 代码变更: 查看 Diff

核心目的:将撮合引擎核心升级为具备账户体系、资金划转和安全鉴权的完整交易系统。


1. 回顾:第一部分的成就

章节主题关键成果
0x01创世纪最简撮合原型
0x02-03浮点数与定点数金融级精度保障
0x04BTree OrderBookO(log n) 撮合
0x05-06用户余额锁定/解锁机制
0x07测试框架100K 订单基线
0x08多线程 Pipeline四线程并发架构
0x09接入层 & 持久化Gateway, TDengine, WebSocket

2. 差距分析:从引擎到系统

维度当前状态目标状态
身份认证user_id 裸奔API Key 签名校验
账户管理单一余额结构Funding + Spot 双账户
资金流转手动 deposit()完整充提+划转流程
经济模型零手续费Maker/Taker 费率

3. 第二部分蓝图

0x0A ─── 账户体系与安全鉴权
        ├── 0x0A-a: 账户体系 (exchange_info + DB 管理)
        ├── 0x0A-b: ID 规范 (Asset/Symbol 命名)
        └── 0x0A-c: 安全鉴权 (API Key 中间件)

0x0B ─── 资金体系与划转
        ├── Funding/Spot 双账户结构
        └── 充提币 API

0x0C ─── 经济模型
        └── 手续费计算与扣除

0x0D ─── 快照与恢复
        └── 优雅停机与状态恢复

4. 技术选型

组件选型用途
PostgreSQL 18账户/资产/交易对关系型配置数据
TDengine订单/成交/K线时序交易数据
sqlxRust PG Driver异步 + 编译时检查

5. 设计原则

原则说明
最小外部依赖鉴权、划转等逻辑内聚
可审计性所有资金变动必须有完整事件流水
渐进式增强每个子模块完成后保持系统可运行
向后兼容复用 Part I 的核心类型