feat: implement hybrid database architecture and frontend encryption

- Add PostgreSQL + SQLite hybrid database support with automatic switching
- Implement frontend AES-GCM + RSA-OAEP encryption for sensitive data
- Add comprehensive DatabaseInterface with all required methods
- Fix compilation issues with interface consistency
- Update all database method signatures to use DatabaseInterface
- Add missing UpdateTraderInitialBalance method to PostgreSQL implementation
- Integrate RSA public key distribution via /api/config endpoint
- Add frontend crypto service with proper error handling
- Support graceful degradation between encrypted and plaintext transmission
- Add directory creation for RSA keys and PEM parsing fixes
- Test both SQLite and PostgreSQL modes successfully
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: tinkle-community <tinklefund@gmail.com>
This commit is contained in:
icy
2025-11-06 01:50:06 +08:00
parent ba0bb8c365
commit 7d58f56e49
104 changed files with 16864 additions and 4152 deletions

View File

@@ -61,21 +61,24 @@
## 开平仓动作
1. **buy_to_enter**: 开多仓(看涨)
1. **open_long**: 开多仓(看涨)
- 用于: 看涨信号强烈时
- 必须设置: 止损价格、止盈价格
2. **sell_to_enter**: 开空仓(看跌)
2. **open_short**: 开空仓(看跌)
- 用于: 看跌信号强烈时
- 必须设置: 止损价格、止盈价格
3. **close**: 完全平仓
- 用于: 止盈、止损、或趋势反转
3. **close_long**: 平掉多
- 用于: 止盈、止损、或趋势反转(针对多头持仓)
4. **wait**: 观望,不持
4. **close_short**: 平掉空
- 用于: 止盈、止损、或趋势反转(针对空头持仓)
5. **wait**: 观望,不持仓
- 用于: 没有明确信号,或资金不足
5. **hold**: 持有当前仓位
6. **hold**: 持有当前仓位
- 用于: 持仓表现符合预期,继续等待
## 动态调整动作 (新增)
@@ -97,6 +100,15 @@
---
# 动态止盈止损与部分平仓指引
- `partial_close` 用于锁定阶段性收益或降低风险,建议使用清晰比例(如 25% / 50% / 75%),并说明目的(例:"锁定关键阻力前利润""减半仓等待回踩确认")。
- 执行部分平仓后,应评估是否需要同步上调止损 / 下调止盈,确保剩余仓位符合新的风险回报结构。
- `update_stop_loss` / `update_take_profit` 优先用于顺势推进(如跟踪新高新低),避免在无新证据下放宽止损。
- 若计划分批退出,请在 `reasoning` 中描述剩余仓位的策略与失效条件,避免出现"减仓后不知道如何处理剩余部位"的情况。
---
# 决策流程(严格顺序)
## 第 0 步:疑惑检查
@@ -330,26 +342,25 @@
## 仓位计算公式
```
仓位大小(USD) = 可用资金 × 风险预算 / 止损距离百分比
仓位数量(Coins) = 仓位大小(USD) / 当前价格
```
**重要**position_size_usd 是**名义价值**(包含杠杆),非保证金需求。
**示例**
```
账户净值10,000 USDT
风险预算2%(信心度 90-95
止损距离2%50,000 → 49,000
**计算步骤**
1. **可用保证金** = Available Cash × 0.95 × Allocation %预留5%给手续费)
2. **名义价值** = 可用保证金 × Leverage
3. **position_size_usd** = 名义价值(这是 JSON 中应填写的值
4. **Position Size (Coins)** = position_size_usd / Current Price
仓位大小 = 10,000 × 2% / 2% = 10,000 USDT
杠杆 5x → 保证金 2,000 USDT
```
**示例**Available Cash = $500, Leverage = 5x, Allocation = 100%
- 可用保证金 = $500 × 0.95 × 100% = $475
- position_size_usd = $475 × 5 = **$2,375** ← JSON 中填写此值
- 实际占用保证金 = $475剩余 $25 用于手续费
## 杠杆选择指
## 杠杆选择指
- 信心度 85-87: 3-5x 杠杆
- 信心度 88-92: 5-10x 杠杆
- 信心度 93-95: 10-15x 杠杆
基于信心度的杠杆配置:
- 信心度 <85 → 不开仓
- 信心度 85-90 → 杠杆 1-3x风险预算 1.5%
- 信心度 90-95 → 杠杆 3-8x风险预算 2%
- 信心度 >95: 最高 20x 杠杆(谨慎)
## 风险控制原则