| | |
| | | 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.HoldOrderDataModel; |
| | | 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; |
| | |
| | | } |
| | | } |
| | | |
| | | 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<HoldOrderDataModel> list = wholePriceData.getList(); |
| | | |
| | | if (CollUtil.isNotEmpty(list)) { |
| | | BigDecimal totalProfitOrLoss = BigDecimal.ZERO; |
| | | Map<String, BigDecimal> prices = new HashMap<>(); |
| | | for (HoldOrderDataModel holdOrderData : list) { |
| | | String price = redisUtils.getString(CoinTypeConvert.convertToKey(holdOrderData.getSymbol())); |
| | | // BigDecimal newPrice = new BigDecimal(price); |
| | | BigDecimal newPrice = new BigDecimal("29958.46627789"); |
| | | |
| | | |
| | | BigDecimal rewardRatio = null; |
| | | if (ContractHoldOrderEntity.OPENING_TYPE_MORE == holdOrderData.getOpeningType()) { |
| | | // (最新价-开仓价)*规格*张数 |
| | | rewardRatio = newPrice.subtract(holdOrderData.getOpeningPrice()).multiply(holdOrderData.getSymbolSku()).multiply(new BigDecimal(holdOrderData.getSymbolCntSale())); |
| | | // 开空 |
| | | } else { |
| | | // (开仓价-最新价)*规格*张数 |
| | | rewardRatio = holdOrderData.getOpeningPrice().subtract(newPrice).multiply(holdOrderData.getSymbolSku()).multiply(new BigDecimal(holdOrderData.getSymbolCntSale())); |
| | | } |
| | | holdOrderData.setRewardAmount(rewardRatio); |
| | | holdOrderData.setClosingPrice(newPrice); |
| | | totalProfitOrLoss = totalProfitOrLoss.add(rewardRatio).setScale(8, BigDecimal.ROUND_DOWN); |
| | | prices.put(holdOrderData.getSymbol(), newPrice); |
| | | } |
| | | |
| | | BigDecimal holdBond = wholePriceData.getHoldBond(); |
| | | BigDecimal balance = wholePriceData.getBalance(); |
| | | if (balance.add(totalProfitOrLoss).compareTo(holdBond) > 0) { |
| | | continue; |
| | | } |
| | | |
| | | dataModelMap.remove(entry.getKey()); |
| | | System.out.println("触发"); |
| | | wholePriceData.setPrices(prices); |
| | | contractHoldOrderDao.updateMemberAllHoldOrderClosingStatus(wholePriceData.getMemberId()); |
| | | orderProducer.sendWholeBomb(JSONObject.toJSONString(wholePriceData)); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | public void wholeBomb(String symbol, String price) { |
| | | List<Long> memberIds = contractHoldOrderDao.selectMemberHasWholeOrder(); |