Files
Hermes-Skills/okx-auto-position/references/single-coin-75pct-cap.md
T

95 lines
3.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
name: single-coin-75pct-cap-and-market-hours
description: "OKX advisor 单币种 75% 总资产上限 + 推送前检查市场开盘时间"
version: 1.0.0
type: reference
---
# 🎯 单币种 75% 总资产上限 + 市场时间检查
> 用户原话(2026-07-13):
> 1. **"只持仓一种币的时候,最多加仓到账户资金的75%"**
> 2. **"A股和港股都收盘了"** → **市场休市不要推**
## 规则 1: 单币种 ≤ 75% × 账户总资产
### 公式
```
total_capital = usdt_free + 所有币种已占用的保证金
single_coin_cap = total_capital × 0.75
已持仓该币种保证金 = sum(p['margin'] for p in positions if p['symbol'].startswith(base))
还能加仓 = min(usdt_free, single_coin_cap - 已持仓该币种保证金)
```
### 关键点
- **`usdt_free`**: USDT 可用余额(不是 buy_power,不是 equity)
- **保证金取法**: OKX ccxt `fetch_positions()` 返回的 notional/leverage
- **同币种合并**: 同一币种多个 entry 都算同一个 base 的持仓(比如 BTC-USDT-SWAP 和 BTC-USD-SWAP 都算 BTC)
- **新币种**: 没持仓时 `single_coin_cap = 0.75 × total_capital`(75% 一次性)
### 实现位置
`scripts/okx_position_advisor.py`:
- `get_account_info()`: 新增 `used_margin``total_capital` 字段
- `recommend_position()`: 用 `min(usdt_free, single_coin_cap - same_coin_margin)` 代替旧的 `usdt_free × 0.45`
### 配置
```yaml
position_sizing:
single_coin_max_pct: 0.75 # 单币种上限, 默认 75%
```
### 用户场景验证(2026-07-13 实测)
账户:$47.69 free + $60.58 used_margin = **$108.26 total_capital**
持仓:SKHYNIX 0.216张 @ $60.58 保证金
| 场景 | 旧(45% free) | 新(75% total_cap) |
|------|--------------|-------------------|
| 加仓 SKHYNIX(已占 $60) | 45% × $47 = $21.5 | **$20.64**(75% cap - $60) |
| 新开 BTC(无持仓) | 45% × $47 = $21.5 | **$47.42**(75% × $108) |
| 新开 ETH(无持仓) | 45% × $47 = $21.5 | **$47.74**(75% × $108) |
⚠️ **新开币种占用 75%**(可能偏激进),加仓受限合理。
## 规则 2: 市场休市不要推交易清单
### 交易时间(北京时间)
| 市场 | 上午 | 下午 | 备注 |
|------|------|------|------|
| A 股 | 9:30-11:30 | 13:00-15:00 | 周末闭市 |
| 港股 | 9:30-12:00 | 13:00-16:00 | 周末闭市 |
| 美股 | (北京时间晚)| 21:30-04:00 | 周日-周四晚上开盘 |
### 检查时机
所有"交易清单"类推送(分红扫描、选股、跟单)推之前:
1. 检查当前北京时间
2. 判断对应市场是否开盘
3. **收盘后不要推** → 用户看到也无法买
### 修正历史(2026-07-13)
- `dividend_alert.py` cron schedule 原本 `30 20 * * 1-5`(晚上 8:30 推) → 修正为 `0 11 * * 1-5`(11:00 上午)
- 新建 cron `366934c1474c`(美股 21:00 推,美股开盘前 30 分钟)
- 分流逻辑:`--market cn_hk` / `--market us` 两个 cron
## 应用清单
| 触发 | 检查方式 |
|------|---------|
| cron 推交易清单 | 调度时间本身就按市场时间 |
| 实时跟单信号 | advisor 加 market_closed 标记 + 不推 |
| cron 触发但用户手动改时间 | 跑前 `datetime.now()` 对比市场时间 |
## 相关
- 用户原话(2026-07-13):
- "只持仓一种币的时候,最多加仓到账户资金的75%"
- "A股和港股都收盘了,你推来我也只能明天再买了"
- 实现代码:`scripts/okx_position_advisor.py`
- 实测时间:2026-07-13 (account $47.69 free, $60.58 used, $108.26 total)