| | |
| | |
|
| | | 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 (CollectionUtils.isNotEmpty(trades)) {
|
| | | for (OrderCoinsEntity trade : trades) {
|
| | | if (trade != null) {
|
| | | orderCoinsDao.updateStatus(trade.getId(),OrderCoinsEntity.ORDERSTATUS_DONE);
|
| | | //orderCoinsDao.updateStatus(trade.getId(),OrderCoinsEntity.ORDERSTATUS_DONE);
|
| | | ids.add(trade.getId());
|
| | | // 买单 实际成交金额小于委托的 这一部分从冻结扣除
|
| | | if(OrderCoinsEntity.ORDERTYPE_BUY==trade.getOrderType()){
|
| | | if(trade.getEntrustAmount().compareTo(trade.getDealAmount())>0){
|
| | | // 此时退回这部分的差额
|
| | | BigDecimal subtract = trade.getEntrustAmount().subtract(trade.getDealAmount());
|
| | | System.out.println(subtract);
|
| | | MemberWalletCoinEntity memberWalletCoinEntity = memberWalletCoinDao.selectWalletCoinBymIdAndCode(trade.getMemberId(), CoinTypeEnum.USDT.name());
|
| | | if(memberWalletCoinEntity!=null){
|
| | | memberWalletCoinDao.updateWalletBalance(memberWalletCoinEntity.getId(),subtract,null,subtract.negate());
|
| | |
| | | }
|
| | | }
|
| | | if (CollectionUtils.isNotEmpty(ids)) {
|
| | | // orderCoinsDao.batchUpdateStatus(ids, OrderCoinsEntity.ORDERSTATUS_DONE);
|
| | | orderCoinsDao.batchUpdateStatus(ids, OrderCoinsEntity.ORDERSTATUS_DONE);
|
| | | }
|
| | | }
|
| | |
|