| | |
| | | * 获得 algoId、状态、订单类型等信息。相当于 Gate 的 {@code futures.autoorders} 频道。 |
| | | * |
| | | * <h3>订阅格式</h3> |
| | | * 私有频道,需要先登录认证。订阅时需要指定 instType 和 instId: |
| | | * 私有频道,需要先登录认证。orders-algo 频道不支持 instId,需使用 instFamily: |
| | | * <pre> |
| | | * {"op":"subscribe","args":[{"channel":"orders-algo","instType":"SWAP","instId":"ETH-USDT-SWAP"}]} |
| | | * {"op":"subscribe","args":[{"channel":"orders-algo","instType":"SWAP","instFamily":"ETH-USDT"}]} |
| | | * </pre> |
| | | * |
| | | * <h3>数据推送格式(条件单触发/成交)</h3> |
| | |
| | | /** OKX 配置 */ |
| | | private final OkxConfig config; |
| | | |
| | | /** 交易品种族(如 "ETH-USDT",从合约名 ETH-USDT-SWAP 派生) */ |
| | | private final String instFamily; |
| | | |
| | | /** |
| | | * 构造条件订单频道处理器。 |
| | | * |
| | |
| | | config.getContract(), |
| | | gridTradeService); |
| | | this.config = config; |
| | | // orders-algo 频道不支持 instId,需用 instFamily:"ETH-USDT-SWAP" → "ETH-USDT" |
| | | String contract = config.getContract(); |
| | | int lastDash = contract.lastIndexOf('-'); |
| | | this.instFamily = lastDash > 0 ? contract.substring(0, lastDash) : contract; |
| | | } |
| | | |
| | | /** |
| | | * 发送订阅请求,需指定 instType 和 instId。 |
| | | * 发送订阅请求,使用 instFamily 而非 instId。 |
| | | * |
| | | * @param ws 私有频道 WebSocket 客户端 |
| | | */ |
| | |
| | | JSONObject arg = new JSONObject(); |
| | | arg.put("channel", CHANNEL_NAME); |
| | | arg.put("instType", "SWAP"); |
| | | arg.put("instId", getInstId()); |
| | | arg.put("instFamily", instFamily); // orders-algo 频道用 instFamily,不能用 instId |
| | | args.add(arg); |
| | | msg.put("args", args); |
| | | ws.send(msg.toJSONString()); |
| | | log.info("[OKX-WS] 订阅条件订单频道, instId: {}", getInstId()); |
| | | log.info("[OKX-WS] 订阅条件订单频道, instFamily: {}", instFamily); |
| | | } |
| | | |
| | | /** |
| | |
| | | JSONObject arg = new JSONObject(); |
| | | arg.put("channel", CHANNEL_NAME); |
| | | arg.put("instType", "SWAP"); |
| | | arg.put("instId", getInstId()); |
| | | arg.put("instFamily", instFamily); |
| | | args.add(arg); |
| | | msg.put("args", args); |
| | | ws.send(msg.toJSONString()); |
| | | log.info("[OKX-WS] 取消订阅条件订单频道, instId: {}", getInstId()); |
| | | log.info("[OKX-WS] 取消订阅条件订单频道, instFamily: {}", instFamily); |
| | | } |
| | | |
| | | /** |
| | |
| | | for (int i = 0; i < dataArray.size(); i++) { |
| | | JSONObject orderData = dataArray.getJSONObject(i); |
| | | |
| | | // 按 instId 过滤 |
| | | // 按合约名称精确过滤(instFamily 已做粗筛,这里精筛) |
| | | String dataInstId = orderData.getString("instId"); |
| | | String instId = arg.getString("instId"); |
| | | if (instId != null && dataInstId != null |
| | | && !instId.equals(dataInstId) |
| | | && !dataInstId.startsWith(contract)) { |
| | | if (dataInstId == null || !contract.equals(dataInstId)) { |
| | | continue; |
| | | } |
| | | |