From a00d810984fe187d24e442d5f557bcc271cfa3ce Mon Sep 17 00:00:00 2001
From: xiaoyong931011 <15274802129@163.com>
Date: Thu, 28 Jan 2021 11:25:49 +0800
Subject: [PATCH] Merge branch 'whole_new' of https://gitee.com/chonggaoxiao/new_excoin.git into whole_new
---
src/main/java/com/xcong/excoin/rabbit/pricequeue/WebsocketPriceService.java | 43 +++++++++++++++++++++++++++++++++++++++++++
1 files changed, 43 insertions(+), 0 deletions(-)
diff --git a/src/main/java/com/xcong/excoin/rabbit/pricequeue/WebsocketPriceService.java b/src/main/java/com/xcong/excoin/rabbit/pricequeue/WebsocketPriceService.java
index ed20d89..bdc4fba 100644
--- a/src/main/java/com/xcong/excoin/rabbit/pricequeue/WebsocketPriceService.java
+++ b/src/main/java/com/xcong/excoin/rabbit/pricequeue/WebsocketPriceService.java
@@ -12,6 +12,8 @@
import com.xcong.excoin.modules.member.dao.MemberWalletContractDao;
import com.xcong.excoin.modules.member.entity.MemberEntity;
import com.xcong.excoin.modules.member.entity.MemberWalletContractEntity;
+import com.xcong.excoin.rabbit.pricequeue.whole.WholeDataQueue;
+import com.xcong.excoin.rabbit.pricequeue.whole.WholePriceDataModel;
import com.xcong.excoin.rabbit.producer.OrderProducer;
import com.xcong.excoin.utils.*;
import lombok.extern.slf4j.Slf4j;
@@ -279,6 +281,47 @@
}
}
+ public void wholeBomb() {
+ Map<String, WholePriceDataModel> dataModelMap = WholeDataQueue.MAP;
+ if (CollUtil.isEmpty(dataModelMap)) {
+ return;
+ }
+
+ for (Map.Entry<String, WholePriceDataModel> entry : dataModelMap.entrySet()) {
+ WholePriceDataModel wholePriceData = entry.getValue();
+ List<ContractHoldOrderEntity> list = wholePriceData.getList();
+
+ if (CollUtil.isNotEmpty(list)) {
+ BigDecimal totalProfitOrLoss = BigDecimal.ZERO;
+ Map<String, BigDecimal> prices = new HashMap<>();
+ for (ContractHoldOrderEntity holdOrderEntity : list) {
+ BigDecimal newPrice = (BigDecimal) redisUtils.get(CoinTypeConvert.convertToKey(holdOrderEntity.getSymbol()));
+
+ BigDecimal rewardRatio = null;
+ if (ContractHoldOrderEntity.OPENING_TYPE_MORE == holdOrderEntity.getOpeningType()) {
+ // (最新价-开仓价)*规格*张数
+ rewardRatio = newPrice.subtract(holdOrderEntity.getOpeningPrice()).multiply(holdOrderEntity.getSymbolSku()).multiply(new BigDecimal(holdOrderEntity.getSymbolCntSale()));
+ // 开空
+ } else {
+ // (开仓价-最新价)*规格*张数
+ rewardRatio = holdOrderEntity.getOpeningPrice().subtract(newPrice).multiply(holdOrderEntity.getSymbolSku()).multiply(new BigDecimal(holdOrderEntity.getSymbolCntSale()));
+ }
+ totalProfitOrLoss = totalProfitOrLoss.add(rewardRatio);
+ prices.put(holdOrderEntity.getSymbol(), newPrice);
+ }
+
+ BigDecimal holdBond = wholePriceData.getHoldBond();
+ BigDecimal balance = wholePriceData.getBalance();
+ if (balance.add(totalProfitOrLoss).compareTo(holdBond) > 0) {
+ continue;
+ }
+
+ wholePriceData.setPrices(prices);
+ orderProducer.sendWholeBomb(JSONObject.toJSONString(wholePriceData));
+ }
+ }
+ }
+
public void wholeBomb(String symbol, String price) {
List<Long> memberIds = contractHoldOrderDao.selectMemberHasWholeOrder();
--
Gitblit v1.9.1