1
zj
2024-08-15 171628f9a463f5af3ce55d897fa37b1b80ea4e8b
src/main/java/project/contract/internal/ContractOrderServiceImpl.java
@@ -7,7 +7,6 @@
import java.util.concurrent.ConcurrentHashMap;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
import kernel.util.Arith;
import kernel.util.DateUtils;
@@ -15,6 +14,7 @@
import kernel.web.ApplicationUtil;
import kernel.web.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import project.Constants;
import project.contract.ContractApplyOrder;
import project.contract.ContractApplyOrderService;
@@ -129,8 +129,19 @@
      double profit = this.settle(order, volume);
      update(order);
//      if (profit > 0) {
      Wallet wallet = this.walletService.saveWalletByPartyId(order.getPartyId());
      double amount_before = wallet.getMoney();
      Object money = redisHandler.get("PARTY_ID_MONEY_" + order.getPartyId().toString());
      if(ObjectUtils.isEmpty(money)){
         wallet.setMoney(wallet.getMoney());
      }else{
         wallet.setMoney(Double.parseDouble(money.toString()));
      }
      if (Arith.add(wallet.getMoney(), profit) < 0) {
         profit = Arith.sub(0, wallet.getMoney());
      }
//      wallet.setMoney(Arith.add(wallet.getMoney(), profit));/
      if (Arith.add(wallet.getMoney(), profit) < 0) {
@@ -202,7 +213,12 @@
      Wallet wallet = this.walletService.saveWalletByPartyId(order.getPartyId());
      double amount_before = wallet.getMoney();
      Object money = redisHandler.get("PARTY_ID_MONEY_" + order.getPartyId().toString());
      if(ObjectUtils.isEmpty(money)){
         wallet.setMoney(wallet.getMoney());
      }else{
         wallet.setMoney(Double.parseDouble(money.toString()));
      }
      if (Arith.add(wallet.getMoney(), profit) < 0) {
         profit = Arith.sub(0, wallet.getMoney());
@@ -313,7 +329,11 @@
       */
      double rate = Arith.div(volume, order.getVolume_open());
      //profit = Arith.mul(Arith.add(order.getDeposit(), order.getProfit()), rate);
      //平仓收益
      double mul = Arith.mul(order.getDeposit_open(), order.getLever_rate());//仓位
      double div = Arith.div(mul, order.getTrade_avg_price());//持有币的数量
      double amount = Arith.mul(div, Arith.sub(order.getClose_avg_price(), order.getTrade_avg_price()));
      profit = Arith.add(Arith.mul(order.getDeposit_open(),rate),Arith.mul(order.getProfit(),rate));
      order.setAmount_close(Arith.add(order.getAmount_close(), profit));
      order.setVolume(Arith.sub(order.getVolume(), volume));
@@ -500,7 +520,7 @@
                     Arith.add(Arith.add(order.getAmount_close(),Arith.mul(order.getProfit(),rate)), order.getDeposit()),
                     order.getDeposit_open())));
      } else {
         map.put("profit", df.format(Arith.sub(Arith.add(order.getAmount_close(), order.getDeposit()), order.getDeposit_open())));
         map.put("profit", df.format(order.getProfit()));
      }
//      double currentPrice = Double.parseDouble(map.get("trade_avg_price").toString());
//