| | |
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import com.alibaba.fastjson.JSON;
|
| | | import com.alibaba.fastjson.JSONObject;
|
| | | import com.xcong.excoin.common.contants.AppContants;
|
| | | import com.xcong.excoin.common.enumerates.CoinTypeEnum;
|
| | | import com.xcong.excoin.modules.blackchain.service.RocService;
|
| | | import com.xcong.excoin.modules.coin.mapper.OrderCoinsDealMapper;
|
| | | import com.xcong.excoin.modules.coin.service.CoinService;
|
| | | import com.xcong.excoin.modules.member.dao.MemberDao;
|
| | | import com.xcong.excoin.modules.member.entity.MemberEntity;
|
| | | import com.xcong.excoin.modules.platform.entity.PlatformCnyUsdtExchangeEntity;
|
| | |
| | |
|
| | | @Resource
|
| | | private OrderSubmitProducer orderSubmitProducer;
|
| | |
|
| | | @Resource
|
| | | private CoinService coinService;
|
| | |
|
| | |
|
| | | @Override
|
| | |
| | |
|
| | | BigDecimal nowPriceinBigDecimal = price;
|
| | | //查询当前价
|
| | | //BigDecimal nowPrice = new BigDecimal(redisUtils.getString(CoinTypeConvert.convertToKey(symbol + "/USDT")));
|
| | | BigDecimal nowPrice = new BigDecimal(redisUtils.getString(CoinTypeConvert.convertToKey(symbol + "/USDT")));
|
| | |
|
| | | // 获取交易管理的杠杠倍率,手续费率等信息,由平台进行设置
|
| | | symbol = symbol.toUpperCase();
|
| | |
| | | closingPrice = price.multiply(amount).multiply(tradeSetting.getCoinFeeRatio());
|
| | | totalPayPrice = price.multiply(amount).add(closingPrice);
|
| | | entrustAmount = price.multiply(amount);
|
| | | // 限价买不能高于当前10%
|
| | | if (OrderCoinsEntity.ORDERTYPE_BUY == type) {
|
| | | BigDecimal multiply = nowPrice.multiply(new BigDecimal("1.2"));
|
| | | if(price.compareTo(multiply)>0){
|
| | | return Result.fail("不能高于当前价的120%");
|
| | | }
|
| | | }else{
|
| | | // 卖不能小于当前90
|
| | | BigDecimal multiply = nowPrice.multiply(new BigDecimal("0.8"));
|
| | | if(price.compareTo(multiply)<0){
|
| | | return Result.fail("不能低于当前价的80%");
|
| | | }
|
| | | }
|
| | | } else {
|
| | | // 市价
|
| | | if (OrderCoinsEntity.ORDERTYPE_BUY == type) {
|
| | |
| | | //冻结相应的资产
|
| | | if (OrderCoinsEntity.ORDERTYPE_BUY.equals(type)) {
|
| | | //如果是买入,所对应的币种增加,USDT账户减少金额
|
| | | memberWalletCoinDao.updateWalletBalance(walletCoinUsdt.getId(), totalPayPrice.negate(), totalPayPrice.negate(), entrustAmount);
|
| | | coinService.updateWalletBalance(walletCoinUsdt.getId(), totalPayPrice.negate(), totalPayPrice.negate(), entrustAmount);
|
| | | } else {
|
| | | //如果是卖出,币种减少,USDT增加
|
| | | memberWalletCoinDao.updateWalletBalance(walletCoin.getId(), amount.negate(), amount.negate(), amount);
|
| | | coinService.updateWalletBalance(walletCoin.getId(), amount.negate(), amount.negate(), amount);
|
| | | }
|
| | | // 加入到撮合
|
| | | order.setSymbol(symbol);
|
| | |
| | | returnFee = orderCoinsEntity.getFeeAmount().subtract(needFee);
|
| | | }
|
| | | BigDecimal avi = returnBalance.add(returnFee);
|
| | | memberWalletCoinDao.updateWalletBalance(walletCoin.getId(), avi, null, returnBalance.negate());
|
| | | coinService.updateWalletBalance(walletCoin.getId(), avi, null, returnBalance.negate());
|
| | | walletCoin.setAvailableBalance(walletCoin.getAvailableBalance().add(returnBalance).add(returnFee));
|
| | | walletCoin.setFrozenBalance(walletCoin.getFrozenBalance().subtract(returnBalance));
|
| | | //memberWalletCoinDao.updateById(walletCoin);
|
| | |
| | | walletCoin.setAvailableBalance(walletCoin.getAvailableBalance().add(returnBalance));
|
| | | walletCoin.setFrozenBalance(walletCoin.getFrozenBalance().subtract(returnBalance));
|
| | | //memberWalletCoinDao.updateById(walletCoin);
|
| | | memberWalletCoinDao.updateWalletBalance(walletCoin.getId(), returnBalance, null, returnBalance.negate());
|
| | | coinService.updateWalletBalance(walletCoin.getId(), returnBalance, null, returnBalance.negate());
|
| | | // 流水记录
|
| | | MemberAccountFlowEntity record = new MemberAccountFlowEntity();
|
| | | record.setSource(MemberAccountFlowEntity.SOURCE_CANCEL);
|
| | |
| | | MemberWalletCoinEntity usdtWallet = memberWalletCoinDao.selectWalletCoinBymIdAndCode(buyOrderCoinsEntity.getMemberId(), MemberWalletCoinEnum.WALLETCOINCODE.getValue());
|
| | | if (usdtWallet != null) {
|
| | | // 减少usdt冻结
|
| | | memberWalletCoinDao.updateWalletBalance(usdtWallet.getId(), null, null, buyTurnover.negate());
|
| | | coinService.updateWalletBalance(usdtWallet.getId(), null, null, buyTurnover.negate());
|
| | | }
|
| | | // 增加买的币
|
| | | MemberWalletCoinEntity buySymbolWallet = memberWalletCoinDao.selectWalletCoinBymIdAndCode(buyOrderCoinsEntity.getMemberId(), buyOrderCoinsEntity.getSymbol());
|
| | | if (buySymbolWallet != null) {
|
| | | memberWalletCoinDao.updateWalletBalance(buySymbolWallet.getId(), amount, amount, null);
|
| | | coinService.updateWalletBalance(buySymbolWallet.getId(), amount, amount, null);
|
| | | }
|
| | | // 流水记录
|
| | | MemberAccountFlowEntity record = new MemberAccountFlowEntity();
|
| | |
| | | MemberWalletCoinEntity memberWalletCoinEntity = memberWalletCoinDao.selectWalletCoinBymIdAndCode(sellOrderCoinsEntity.getMemberId(), sellOrderCoinsEntity.getSymbol());
|
| | | if (memberWalletCoinEntity != null) {
|
| | | // 更新卖币减少的币种
|
| | | memberWalletCoinDao.updateWalletBalance(memberWalletCoinEntity.getId(), null, null, amount.negate());
|
| | | coinService.updateWalletBalance(memberWalletCoinEntity.getId(), null, null, amount.negate());
|
| | | }
|
| | | // 更新卖币得到的usdt
|
| | | MemberWalletCoinEntity sellWalletCoinEntity = memberWalletCoinDao.selectWalletCoinBymIdAndCode(sellOrderCoinsEntity.getMemberId(), MemberWalletCoinEnum.WALLETCOINCODE.getValue());
|
| | | if (sellOrderCoinsEntity != null) {
|
| | | memberWalletCoinDao.updateWalletBalance(sellWalletCoinEntity.getId(), buyTurnover, buyTurnover, null);
|
| | | coinService.updateWalletBalance(sellWalletCoinEntity.getId(), buyTurnover, buyTurnover, null);
|
| | | }
|
| | | // 流水记录
|
| | | MemberAccountFlowEntity recordSell = new MemberAccountFlowEntity();
|
| | |
| | | if (CollectionUtils.isNotEmpty(trades)) {
|
| | | for (OrderCoinsEntity trade : trades) {
|
| | | if (trade != null) {
|
| | | if (trade.getOrderType()==2 && trade.getEntrustCnt().compareTo(trade.getDealCnt())!=0){
|
| | | System.out.println("问题卖单:"+ JSON.toJSONString(trade));
|
| | | }
|
| | | //orderCoinsDao.updateStatus(trade.getId(),OrderCoinsEntity.ORDERSTATUS_DONE);
|
| | | ids.add(trade.getId());
|
| | | // 买单 实际成交金额小于委托的 这一部分从冻结扣除
|
| | |
| | | BigDecimal subtract = trade.getEntrustAmount().subtract(trade.getDealAmount());
|
| | | MemberWalletCoinEntity memberWalletCoinEntity = memberWalletCoinDao.selectWalletCoinBymIdAndCode(trade.getMemberId(), CoinTypeEnum.USDT.name());
|
| | | if(memberWalletCoinEntity!=null){
|
| | | memberWalletCoinDao.updateWalletBalance(memberWalletCoinEntity.getId(),subtract,null,subtract.negate());
|
| | | coinService.updateWalletBalance(memberWalletCoinEntity.getId(),subtract,null,subtract.negate());
|
| | | }
|
| | | }
|
| | | }
|