Administrator
3 days ago 5c3737c9718ad01a4d2a4a02c09548fcc3966438
src/main/java/com/xcong/excoin/modules/gateApi/gateApi-logic.md
@@ -141,12 +141,12 @@
### 网格队列生成
以基底入场价为基准,按 `gridRate` 步长生成 N 个价格(N = gridQueueSize,默认50):
以基底入场价为基准,按 `gridRate`(百分比步长)生成 N 个价格(N = gridQueueSize,默认50):
| 队列 | 计算方式 | 排序 |
|------|---------|------|
| 空仓队列 shortPriceQueue | 基底空入场价 - gridRate × i (i=1..N) | 降序(大→小) |
| 多仓队列 longPriceQueue | 基底多入场价 + gridRate × i (i=1..N) | 升序(小→大) |
| 空仓队列 shortPriceQueue | 基底空入场价 × (1 − gridRate × i) (i=1..N) | 降序(大→小) |
| 多仓队列 longPriceQueue | 基底多入场价 × (1 + gridRate × i) (i=1..N) | 升序(小→大) |
### K线触发网格
@@ -158,7 +158,7 @@
│   ├─ 保证金检查: positionInitialMargin / initialPrincipal < marginRatioLimit(20%)
│   │   ├─ 安全 → openShort 开空单(成交后仓位推送会自动设止盈)
│   │   └─ 超限 → 跳过开仓,队列照常更新
│   ├─ 空仓队列: 移除匹配元素,尾部补充新价格(按步长递减)
│   ├─ 空仓队列: 移除匹配元素,尾部补充新价格(尾价 × (1 − gridRate))
│   └─ 多仓队列: 接收匹配元素,升序排列,截断到 gridQueueSize
└─ processLongGrid: 当前价 > 多仓队列元素(价格涨超了队列中的低价)
@@ -166,22 +166,24 @@
    ├─ 保证金检查: 同上
    │   ├─ 安全 → openLong 开多单
    │   └─ 超限 → 跳过开仓
    ├─ 多仓队列: 移除匹配元素,尾部补充新价格(按步长递增)
    ├─ 多仓队列: 移除匹配元素,尾部补充新价格(尾价 × (1 + gridRate))
    └─ 空仓队列: 接收匹配元素,降序排列,截断到 gridQueueSize
```
### 队列转移示意
```
初始状态:
  空仓队列: [100, 99, 98, 97]  (降序)
  多仓队列: [102, 103, 104, 105] (升序)
ETH_USDT, gridRate=0.0035, 基底空入场价=2275, 基底多入场价=2275:
价格跌到 98.5 → processShortGrid 触发:
  匹配: [100, 99](都 > 98.5)
初始状态:
  空仓队列: [2267.1, 2270.0, 2272.5, 2275.0]  (降序,base×0.9965, base×0.993...)
  多仓队列: [2275.0, 2277.5, 2280.0, 2282.5]  (升序,base×1.0035, base×1.007...)
价格跌到 2271 → processShortGrid 触发:
  匹配: [2275.0, 2272.5](都 > 2271)
  
  空仓队列: 移除[100,99] → [98,97] → 补充[96,95] → [98,97,96,95]
  多仓队列: 接收[100,99] → [100,99,102,103,104,105] → 截断到4 → [102,103,104,105]
  空仓队列: 移除[2275.0,2272.5] → [2270.0,2267.1] → 补充[2267.1×0.9965≈2259.1, 2259.1×0.9965≈2251.2] → [2270.0,2267.1,2259.1,2251.2]
  多仓队列: 接收[2275.0,2272.5] → 合并后截断到4 → [2272.5,2275.0,2277.5,2280.0]
```
---
@@ -370,7 +372,7 @@
| 切持仓模式 | `POST /futures/usdt/set_position_mode` | `FuturesApi.setPositionMode()` | |
| 查仓位 | `GET /futures/usdt/positions` | `FuturesApi.listPositions()` | 遍历所有仓位,按合约过滤 |
| 市价平仓 | `POST /futures/usdt/orders` | `FuturesApi.createFuturesOrder()` | reduce_only, IOC。双向: size=0+close=false+autoSize |
| 设杠杆 | `POST /futures/usdt/positions/{contract}/leverage` | `FuturesApi.updateContractPositionLeverageCall()` | |
| 设杠杆 | `POST /futures/usdt/dual_comp/positions/{contract}/leverage` | `FuturesApi.updateDualModePositionLeverageCall()` | 双向模式专用 |
| 查账户 | `GET /futures/usdt/accounts` | `FuturesApi.listFuturesAccounts()` | 获取初始本金和保证金 |
| 清除条件单 | `DELETE /futures/usdt/price_orders` | `FuturesApi.cancelPriceTriggeredOrderList()` | |
| 市价单 | `POST /futures/usdt/orders` | `FuturesApi.createFuturesOrder()` | price=0, tif=IOC |