From f4cda78ffefc67a0bafebb5dac82b416f3751592 Mon Sep 17 00:00:00 2001
From: Administrator <15274802129@163.com>
Date: Sun, 24 May 2026 20:26:17 +0800
Subject: [PATCH] config(gateApi): 更新Gate API配置参数
---
src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java | 226 +++++++++++++++++++++++++++++---------------------------
1 files changed, 116 insertions(+), 110 deletions(-)
diff --git a/src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java b/src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java
index 9ac5617..f953866 100644
--- a/src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java
+++ b/src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java
@@ -377,8 +377,8 @@
if (state != StrategyState.ACTIVE) {
return;
}
- processLongGrid(closePrice);
- processShortGrid(closePrice);
+// processLongGrid(closePrice);
+// processShortGrid(closePrice);
}
// ---- 仓位推送回调 ----
@@ -692,19 +692,6 @@
/**
* 匹配止盈单止盈
*/
- GridElement byLongTakeProfitOrderId = GridElement.findByLongTakeProfitOrderId(orderId);
- if (byLongTakeProfitOrderId != null){
- longTakeProfitTraderIdParam(
- byLongTakeProfitOrderId,
- null,
- false
- );
- longEntryTraderIdParam(
- byLongTakeProfitOrderId,
- null,
- false
- );
- }
GridElement byShortTakeProfitOrderId = GridElement.findByShortTakeProfitOrderId(orderId);
if (byShortTakeProfitOrderId != null){
shortTakeProfitTraderIdParam(
@@ -717,36 +704,27 @@
null,
false
);
+ TPonUserTradeShortEntry(byShortTakeProfitOrderId);
+ }
+ GridElement byLongTakeProfitOrderId = GridElement.findByLongTakeProfitOrderId(orderId);
+ if (byLongTakeProfitOrderId != null){
+ longTakeProfitTraderIdParam(
+ byLongTakeProfitOrderId,
+ null,
+ false
+ );
+ longEntryTraderIdParam(
+ byLongTakeProfitOrderId,
+ null,
+ false
+ );
+ TPonUserTradeLongEntry(byLongTakeProfitOrderId);
}
/**
* 匹配挂单
*/
- GridElement longGridElement = GridElement.findByLongOrderId(orderId);
- if (longGridElement != null) {
- if (longGridElement.isHasLongOrder() && !tradeId.equals("0")){
- onUserTradeLongEntry(longGridElement);
- if (longGridElement.getLongTakeProfitOrderId() == null){
- BigDecimal longTp = longGridElement.getLongTraderParam().getTakeProfitPrice();
- if (longTp != null) {
- executor.placeTakeProfit(longTp,
- FuturesPriceTrigger.RuleEnum.NUMBER_1,
- ORDER_TYPE_CLOSE_LONG,
- negate(config.getQuantity()),
- (profitId) -> {
- longTakeProfitTraderIdParam(
- longGridElement,
- profitId,
- true
- );
- });
- log.info("[Gate] 多单成交匹配止盈, orderId:{}, 止盈价:{}, size:{}", orderId, longTp, negate(config.getQuantity()));
- return;
- }
- }
- }
- }
GridElement shortGridElement = GridElement.findByShortOrderId(orderId);
if (shortGridElement != null) {
if (shortGridElement.isHasShortOrder() && !tradeId.equals("0")){
@@ -771,9 +749,33 @@
}
}
}
+ GridElement longGridElement = GridElement.findByLongOrderId(orderId);
+ if (longGridElement != null) {
+ if (longGridElement.isHasLongOrder() && !tradeId.equals("0")){
+
+ onUserTradeLongEntry(longGridElement);
+ if (longGridElement.getLongTakeProfitOrderId() == null){
+ BigDecimal longTp = longGridElement.getLongTraderParam().getTakeProfitPrice();
+ if (longTp != null) {
+ executor.placeTakeProfit(longTp,
+ FuturesPriceTrigger.RuleEnum.NUMBER_1,
+ ORDER_TYPE_CLOSE_LONG,
+ negate(config.getQuantity()),
+ (profitId) -> {
+ longTakeProfitTraderIdParam(
+ longGridElement,
+ profitId,
+ true
+ );
+ });
+ log.info("[Gate] 多单成交匹配止盈, orderId:{}, 止盈价:{}, size:{}", orderId, longTp, negate(config.getQuantity()));
+ }
+ }
+ }
+ }
}
- private void onUserTradeShortEntry(GridElement gridElement) {
+ private void TPonUserTradeShortEntry(GridElement gridElement) {
if (!isMarginSafe()) {
log.warn("[Gate] 保证金超限,跳过挂条件单");
} else {
@@ -785,6 +787,80 @@
* 前进方向挂空仓条件单
* 后置方向挂多空条件单
*/
+ //下一个开仓位置
+ BigDecimal gridPrice = gridElement.getGridPrice();
+
+ // 判断网格是否能开空仓,如果不能则跳过
+ if (gridElement != null) {
+ TraderParam downShortTraderParam = gridElement.getShortTraderParam();
+ if (
+ !gridElement.isHasShortOrder() &&
+ gridPrice.compareTo(longEntryPrice) <= 0 &&
+ gridPrice.compareTo(shortEntryPrice) >= 0
+ ){
+ placeEntryOrderWithPreFlag(gridElement, false,
+ downShortTraderParam.getEntryPrice(),
+ FuturesPriceTrigger.RuleEnum.NUMBER_1,
+ negate(downShortTraderParam.getQuantity()));
+
+ }
+
+ TraderParam downLongTraderParam = gridElement.getLongTraderParam();
+ if (
+ !gridElement.isHasLongOrder() &&
+ gridPrice.compareTo(longEntryPrice) <= 0
+ ){
+ placeEntryOrderWithPreFlag(gridElement, true,
+ downLongTraderParam.getEntryPrice(),
+ FuturesPriceTrigger.RuleEnum.NUMBER_1,
+ downLongTraderParam.getQuantity());
+ }
+
+ }
+ }
+ }
+
+ private void TPonUserTradeLongEntry(GridElement gridElement) {
+ if (!isMarginSafe()) {
+ log.warn("[Gate] 保证金超限,跳过挂条件单");
+ } else {
+ BigDecimal newLongFirst = gridElement.getGridPrice() ;
+
+ // 判断网格是否能开多空仓,如果不能则跳过
+ if (gridElement != null) {
+
+ TraderParam downLongTraderParam = gridElement.getLongTraderParam();
+ if (
+ !gridElement.isHasLongOrder() &&
+ newLongFirst.compareTo(shortEntryPrice) >= 0 &&
+ newLongFirst.compareTo(longEntryPrice) <= 0
+ ){
+ placeEntryOrderWithPreFlag(gridElement, true,
+ downLongTraderParam.getEntryPrice(),
+ FuturesPriceTrigger.RuleEnum.NUMBER_2,
+ config.getQuantity());
+
+ }
+
+ TraderParam shortTraderParam = gridElement.getShortTraderParam();
+ if (
+ !gridElement.isHasShortOrder() &&
+ newLongFirst.compareTo(shortEntryPrice) >= 0
+ ){
+
+ placeEntryOrderWithPreFlag(gridElement, false,
+ shortTraderParam.getEntryPrice(),
+ FuturesPriceTrigger.RuleEnum.NUMBER_2,
+ negate(config.getQuantity()));
+ }
+ }
+ }
+ }
+
+ private void onUserTradeShortEntry(GridElement gridElement) {
+ if (!isMarginSafe()) {
+ log.warn("[Gate] 保证金超限,跳过挂条件单");
+ } else {
//下一个开仓位置
GridElement UpGridElement = GridElement.findById(gridElement.getDownId());
BigDecimal newLongFirst = UpGridElement.getGridPrice();
@@ -800,36 +876,6 @@
FuturesPriceTrigger.RuleEnum.NUMBER_2,
negate(upShortTraderParam.getQuantity()));
}
- int i = gridElement.getUpId();
- GridElement downGridElement = GridElement.findById(i);
- if (downGridElement != null){
-
- BigDecimal downGridPrice = downGridElement.getGridPrice();
-
- TraderParam downShortTraderParam = downGridElement.getShortTraderParam();
- if (
- !downGridElement.isHasShortOrder() &&
- downGridPrice.compareTo(longEntryPrice) <= 0 &&
- downGridPrice.compareTo(shortEntryPrice) >= 0
- ){
- placeEntryOrderWithPreFlag(downGridElement, false,
- downShortTraderParam.getEntryPrice(),
- FuturesPriceTrigger.RuleEnum.NUMBER_1,
- negate(downShortTraderParam.getQuantity()));
-
- }
-
- TraderParam downLongTraderParam = downGridElement.getLongTraderParam();
- if (
- !downGridElement.isHasLongOrder() &&
- downGridPrice.compareTo(longEntryPrice) <= 0
- ){
- placeEntryOrderWithPreFlag(downGridElement, true,
- downLongTraderParam.getEntryPrice(),
- FuturesPriceTrigger.RuleEnum.NUMBER_1,
- downLongTraderParam.getQuantity());
- }
- }
}
}
}
@@ -838,14 +884,6 @@
if (!isMarginSafe()) {
log.warn("[Gate] 保证金超限,跳过挂条件单");
} else {
-
- /**
- * 下一个开仓位置
- * 获取队列第一个元素的价格对应的网格
- * 判断网格是否能开多仓,如果不能则跳过
- * 前进方向挂多仓条件单
- * 后置方向挂多空条件单
- */
//下一个开仓位置
GridElement UpGridElement = GridElement.findById(gridElement.getUpId());
BigDecimal newLongFirst = UpGridElement.getGridPrice() ;
@@ -859,38 +897,6 @@
upLongTraderParam.getEntryPrice(),
FuturesPriceTrigger.RuleEnum.NUMBER_1,
config.getQuantity());
- }
-
- int i = gridElement.getDownId();
- GridElement downGridElement = GridElement.findById(i);
- if (downGridElement != null){
-
- BigDecimal downGridPrice = downGridElement.getGridPrice();
-
- TraderParam downLongTraderParam = downGridElement.getLongTraderParam();
- if (
- !downGridElement.isHasLongOrder() &&
- downGridPrice.compareTo(shortEntryPrice) >= 0 &&
- downGridPrice.compareTo(longEntryPrice) <= 0
- ){
- placeEntryOrderWithPreFlag(downGridElement, true,
- downLongTraderParam.getEntryPrice(),
- FuturesPriceTrigger.RuleEnum.NUMBER_2,
- config.getQuantity());
-
- }
-
- TraderParam shortTraderParam = downGridElement.getShortTraderParam();
- if (
- !downGridElement.isHasShortOrder() &&
- downGridPrice.compareTo(shortEntryPrice) >= 0
- ){
-
- placeEntryOrderWithPreFlag(downGridElement, false,
- shortTraderParam.getEntryPrice(),
- FuturesPriceTrigger.RuleEnum.NUMBER_2,
- negate(config.getQuantity()));
- }
}
}
}
--
Gitblit v1.9.1