docs: 更新 README 文件,添加静默启动和后台运行的说明,包括命令行用法和 pm2 配置示例

This commit is contained in:
discountry
2025-09-28 01:39:49 +08:00
parent 5c1283fac2
commit d6533733c9
2 changed files with 76 additions and 0 deletions
+36
View File
@@ -80,6 +80,42 @@ bun run dev # 调试模式,等价于运行 index.ts
bun x vitest run # 执行单元测试
```
## 静默启动与后台运行
### 直接静默启动
无需进入 Ink 菜单,可用命令行直接拉起指定策略:
```bash
bun run index.ts --strategy trend --silent # 启动趋势策略
bun run index.ts --strategy maker --silent # 启动做市策略
bun run index.ts --strategy offset-maker --silent # 启动偏移做市策略
```
### 项目内置脚本
`package.json` 提供了便捷脚本:
```bash
bun run start:trend:silent
bun run start:maker:silent
bun run start:offset:silent
```
### 使用 pm2 守护并自动重启
将 `pm2` 安装到项目中(示例:`bun add -d pm2`),之后即可在不安装全局 pm2 的情况下运行:
```bash
bunx pm2 start bun --name ritmex-trend --cwd . --restart-delay 5000 -- run index.ts --strategy trend --silent
```
亦可直接调用脚本:
```bash
bun run pm2:start:trend
bun run pm2:start:maker
bun run pm2:start:offset
```
根据需要调整 `--name`、`--cwd`、`--restart-delay` 等参数,完成后可执行 `pm2 save` 持久化进程列表。
## 测试
项目使用 Vitest
```bash
+40
View File
@@ -77,6 +77,42 @@ bun run dev # Development entry point
bun x vitest run # Execute the Vitest suite
```
## Silent & Background Execution
### Direct silent launch
Skip the Ink menu and start a strategy straight from the CLI:
```bash
bun run index.ts --strategy trend --silent # Trend engine
bun run index.ts --strategy maker --silent # Maker engine
bun run index.ts --strategy offset-maker --silent # Offset maker engine
```
### Package scripts
Convenience aliases are exposed in `package.json`:
```bash
bun run start:trend:silent
bun run start:maker:silent
bun run start:offset:silent
```
### Daemonising with pm2
Install `pm2` locally (e.g. `bun add -d pm2`) and launch without a global install:
```bash
bunx pm2 start bun --name ritmex-trend --cwd . --restart-delay 5000 -- run index.ts --strategy trend --silent
```
You can also reuse the bundled scripts:
```bash
bun run pm2:start:trend
bun run pm2:start:maker
bun run pm2:start:offset
```
Adjust `--name`, `--cwd`, or `--restart-delay` to suit your environment and run `pm2 save` if you want the process to auto-start after reboot.
## Testing
Vitest powers the unit tests:
```bash
@@ -85,6 +121,10 @@ bun x vitest --watch
```
## Troubleshooting
- You need at least 50100 USDT of capital before deploying a live strategy.
- Set leverage on the exchange beforehand (around 50x is recommended); the bot does not change it for you.
- Keep server/desktop time in sync with real-world time to avoid signature errors.
- Make sure the exchange account is in one-way position mode.
- **Env not loading**: ensure `.env` resides in the repository root and variable names are spelled correctly.
- **Order rejected for precision**: align `PRICE_TICK`, `QTY_STEP`, and `TRADE_SYMBOL` with the exchange filters.
- **Permission or auth errors**: double-check exchange API scopes.