| | |
| | | import java.math.BigDecimal; |
| | | |
| | | /** |
| | | * 仓位频道处理器。 |
| | | * |
| | | * <h3>数据用途</h3> |
| | | * 监控仓位数量(size)。当 size 从有变为 0 时,表示该方向被止盈条件单平仓, |
| | | * 触发补仓(reopenLongPosition / reopenShortPosition)。 |
| | | * |
| | | * <h3>推送字段</h3> |
| | | * contract, mode(dual_long / dual_short), size(正=持有,0=无仓位), entry_price |
| | | * |
| | | * <h3>注意</h3> |
| | | * 双向持仓模式下空头 size 为负数,使用 {@code size.abs()} 判断是否有仓位。 |
| | | * 累计盈亏不由本频道计算,而是由 {@link PositionClosesChannelHandler} 独立处理。 |
| | | * 仓位频道处理器(futures.positions),接收仓位更新推送并回调 {@link GateGridTradeService#onPositionUpdate}。 |
| | | * |
| | | * @author Administrator |
| | | */ |
| | |
| | | |
| | | private static final String CHANNEL_NAME = "futures.positions"; |
| | | |
| | | /** |
| | | * @param apiKey Gate API v4 密钥,用于签名认证 |
| | | * @param apiSecret Gate API v4 签名密钥 |
| | | * @param contract 合约名称(如 ETH_USDT) |
| | | * @param gridTradeService 网格交易策略服务实例 |
| | | */ |
| | | public PositionsChannelHandler(String apiKey, String apiSecret, |
| | | String contract, |
| | | GateGridTradeService gridTradeService) { |
| | |
| | | Position.ModeEnum mode = Position.ModeEnum.fromValue(modeStr); |
| | | BigDecimal size = new BigDecimal(pos.getString("size")); |
| | | BigDecimal entryPrice = new BigDecimal(pos.getString("entry_price")); |
| | | log.info("[{}] 持仓更新, 模式:{}, 数量:{}, 入场价:{}", CHANNEL_NAME, modeStr, size, entryPrice); |
| | | log.info("[{}] 持仓更新, 合约:{}, 模式:{}, 数量:{}, 入场价:{}, 全仓杠杆上限:{}, 历史盈亏:{}, 历史点卡:{}, 最近平仓盈亏:{}, 杠杆:{}, 最大杠杆:{}, 爆仓价:{}, 维持保证金率:{}, 保证金:{}, 已实现盈亏:{}, 点卡已实现盈亏:{}, 风险限额:{}, 时间:{}, 时间ms:{}, 用户:{}, 更新ID:{}", |
| | | CHANNEL_NAME, pos.getString("contract"), modeStr, size, entryPrice, |
| | | pos.get("cross_leverage_limit"), pos.get("history_pnl"), pos.get("history_point"), |
| | | pos.get("last_close_pnl"), pos.get("leverage"), pos.get("leverage_max"), |
| | | pos.get("liq_price"), pos.get("maintenance_rate"), pos.get("margin"), |
| | | pos.get("realised_pnl"), pos.get("realised_point"), pos.get("risk_limit"), |
| | | pos.get("time"), pos.get("time_ms"), pos.get("user"), pos.get("update_id")); |
| | | if (getGridTradeService() != null) { |
| | | getGridTradeService().onPositionUpdate(getContract(), mode, size, entryPrice); |
| | | } |