| | |
| | | Spring @PostConstruct |
| | | → GateConfig.builder()...build() |
| | | → GateGridTradeService(config) |
| | | → init(): 查ID → 查账户切持仓 → 清旧条件单 → 设杠杆 |
| | | → init(): 查ID → 查账户切持仓 → 清旧条件单 → 平已有仓位 → 设杠杆 |
| | | → GateKlineWebSocketClient(config.getWsUrl()) |
| | | → addChannelHandler x3 → init() → connect() |
| | | → onOpen: handlers依次subscribe → sendPing |
| | |
| | | |------|-----|------| |
| | | | 获取用户ID | `GET /account/detail` | `AccountApi.getAccountDetail()` | |
| | | | 切持仓模式 | `POST /futures/usdt/set_position_mode` | `FuturesApi.setPositionMode()` | |
| | | | 查仓位 | `GET /futures/usdt/positions` | `FuturesApi.listPositions()` | |
| | | | 市价平仓 | `POST /futures/usdt/orders` (reduce_only, IOC) | `FuturesApi.createFuturesOrder()` | |
| | | | 设杠杆 | `POST /futures/usdt/positions/{contract}/leverage` | `FuturesApi.updateContractPositionLeverageCall()` | |
| | | | 查账户 | `GET /futures/usdt/accounts` | `FuturesApi.listFuturesAccounts()` | |
| | | | 清除条件单 | `DELETE /futures/usdt/price_orders` | `FuturesApi.cancelPriceTriggeredOrderList()` | |
| | | | 市价单 | `POST /futures/usdt/orders` (price=0, IOC) | `FuturesApi.createFuturesOrder()` | |
| | | | 条件单 | `POST /futures/usdt/price_orders` | `FuturesApi.createPriceTriggeredOrder()` | |
| | | |
| | | --- |
| | | **初始化顺序** (`init()`): |
| | | ``` |
| | | 1. 获取用户 ID |
| | | 2. 查账户 → 如需要切持仓模式 |
| | | 3. 清除旧的止盈止损条件单 |
| | | 4. 市价平掉当前合约所有已有仓位(确保从零持仓开始) |
| | | 5. 设杠杆 |
| | | 6. 打印账户余额 |
| | | ``` |
| | | |
| | | ## GateWebSocketClientMain |
| | | --- |
| | | |
| | | 独立 `main()` 方法入口,通过 Spring XML 上下文启动,运行后手动关闭。 |
| | | |