docs: translate README.md to English

This commit is contained in:
0xcathiefish
2026-05-30 10:00:45 +00:00
parent 25b30ebecd
commit 88052a5c5b
+59 -52
View File
@@ -1,65 +1,70 @@
# nosync
一款高效、解耦的 Hyperliquid 钱包仓位监听与 Notion 同步工具。
An efficient, decoupled Hyperliquid wallet position monitor and Notion database logger.
## 1. 项目简介
`nosync` 是一个基于 Rust 构建的实时钱包仓位监控与分析工具。它通过 WebSocket 订阅指定的 Hyperliquid 钱包地址事件,实时抓取开仓(及后续平仓)交易,并将相关交易数据自动同步整理到 Notion 对应的数据库中,帮助用户进行自动化交易跟踪与统计。
## 1. Introduction
`nosync` is a real-time wallet position monitoring and analysis tool built with Rust. It subscribes to a specified Hyperliquid wallet address via WebSockets, captures position-opening trades in real-time, aggregates multi-tick partial fills of a single order (using a 500ms debounce aggregation mechanism), and automatically synchronizes the formatted trade data to a Notion database.
## 2. 核心功能
* **实时钱包订阅**:使用 `hyperliquid-rust-sdk` 长连接订阅钱包的 `UserEvents` 变动,毫秒级感知仓位变化。
* **开仓事件识别**:通过解析成交明细的 `start_position` 是否为零,精准捕捉首次开仓(Position Opening)动作。
* **断线自动重连**:内部包含 robust 的重连与容错机制,确保网络抖动或服务关闭重启后自动恢复订阅。
* **Notion 数据同步**:集成 `notion-client` API,将捕捉到的开仓事件格式化为对应的属性并写入 Notion 数据库中(Notion 数据库结构由后续接口配置定义)。
## 2. Key Features
* **Real-time Wallet Subscription**: Uses `hyperliquid-rust-sdk` to establish a persistent WebSocket connection to the wallet's `UserEvents`, sensing position changes at millisecond latency.
* **Aggregated Fills via `oid`**: Aggregates multi-tick partial fills belonging to the same order (`oid`) within a 500ms window into a single unified row, preventing split trades from generating duplicate database entries.
* **Opening Event Capture**: Identifies position opening actions by validating if the starting position (`start_position`) is zero. Currently captures only opening positions (ignores closes to prevent tick-splitting complexity).
* **Order Type Detection**: Auto-detects order execution types (`MARKET` for taker fills with `crossed == true`, `LIMIT` for maker fills with `crossed == false`).
* **Robust Reconnection**: Implements a robust connection loop that automatically reconnects after network glitches or WebSocket drops.
* **Notion Integration**: Integrates `notion-client` API to write structured rows (`Symbol`, `Quantity`, `Filled Price`, `Direction`, `Exchange`, `DataTime`, `Order ID`, `Order Type`, `Check`) directly to a target Notion database.
## 3. 架构与模块
本项目的目录结构与模块划分如下:
## 3. Architecture & Modules
The directory structure and modules are as follows:
```
nosync/
├── src/
│ ├── lib.rs # 统一模块导出
│ ├── structs.rs # 数据模型与事件定义(如 PositionOpenEvent
── hyperliquid.rs # Hyperliquid 监听器实现(包含 HyperliquidMonitor
├── examples/ # 使用示例
│ └── demo.rs # 实时钱包监听演示
├── tests/ # 集成测试
│ └── monitor_test.rs # 监听器连通性与重连循环测试
├── references/ # 本地参考源(submodules
├── .env # 本地运行环境变量配置文件 (不提交)
├── .env.example # 环境变量配置模板
├── Cargo.toml # 远程 Git 依赖及配置
── CHANGELOG.md # 变更日志
│ ├── lib.rs # Unified module exports
│ ├── structs.rs # Data models and event definitions (e.g., NotionRowData)
── hyperliquid.rs # Hyperliquid WebSocket monitor implementation
│ └── notion.rs # Notion Database writer implementation
├── examples/ # Development examples
│ ├── demo.rs # Real-time wallet monitoring demo
│ └── fetch_notion_db.rs # Dev script to fetch Notion Database schema properties
├── tests/ # Integration and unit tests
│ └── monitor_test.rs # Monitor connectivity and reconnection loop tests
├── references/ # Local reference submodules
├── .env # Local environment variables configuration (ignored by git)
── .env.example # Environment configuration template
├── Cargo.toml # Cargo package file with remote Git dependencies
└── CHANGELOG.md # Change log
```
* **HyperliquidMonitor** (`hyperliquid`):长周期运行服务,维护与 Hyperliquid API 的长连接,订阅 `UserEvents`
* **PositionOpenEvent** (`structs`):定义了捕获到的开仓事件明细,包括币种、买卖方向、成交价格、数量、时间戳等。
* **HyperliquidMonitor** (`src/hyperliquid.rs`): Long-running service maintaining the WebSocket connection to the Hyperliquid API and emitting aggregated trade events.
* **NotionWriter** (`src/notion.rs`): Formats and writes the captured row data to the Notion database.
* **structs** (`src/structs.rs`): Defines data models like `PositionTradeEvent` and `NotionRowData`.
## 4. 环境要求
* **Rust**: `1.85.0` 或更高版本(支持最新 edition 2024
## 4. Requirements
* **Rust**: `1.85.0` or higher (supports the 2024 edition)
* **OS**: Linux, macOS, Windows
## 5. 安装与启动
## 5. Getting Started
```bash
# 克隆仓库
# Clone the repository
git clone https://github.com/cathiefish/nosync.git
cd nosync
# 复制并配置环境变量
# Copy and configure environment variables
cp .env.example .env
# 编辑 .env 文件,填入您需要监控的 WALLET_ADDRESS 及网络类型
# Edit the .env file with your WALLET_ADDRESS, Notion integration token, and database ID
# 构建项目
# Build the project
cargo build --release
# 运行监控服务
# Run the monitoring sync service
cargo run
# 运行本地监听 Demo
# Run the local monitor demo
cargo run --example demo
```
## 6. 使用示例
最小可运行示例位于 [examples/demo.rs](file:///home/cathiefish/App/nosync/examples/demo.rs)
## 6. Code Example
A minimal running example for the monitor is located at [examples/demo.rs](file:///home/cathiefish/App/nosync/examples/demo.rs):
```rust
use alloy::primitives::address;
use nosync::HyperliquidMonitor;
@@ -68,7 +73,7 @@ use tokio::sync::mpsc;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let wallet = address!("0xc64cc00b46101bd40aa1c3121195e85c0b0918d8");
let monitor = HyperliquidMonitor::new(wallet, true); // true 代表使用 Testnet
let monitor = HyperliquidMonitor::new(wallet, true); // true for Testnet
let (tx, mut rx) = mpsc::unbounded_channel();
tokio::spawn(async move {
@@ -82,30 +87,32 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
}
```
## 7. 环境变量说明
| 环境变量名 | 用途 | 是否必填 | 默认值 / 示例值 |
## 7. Environment Variables
| Variable | Description | Required | Default / Example Value |
| :--- | :--- | :--- | :--- |
| `WALLET_ADDRESS` | 需要监控的以太坊/Hyperliquid钱包地址 | **** | `0xc64cc00b46101bd40aa1c3121195e85c0b0918d8` |
| `IS_TESTNET` | 是否是 Testnet 环境 (`true`/`false`) | | `true` |
| `RUST_LOG` | 设定日志输出级别 (e.g. error, warn, info, debug) | 否 | `info` |
| `WALLET_ADDRESS` | The Ethereum/Hyperliquid wallet address to monitor | **Yes** | `0xc64cc00b46101bd40aa1c3121195e85c0b0918d8` |
| `IS_TESTNET` | Connect to Hyperliquid Testnet (`true`/`false`) | No | `true` |
| `NOTION_API_KEY` | Notion integration token (internal secret) | **Yes** | `secret_xxxxxx...` |
| `NOTION_DATABASE_ID` | Notion Database ID | **Yes** | `2b08f81ac37083389c5c01242f3c1557` |
| `RUST_LOG` | Logging verbosity level (error, warn, info, debug) | No | `info` |
## 8. 测试与开发
### 开发分支约定
* `dev`:主开发分支,新功能与修复首发合并至此。
* `main`:生产稳定分支。
## 8. Development & Testing
### Git Branching Strategy
* `dev`: Active development branch. New features and fixes are merged here first.
* `main`: Stable production-ready branch.
### 本地验证命令
在提交代码前,**必须**运行以下命令进行本地验证:
### Local Quality Checks
Before submitting pull requests, you **must** run:
```bash
# 自动格式化代码
# Auto-format codebase
cargo fmt --all
# 运行代码规范检查
# Run lint checks
cargo clippy --all-targets --all-features -- -D warnings
# 执行集成测试
# Execute test suite
cargo test
```
## 9. 变更日志指引
关于项目的详细改动,请参阅 [CHANGELOG.md](file:///home/cathiefish/App/nosync/CHANGELOG.md)
## 9. Changelog
For a detailed log of project updates, please refer to [CHANGELOG.md](file:///home/cathiefish/App/nosync/CHANGELOG.md).