02bc3c14bc
Add docs/env-sync-scripts.md; cross-link from deploy README, feature docs, README, and script headers. Co-authored-by: Cursor <cursoragent@cursor.com>
117 lines
3.4 KiB
Markdown
117 lines
3.4 KiB
Markdown
# 四所 `.env` 同步脚本说明
|
||
|
||
在**仓库根目录**执行。仅处理四所实例目录下的 `.env`,**不覆盖** API 密钥与已存在的自定义值;若某目录无 `.env` 会 `SKIP`(需先 `cp .env.example .env`)。
|
||
|
||
| 目录 |
|
||
|------|
|
||
| `crypto_monitor_binance` |
|
||
| `crypto_monitor_okx` |
|
||
| `crypto_monitor_gate` |
|
||
| `crypto_monitor_gate_bot` |
|
||
|
||
修改 `.env` 后须 **`pm2 restart`** 对应实例后生效。
|
||
|
||
---
|
||
|
||
## 一键同步(推荐)
|
||
|
||
`scripts/sync_four_exchange_env.py`:依次执行**计仓** + **自动划转** 两个子脚本。
|
||
|
||
```bash
|
||
cd /path/to/crypto_monitor
|
||
git pull
|
||
|
||
# 仅补全缺失项(已有值保留)
|
||
python scripts/sync_four_exchange_env.py
|
||
|
||
# 预览,不写文件
|
||
python scripts/sync_four_exchange_env.py --dry-run
|
||
|
||
# 划转目标 50U 并开启自动划转(计仓仍只补缺失项)
|
||
python scripts/sync_four_exchange_env.py --set-transfer-amount 50 --enable-auto-transfer
|
||
|
||
# 无仓后切换全仓杠杆(须先确认交易所无持仓)
|
||
python scripts/sync_four_exchange_env.py --set-mode full_margin
|
||
```
|
||
|
||
| 参数 | 说明 |
|
||
|------|------|
|
||
| `--dry-run` | 只打印将做的变更,不写 `.env` |
|
||
| `--set-mode risk\|full_margin` | 强制四所 `POSITION_SIZING_MODE` |
|
||
| `--set-transfer-amount U` | 强制四所 `AUTO_TRANSFER_AMOUNT` |
|
||
| `--enable-auto-transfer` | 强制四所 `AUTO_TRANSFER_ENABLED=true` |
|
||
|
||
---
|
||
|
||
## 仅自动划转
|
||
|
||
`scripts/sync_four_exchange_transfer_env.py`
|
||
|
||
行为说明见 [auto-transfer-daily.md](./auto-transfer-daily.md)。
|
||
|
||
```bash
|
||
# 补全缺失项
|
||
python scripts/sync_four_exchange_transfer_env.py
|
||
python scripts/sync_four_exchange_transfer_env.py --dry-run
|
||
|
||
# 目标 50U 并开启
|
||
python scripts/sync_four_exchange_transfer_env.py --set-amount 50 --enable-auto-transfer
|
||
```
|
||
|
||
| 参数 | 说明 |
|
||
|------|------|
|
||
| `--dry-run` | 预览 |
|
||
| `--set-amount U` | 强制 `AUTO_TRANSFER_AMOUNT` |
|
||
| `--enable-auto-transfer` | 强制 `AUTO_TRANSFER_ENABLED=true` |
|
||
|
||
**缺项默认**(未使用 `--set-amount` 且文件中无该键时):
|
||
|
||
1. 若已有 `AUTO_TRANSFER_AMOUNT` → 保留
|
||
2. 否则若存在 `DAILY_START_CAPITAL` → 沿用其值
|
||
3. 否则 → **50**
|
||
|
||
补全时会写入(若缺失):`AUTO_TRANSFER_FROM=funding`、`AUTO_TRANSFER_TO=swap`、`TRANSFER_CCY=USDT`、`AUTO_TRANSFER_BJ_HOUR=8`;币安额外补 `BINANCE_FUNDING_INCLUDE_SPOT=false`。
|
||
|
||
---
|
||
|
||
## 仅计仓模式
|
||
|
||
`scripts/sync_four_exchange_position_sizing_env.py`
|
||
|
||
行为说明见 [position-sizing-mode.md](./position-sizing-mode.md)。
|
||
|
||
```bash
|
||
# 补全缺失项(默认 risk、FULL_MARGIN_BUFFER_RATIO=0.98)
|
||
python scripts/sync_four_exchange_position_sizing_env.py
|
||
python scripts/sync_four_exchange_position_sizing_env.py --dry-run
|
||
|
||
# 无仓后切全仓
|
||
python scripts/sync_four_exchange_position_sizing_env.py --set-mode full_margin
|
||
|
||
# 无仓后切回以损定仓
|
||
python scripts/sync_four_exchange_position_sizing_env.py --set-mode risk
|
||
|
||
# 强制缓冲比例
|
||
python scripts/sync_four_exchange_position_sizing_env.py --set-buffer 0.98
|
||
```
|
||
|
||
| 参数 | 说明 |
|
||
|------|------|
|
||
| `--dry-run` | 预览 |
|
||
| `--set-mode risk\|full_margin` | 强制 `POSITION_SIZING_MODE`(**须无持仓**后 restart) |
|
||
| `--set-buffer RATIO` | 强制 `FULL_MARGIN_BUFFER_RATIO` |
|
||
|
||
---
|
||
|
||
## 部署后重启
|
||
|
||
```bash
|
||
pm2 restart crypto-monitor-binance crypto-monitor-okx crypto-monitor-gate crypto-monitor-gate-bot
|
||
```
|
||
|
||
## 相关文档
|
||
|
||
- [计仓模式](./position-sizing-mode.md)
|
||
- [每日自动划转](./auto-transfer-daily.md)
|
||
- [部署说明](../deploy/README.md)
|