| | |
| | | return isSuccess(result, "设置杠杆"); |
| | | } |
| | | |
| | | public String fetchInstIdCode(String instType, String instId) { |
| | | public boolean cancelAllOrders(String instId) { |
| | | JSONObject params = new JSONObject(); |
| | | params.put("instType", "SWAP"); |
| | | params.put("instId", instId); |
| | | JSONObject result = post("/api/v5/trade/cancel-all-orders", params); |
| | | return isSuccess(result, "撤销所有委托单"); |
| | | } |
| | | |
| | | public boolean closeAllPositions(String instId, String mgnMode) { |
| | | JSONObject params = new JSONObject(); |
| | | params.put("instType", "SWAP"); |
| | | params.put("instId", instId); |
| | | params.put("mgnMode", mgnMode); |
| | | JSONObject result = post("/api/v5/trade/close-all-positions", params); |
| | | return isSuccess(result, "平仓ETH"); |
| | | } |
| | | |
| | | public Long fetchInstIdCode(String instType, String instId) { |
| | | String path = "/api/v5/account/instruments?instType=" + instType + "&instId=" + instId; |
| | | JSONObject result = get(path); |
| | | if (result == null || !"0".equals(result.getString("code"))) { |
| | |
| | | return null; |
| | | } |
| | | JSONObject first = data.getJSONObject(0); |
| | | String instIdCode = first.getString("instIdCode"); |
| | | Long instIdCode = first.getLong("instIdCode"); |
| | | log.info("[REST] 获取instIdCode成功, instId:{}, instIdCode:{}", instId, instIdCode); |
| | | return instIdCode; |
| | | } |
| | |
| | | |
| | | int code = conn.getResponseCode(); |
| | | String response = readResponse(conn); |
| | | log.info("[REST] GET {} → HTTP {} body:{}", path, code, response); |
| | | if (code < 200 || code >= 300) { |
| | | log.error("[REST] GET {} → HTTP {} body:{}", path, code, response); |
| | | } |
| | | |
| | | return JSON.parseObject(response); |
| | | } catch (Exception e) { |
| | |
| | | |
| | | int code = conn.getResponseCode(); |
| | | String response = readResponse(conn); |
| | | log.info("[REST] POST {} → HTTP {} body:{}", path, code, response); |
| | | if (code < 200 || code >= 300) { |
| | | log.error("[REST] POST {} → HTTP {} body:{}", path, code, response); |
| | | } |
| | | |
| | | return JSON.parseObject(response); |
| | | } catch (Exception e) { |