1
zj
2025-05-25 a0295049dfce83691dccab5d33992a368e78bc48
1
4 files modified
1 files added
243 ■■■■■ changed files
.idea/uiDesigner.xml 124 ●●●●● patch | view | raw | blame | history
src/main/java/project/contract/internal/ContractOrderServiceImpl.java 56 ●●●● patch | view | raw | blame | history
src/main/java/project/contract/job/ContractOrderCalculationServiceImpl.java 4 ●●● patch | view | raw | blame | history
src/main/java/project/project/web/admin/AdminContractOrderController.java 43 ●●●●● patch | view | raw | blame | history
src/main/java/project/project/web/api/ContractOrderController.java 16 ●●●● patch | view | raw | blame | history
.idea/uiDesigner.xml
New file
@@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="Palette2">
    <group name="Swing">
      <item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
        <default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
      </item>
      <item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
        <default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
      </item>
      <item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
        <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
      </item>
      <item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
        <default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
      </item>
      <item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
        <default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
        <initial-values>
          <property name="text" value="Button" />
        </initial-values>
      </item>
      <item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
        <default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
        <initial-values>
          <property name="text" value="RadioButton" />
        </initial-values>
      </item>
      <item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
        <default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
        <initial-values>
          <property name="text" value="CheckBox" />
        </initial-values>
      </item>
      <item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
        <default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
        <initial-values>
          <property name="text" value="Label" />
        </initial-values>
      </item>
      <item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
          <preferred-size width="150" height="-1" />
        </default-constraints>
      </item>
      <item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
          <preferred-size width="150" height="-1" />
        </default-constraints>
      </item>
      <item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
          <preferred-size width="150" height="-1" />
        </default-constraints>
      </item>
      <item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
          <preferred-size width="150" height="50" />
        </default-constraints>
      </item>
      <item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
          <preferred-size width="150" height="50" />
        </default-constraints>
      </item>
      <item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
          <preferred-size width="150" height="50" />
        </default-constraints>
      </item>
      <item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
        <default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
      </item>
      <item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
          <preferred-size width="150" height="50" />
        </default-constraints>
      </item>
      <item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
        <default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
          <preferred-size width="150" height="50" />
        </default-constraints>
      </item>
      <item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
          <preferred-size width="150" height="50" />
        </default-constraints>
      </item>
      <item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
        <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
          <preferred-size width="200" height="200" />
        </default-constraints>
      </item>
      <item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
        <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
          <preferred-size width="200" height="200" />
        </default-constraints>
      </item>
      <item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
      </item>
      <item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
      </item>
      <item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
      </item>
      <item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
        <default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
      </item>
      <item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
        <default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
          <preferred-size width="-1" height="20" />
        </default-constraints>
      </item>
      <item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
        <default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
      </item>
      <item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
        <default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
      </item>
    </group>
  </component>
</project>
src/main/java/project/contract/internal/ContractOrderServiceImpl.java
@@ -1,5 +1,7 @@
package project.contract.internal;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.*;
@@ -540,22 +542,24 @@
        double totleMoney = wallet.getMoney();
        profit = Arith.add(profit,totleMoney);
        if (map.get("direction") != null) {
            String direction = map.get("direction").toString();
            double liquidationPrice;
            double deposit = depositOpen + profit;
            double deposit =  profit;
            if(leverRate == 1){
                liquidationPrice = 0;
            }else {
                if ("sell".equals(direction)) {
                    liquidationPrice = tradeAvgPrice + (deposit / div);
                    double lossPercentage = deposit / (Arith.mul(order.getVolume(), order.getUnit_amount()));
                    double priceIncrease = lossPercentage * tradeAvgPrice;
                    liquidationPrice = tradeAvgPrice + priceIncrease;
                } else {
                    liquidationPrice = (mul * tradeAvgPrice) / (deposit + mul);
                    double lossPercentage = deposit / (Arith.mul(order.getVolume(), order.getUnit_amount()));
                    double priceDrop = lossPercentage * tradeAvgPrice;
                    liquidationPrice = tradeAvgPrice - priceDrop;
                }
            }
            DecimalFormat dfs = new DecimalFormat("#.#####");
            String formattedPrice = dfs.format(liquidationPrice);
            map.put("qiangPing", formattedPrice);
@@ -566,48 +570,6 @@
        return map;
    }
//
//
    public static void main(String[] args) {
        Map<String, Object> map = new HashMap<>();
        map.put("direction", "buy");  // "buy" 或 "sell"
        double currentPrice = 59649.7;  // 开仓价格
        double leve = 10;  // 杠杆倍数
        double bzj = 500; // 保证金
        double zjbzj = 500; // 资金账户
        double xj = 70781.28; // 现价
        double mul = Arith.mul(bzj, leve);//仓位
        double div = Arith.div(mul, currentPrice);//持有币的数量
        double amount = Arith.mul(div, Arith.sub(xj, currentPrice));
        System.out.println(amount);
        if (map.get("direction") != null) {
            String direction = map.get("direction").toString();
            double liquidationPrice;
            double bcbzj = bzj + zjbzj;
            if(leve == 1){
                liquidationPrice = 0;
            }else{
                if ("sell".equals(direction)) {
                    liquidationPrice = currentPrice + (bcbzj / div);
                } else {
                    liquidationPrice = (mul * currentPrice) / (bcbzj + mul);
                }
            }
            DecimalFormat dfs = new DecimalFormat("#.#####");
            String formattedPrice = dfs.format(liquidationPrice);
            map.put("qiangPing", formattedPrice);
        }
        // 打印结果以验证
        System.out.println("Calculated Liquidation Price: " + map.get("qiangPing"));
    }
//
    @Override
    public List<ContractOrder> findSubmitted() {
src/main/java/project/contract/job/ContractOrderCalculationServiceImpl.java
@@ -185,7 +185,9 @@
        double changeRatio;
        changeRatio = Arith.mul(Arith.div(order.getProfit(), order.getDeposit_open()), 100);
        DecimalFormat df = new DecimalFormat("#.##");
        order.setChange_ratio(Double.valueOf(df.format(changeRatio)));
        if(!order.getState().equals("created")){
            order.setChange_ratio(Double.valueOf(df.format(changeRatio)));
        }
        /**
         * 多次平仓价格不对,后续修
src/main/java/project/project/web/admin/AdminContractOrderController.java
@@ -134,7 +134,8 @@
                        profit = Arith.add(profit, Arith.add(close_line.getProfit(), close_line.getDeposit()));
                    }else{
                        profit = Arith.add(profit, close_line.getDeposit());
                    }                }
                    }
                }
                Wallet wallet = this.walletService.saveWalletByPartyId(map.get("party_id").toString());
                double totleMoney = wallet.getMoney();
                profit = Arith.add(profit,totleMoney);
@@ -143,36 +144,25 @@
                if (map.get("direction") != null) {
                    String direction = map.get("direction").toString();
                    double liquidationPrice;
                    double deposit = depositOpen + profit;
                    double deposit =  profit;
                    if(leverRate == 1){
                        liquidationPrice = 0;
                    }else {
                        if ("sell".equals(direction)) {
                            liquidationPrice = tradeAvgPrice + (deposit / div);
                            double lossPercentage = deposit / (Arith.mul(Double.parseDouble(map.get("volume").toString()), Double.parseDouble(map.get("unit_amount").toString())));
                            double priceIncrease = lossPercentage * tradeAvgPrice;
                            liquidationPrice = tradeAvgPrice + priceIncrease;
                        } else {
                            liquidationPrice = (mul * tradeAvgPrice) / (deposit + mul);
                            double lossPercentage = deposit / (Arith.mul(Double.parseDouble(map.get("volume").toString()), Double.parseDouble(map.get("unit_amount").toString())));
                            double priceDrop = lossPercentage * tradeAvgPrice;
                            liquidationPrice = tradeAvgPrice - priceDrop;
                        }
                    }
                    DecimalFormat dfs = new DecimalFormat("#.#####");
                    String formattedPrice = dfs.format(liquidationPrice);
                    map.put("qiangPing", formattedPrice);
                }
//                double currentPrice = Double.parseDouble(map.get("trade_avg_price").toString());
//
//                double leve = Double.parseDouble(map.get("lever_rate").toString());
//                //得到强平价格
//                if(null != map.get("direction")){
//                    double liquidationPrice;
//                    if(map.get("direction").equals("sell")){
//                        liquidationPrice = currentPrice * (1 + (1 / leve));
//                    }else{
//                        liquidationPrice = currentPrice * (1 - 1 / leve);
//                    }
//                    DecimalFormat df = new DecimalFormat("#.#####");
//                    String formattedPrice = df.format(liquidationPrice);
//                    map.put("qiangPing",formattedPrice);
//                }
            }
            List<Item> items = this.itemService.cacheGetAll();
@@ -305,22 +295,27 @@
                if (map.get("direction") != null) {
                    String direction = map.get("direction").toString();
                    double liquidationPrice;
                    double deposit = depositOpen + profit;
                    double deposit =  profit;
                    if(leverRate == 1){
                        liquidationPrice = 0;
                    }else {
                        if ("sell".equals(direction)) {
                            liquidationPrice = tradeAvgPrice + (deposit / div);
                            double lossPercentage = deposit / (Arith.mul(Double.parseDouble(map.get("volume").toString()), Double.parseDouble(map.get("unit_amount").toString())));
                            double priceIncrease = lossPercentage * tradeAvgPrice;
                            liquidationPrice = tradeAvgPrice + priceIncrease;
                        } else {
                            liquidationPrice = (mul * tradeAvgPrice) / (deposit + mul);
                            double lossPercentage = deposit / (Arith.mul(Double.parseDouble(map.get("volume").toString()), Double.parseDouble(map.get("unit_amount").toString())));
                            double priceDrop = lossPercentage * tradeAvgPrice;
                            liquidationPrice = tradeAvgPrice - priceDrop;
                        }
                    }
                    DecimalFormat dfs = new DecimalFormat("#.#####");
                    String formattedPrice = dfs.format(liquidationPrice);
                    map.put("qiangPing", formattedPrice);
                }
            }
        } catch (BusinessException e) {
src/main/java/project/project/web/api/ContractOrderController.java
@@ -216,25 +216,25 @@
                if (map.get("direction") != null) {
                    String direction = map.get("direction").toString();
                    double liquidationPrice;
                    double deposit = depositOpen + profit;
                    double deposit =  profit;
                    if(leverRate == 1){
                        liquidationPrice = 0;
                    }else {
                        if ("sell".equals(direction)) {
                            liquidationPrice = tradeAvgPrice + (deposit / div);
                            double lossPercentage = deposit / Double.parseDouble(map.get("amount").toString());
                            double priceIncrease = lossPercentage * tradeAvgPrice;
                            liquidationPrice = tradeAvgPrice + priceIncrease;
                        } else {
                            liquidationPrice = (mul * tradeAvgPrice) / (deposit + mul);
                            double lossPercentage = deposit / Double.parseDouble(map.get("amount").toString());
                            double priceDrop = lossPercentage * tradeAvgPrice;
                            liquidationPrice = tradeAvgPrice - priceDrop;
                        }
                    }
                    DecimalFormat dfs = new DecimalFormat("#.#####");
                    String formattedPrice = dfs.format(liquidationPrice);
                    map.put("qiangPing", formattedPrice);
                }
                // 标记价格
                Realtime realtime = realtimeMap.get(map.get("symbol"));
                if (null == realtime) {