diff --git a/src/main/java/com/sample/trend/strategy/AutoGridStrategy.java b/src/main/java/com/sample/trend/strategy/AutoGridStrategy.java index b4526e5..8f00151 100644 --- a/src/main/java/com/sample/trend/strategy/AutoGridStrategy.java +++ b/src/main/java/com/sample/trend/strategy/AutoGridStrategy.java @@ -585,7 +585,7 @@ public class AutoGridStrategy extends BaseStrategy { String clientOrderId = buildClientOrderId("BUY", normalizedPrice); try { - JSONObject orderInfo = buildOrderRequest("buy", "open", "limit", normalizedPrice, baseQuantity, false); + JSONObject orderInfo = buildOrderRequest("buy", "open", "limit", normalizedPrice, baseQuantity); orderInfo.put("clientOid", clientOrderId); JSONObject result = bitGetClient.placeOrder(orderInfo); @@ -633,8 +633,8 @@ public class AutoGridStrategy extends BaseStrategy { String clientOrderId = buildClientOrderId("SELL", position.entryPrice); try { - JSONObject orderInfo = buildOrderRequest("sell", "close", "limit", sellPrice, - position.quantity, true); + JSONObject orderInfo = buildOrderRequest("buy", "close", "limit", sellPrice, + position.quantity); orderInfo.put("clientOid", clientOrderId); JSONObject result = bitGetClient.placeOrder(orderInfo); @@ -694,7 +694,7 @@ public class AutoGridStrategy extends BaseStrategy { if (isOpenBuy(side, tradeSide)) { onBuyFilled(price, volume, orderId, clientOid, price); - } else if (isCloseSell(side, tradeSide)) { + } else if (isCloseBuy(side, tradeSide)) { onSellFilled(price, volume, orderId, clientOid); } } @@ -717,9 +717,9 @@ public class AutoGridStrategy extends BaseStrategy { BigDecimal orderPrice = order.getBigDecimal("price"); if ("cancelled".equals(status) || "canceled".equals(status)) { - if ("buy".equals(side)) { + if (isOpenBuy(side, tradeSide)) { removePendingBuy(orderId, clientOid, orderPrice); - } else if ("sell".equals(side)) { + } else if (isCloseBuy(side, tradeSide)) { removePendingSell(orderId, clientOid, orderPrice); } return; @@ -740,7 +740,7 @@ public class AutoGridStrategy extends BaseStrategy { if (isOpenBuy(side, tradeSide)) { onBuyFilled(fillPrice, volume, orderId, clientOid, orderPrice); - } else if (isCloseSell(side, tradeSide)) { + } else if (isCloseBuy(side, tradeSide)) { onSellFilled(fillPrice, volume, orderId, clientOid); } } @@ -863,14 +863,8 @@ public class AutoGridStrategy extends BaseStrategy { || "buy_single".equals(tradeSide); } - private boolean isCloseSell(String side, String tradeSide) { - if (!"sell".equals(side)) { - return false; - } - return tradeSide == null - || "close".equals(tradeSide) - || "sell_single".equals(tradeSide) - || "reduce_sell_single".equals(tradeSide); + private boolean isCloseBuy(String side, String tradeSide) { + return "buy".equals(side) && "close".equals(tradeSide); } private BigDecimal firstPositive(BigDecimal... values) { @@ -1008,7 +1002,7 @@ public class AutoGridStrategy extends BaseStrategy { gridBuyOrder.exchangeOrderId = exchangeOrderId; pendingBuyOrders.put(priceKey(price), gridBuyOrder); buyCount++; - } else if ("sell".equals(side) && "close".equals(tradeSide)) { + } else if ("buy".equals(side) && "close".equals(tradeSide)) { if (clientOid == null) { clientOid = "SYNC_SELL_" + price.toPlainString(); } @@ -1251,7 +1245,7 @@ public class AutoGridStrategy extends BaseStrategy { // ======================== 工具方法 ======================== private JSONObject buildOrderRequest(String side, String tradeSide, String orderType, - BigDecimal price, BigDecimal size, boolean reduceOnly) { + BigDecimal price, BigDecimal size) { JSONObject orderInfo = new JSONObject(); orderInfo.put("symbol", getPlainSymbol()); orderInfo.put("marginMode", MARGIN_MODE); @@ -1262,9 +1256,6 @@ public class AutoGridStrategy extends BaseStrategy { if (price != null) { orderInfo.put("price", normalizePrice(price).toPlainString()); } - if (reduceOnly) { - orderInfo.put("reduceOnly", "YES"); - } return orderInfo; }