From f6a912c1a6a26c809568f964941fb4ad4483274e Mon Sep 17 00:00:00 2001
From: Helius <wangdoubleone@gmail.com>
Date: Mon, 31 May 2021 11:19:40 +0800
Subject: [PATCH] modify
---
src/main/java/com/xcong/excoin/rabbit/init/OrderProducerInit.java | 70 +++++++++++++++++++++++++----------
1 files changed, 50 insertions(+), 20 deletions(-)
diff --git a/src/main/java/com/xcong/excoin/rabbit/init/OrderProducerInit.java b/src/main/java/com/xcong/excoin/rabbit/init/OrderProducerInit.java
index ad8f3e0..529878d 100644
--- a/src/main/java/com/xcong/excoin/rabbit/init/OrderProducerInit.java
+++ b/src/main/java/com/xcong/excoin/rabbit/init/OrderProducerInit.java
@@ -1,23 +1,30 @@
package com.xcong.excoin.rabbit.init;
+import cn.hutool.core.collection.CollUtil;
import com.alibaba.fastjson.JSONObject;
import com.xcong.excoin.common.enumerates.RabbitPriceTypeEnum;
import com.xcong.excoin.modules.contract.dao.ContractEntrustOrderDao;
import com.xcong.excoin.modules.contract.dao.ContractHoldOrderDao;
import com.xcong.excoin.modules.contract.entity.ContractEntrustOrderEntity;
import com.xcong.excoin.modules.contract.entity.ContractHoldOrderEntity;
+import com.xcong.excoin.modules.member.dao.MemberDao;
+import com.xcong.excoin.modules.member.entity.MemberEntity;
import com.xcong.excoin.rabbit.pricequeue.OrderModel;
import com.xcong.excoin.rabbit.producer.OrderProducer;
+import com.xcong.excoin.utils.CalculateUtil;
+import com.xcong.excoin.utils.ThreadPoolUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
+import java.util.HashMap;
import java.util.List;
/**
@@ -26,6 +33,7 @@
* @author helius
*/
@Slf4j
+@DependsOn("springContextHolder")
@Component
@ConditionalOnProperty(prefix = "app", name = "newest-price-update-job", havingValue = "true")
public class OrderProducerInit {
@@ -38,6 +46,8 @@
@Resource
private OrderProducer producer;
+ @Resource
+ private MemberDao memberDao;
@PostConstruct
public void initOrder() {
@@ -56,13 +66,15 @@
// 9:止盈平多10:止盈平空11:止损平多12:止损平空
if (ContractHoldOrderEntity.OPENING_TYPE_MORE == openingType) {
// 开多 发送开多止损 止盈 爆仓
- // 爆仓价
- BigDecimal forceSetPrice = order.getForceClosingPrice();
- if (forceSetPrice != null) {
- if (forceSetPrice.compareTo(BigDecimal.ZERO) >= 0) {
- OrderModel model = new OrderModel(order.getId(), RabbitPriceTypeEnum.CLOSE_MORE_BOMB.getValue(), forceSetPrice.toPlainString(),
- order.getSymbol(), order.getOperateNo());
- producer.sendPriceOperate(JSONObject.toJSONString(model));
+ if (order.getPositionType() == ContractEntrustOrderEntity.POSITION_TYPE_ADD) {
+ // 爆仓价
+ BigDecimal forceSetPrice = order.getForceClosingPrice();
+ if (forceSetPrice != null) {
+ if (forceSetPrice.compareTo(BigDecimal.ZERO) >= 0) {
+ OrderModel model = new OrderModel(order.getId(), RabbitPriceTypeEnum.CLOSE_MORE_BOMB.getValue(), forceSetPrice.toPlainString(),
+ order.getSymbol(), order.getOperateNo(), order.getMemberId());
+ producer.sendPriceOperate(JSONObject.toJSONString(model));
+ }
}
}
// 止损
@@ -70,7 +82,7 @@
if (stopLossPrice != null && stopLossPrice.compareTo(BigDecimal.ZERO) > 0) {
OrderModel model = new OrderModel(order.getId(), RabbitPriceTypeEnum.CLOSE_MORE_STOP_LESS.getValue(),
stopLossPrice.setScale(8, RoundingMode.HALF_UP).toPlainString(),
- order.getSymbol());
+ order.getSymbol(), order.getMemberId());
producer.sendPriceOperate(JSONObject.toJSONString(model));
}
// 止盈
@@ -78,19 +90,21 @@
if (stopProfitPrice != null && stopProfitPrice.compareTo(BigDecimal.ZERO) > 0) {
OrderModel model = new OrderModel(order.getId(), RabbitPriceTypeEnum.CLOSE_MORE_STOP_PROFIT.getValue(),
stopProfitPrice.setScale(8, RoundingMode.HALF_UP).toPlainString(),
- order.getSymbol());
+ order.getSymbol(), order.getMemberId());
producer.sendPriceOperate(JSONObject.toJSONString(model));
}
} else {
// 开空 发送开空止损 止盈 爆仓
// 爆仓价
- BigDecimal forceSetPrice = order.getForceClosingPrice();
- if (forceSetPrice != null) {
- if (forceSetPrice.compareTo(BigDecimal.ZERO) >= 0) {
- OrderModel model = new OrderModel(order.getId(), RabbitPriceTypeEnum.CLOSE_LESS_BOMB.getValue(), forceSetPrice.toPlainString(),
- order.getSymbol(), order.getOperateNo());
- producer.sendPriceOperate(JSONObject.toJSONString(model));
+ if (order.getPositionType() == ContractEntrustOrderEntity.POSITION_TYPE_ADD) {
+ BigDecimal forceSetPrice = order.getForceClosingPrice();
+ if (forceSetPrice != null) {
+ if (forceSetPrice.compareTo(BigDecimal.ZERO) >= 0) {
+ OrderModel model = new OrderModel(order.getId(), RabbitPriceTypeEnum.CLOSE_LESS_BOMB.getValue(), forceSetPrice.toPlainString(),
+ order.getSymbol(), order.getOperateNo(), order.getMemberId());
+ producer.sendPriceOperate(JSONObject.toJSONString(model));
+ }
}
}
// 止损
@@ -98,7 +112,7 @@
if (stopLossPrice != null && stopLossPrice.compareTo(BigDecimal.ZERO) > 0) {
OrderModel model = new OrderModel(order.getId(), RabbitPriceTypeEnum.CLOSE_LESS_STOP_LESS.getValue(),
stopLossPrice.setScale(8, RoundingMode.HALF_UP).toPlainString(),
- order.getSymbol());
+ order.getSymbol(), order.getMemberId());
producer.sendPriceOperate(JSONObject.toJSONString(model));
}
// 止盈
@@ -106,11 +120,19 @@
if (stopProfitPrice != null && stopProfitPrice.compareTo(BigDecimal.ZERO) > 0) {
OrderModel model = new OrderModel(order.getId(), RabbitPriceTypeEnum.CLOSE_LESS_STOP_PROFIT.getValue(),
stopProfitPrice.setScale(8, RoundingMode.HALF_UP).toPlainString(),
- order.getSymbol());
+ order.getSymbol(), order.getMemberId());
producer.sendPriceOperate(JSONObject.toJSONString(model));
}
}
+ }
+ }
+
+ // 全仓持仓
+ List<Long> wholeHoldOrders = contractHoldOrderDao.selectAllWholeOrderMemberId();
+ if (CollUtil.isNotEmpty(wholeHoldOrders)) {
+ for (Long memberId : wholeHoldOrders) {
+ ThreadPoolUtils.sendWholePrice(memberId);
}
}
@@ -125,12 +147,20 @@
// 开多委托
model = new OrderModel(order.getId(), RabbitPriceTypeEnum.ENTRUST_OPEN_MORE.getValue(),
entrustPrice.setScale(8, RoundingMode.HALF_UP).toPlainString(),
- order.getSymbol());
+ order.getSymbol(), order.getMemberId());
- } else {
+ } else if (ContractEntrustOrderEntity.ENTRUST_TYPE_OPEN_LESS == entrustType){
model = new OrderModel(order.getId(), RabbitPriceTypeEnum.ENTRUST_OPEN_LESS.getValue(),
entrustPrice.setScale(8, RoundingMode.HALF_UP).toPlainString(),
- order.getSymbol());
+ order.getSymbol(), order.getMemberId());
+ } else if (ContractEntrustOrderEntity.ENTRUST_TYPE_CLOSE_MORE == entrustType) {
+ model = new OrderModel(order.getId(), RabbitPriceTypeEnum.ENTRUST_CLOSE_MORE.getValue(),
+ entrustPrice.setScale(8, RoundingMode.HALF_UP).toPlainString(),
+ order.getSymbol(), order.getMemberId());
+ } else {
+ model = new OrderModel(order.getId(), RabbitPriceTypeEnum.ENTRUST_CLOSE_LESS.getValue(),
+ entrustPrice.setScale(8, RoundingMode.HALF_UP).toPlainString(),
+ order.getSymbol(), order.getMemberId());
}
producer.sendPriceOperate(JSONObject.toJSONString(model));
}
--
Gitblit v1.9.1