| | |
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import com.xcong.excoin.modules.coin.mapper.OrderCoinsDealMapper;
|
| | | import com.xcong.excoin.modules.platform.entity.PlatformCnyUsdtExchangeEntity;
|
| | | import com.xcong.excoin.modules.platform.entity.PlatformSymbolsCoinEntity;
|
| | |
|
| | |
| | | Map<String, Object> columnMap = new HashMap<>();
|
| | | columnMap.put("symbol", symbol);
|
| | | columnMap.put("member_id", memberId);
|
| | | memberSelectSymbolsDao.deleteByMap(columnMap);;
|
| | | memberSelectSymbolsDao.deleteByMap(columnMap);
|
| | | ;
|
| | | return Result.ok(MessageSourceUtils.getString("order_service_0016"));
|
| | | }
|
| | | }
|
| | |
| | | return Result.ok(findCollectListVo);
|
| | | }
|
| | |
|
| | | @Override
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | public void dealEntrustCoinOrder() {
|
| | | List<OrderCoinsEntity> list = orderCoinsDao.selectAllEntrustingCoinOrderList();
|
| | | if (CollUtil.isNotEmpty(list)) {
|
| | | for (OrderCoinsEntity orderCoinsEntity : list) {
|
| | | BigDecimal nowPrice = new BigDecimal(redisUtils.getString(CoinTypeConvert.convertToKey(orderCoinsEntity.getSymbol() + "/USDT")));
|
| | | // 下单时市场价
|
| | | BigDecimal markPrice = orderCoinsEntity.getMarkPrice();
|
| | | // 委托价
|
| | | BigDecimal entrustPrice = orderCoinsEntity.getEntrustPrice();
|
| | |
|
| | | //如果当时委托价小于市价
|
| | | if (entrustPrice.compareTo(markPrice) < 0) {
|
| | | if (nowPrice.compareTo(entrustPrice) > 0) {
|
| | | continue;
|
| | | }
|
| | | } else {
|
| | | //委托价大于市价
|
| | | if (nowPrice.compareTo(entrustPrice) < 0) {
|
| | | continue;
|
| | | }
|
| | | }
|
| | |
|
| | | BigDecimal fee = entrustPrice.multiply(orderCoinsEntity.getEntrustCnt()).multiply(new BigDecimal("0.002")).setScale(8, BigDecimal.ROUND_HALF_UP);
|
| | |
|
| | | BigDecimal dealAmount = entrustPrice.multiply(orderCoinsEntity.getEntrustCnt());
|
| | |
|
| | | OrderCoinsDealEntity orderCoinsDealEntity = OrderCoinsDealMapper.INSTANCE.orderToOrderDeal(orderCoinsEntity);
|
| | | orderCoinsDealEntity.setDealAmount(dealAmount);
|
| | | orderCoinsDealEntity.setDealPrice(entrustPrice);
|
| | | orderCoinsDealEntity.setFeeAmount(fee);
|
| | | orderCoinsDealEntity.setOrderStatus(OrderCoinsDealEntity.ORDERSTATUS_DONE);
|
| | | orderCoinsDealEntity.setId(null);
|
| | | orderCoinDealDao.insert(orderCoinsDealEntity);
|
| | |
|
| | | orderCoinsDao.deleteById(orderCoinsEntity.getId());
|
| | |
|
| | | MemberWalletCoinEntity walletCoinEntity = memberWalletCoinDao.selectWalletCoinBymIdAndCode(orderCoinsEntity.getMemberId(), orderCoinsEntity.getSymbol());
|
| | | MemberWalletCoinEntity usdt = memberWalletCoinDao.selectWalletCoinBymIdAndCode(orderCoinsEntity.getMemberId(), "USDT");
|
| | |
|
| | | BigDecimal frozen = BigDecimal.ZERO;
|
| | | BigDecimal total = BigDecimal.ZERO;
|
| | | // 买入
|
| | | if (OrderCoinsEntity.ORDERTYPE_BUY.equals(orderCoinsEntity.getOrderType())) {
|
| | | BigDecimal newCoins = walletCoinEntity.getAvailableBalance().add(orderCoinsEntity.getEntrustCnt());
|
| | | BigDecimal newCoinTotal = walletCoinEntity.getTotalBalance().add(orderCoinsEntity.getEntrustCnt());
|
| | | walletCoinEntity.setAvailableBalance(newCoins);
|
| | | walletCoinEntity.setTotalBalance(newCoinTotal);
|
| | | memberWalletCoinDao.updateById(walletCoinEntity);
|
| | |
|
| | | frozen = usdt.getFrozenBalance().subtract(dealAmount.add(fee));
|
| | | total = usdt.getTotalBalance().subtract(dealAmount.add(fee));
|
| | | usdt.setFrozenBalance(frozen);
|
| | | usdt.setTotalBalance(total);
|
| | | memberWalletCoinDao.updateById(usdt);
|
| | | } else {
|
| | | walletCoinEntity.setFrozenBalance(walletCoinEntity.getFrozenBalance().subtract(orderCoinsEntity.getEntrustCnt()));
|
| | | walletCoinEntity.setTotalBalance(walletCoinEntity.getTotalBalance().subtract(orderCoinsEntity.getEntrustCnt()));
|
| | | memberWalletCoinDao.updateById(walletCoinEntity);
|
| | |
|
| | | usdt.setAvailableBalance(usdt.getAvailableBalance().add(dealAmount.add(fee)));
|
| | | usdt.setTotalBalance(usdt.getTotalBalance().add(dealAmount.add(fee)));
|
| | | memberWalletCoinDao.updateById(usdt);
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|