From 2abd0e479bd68cc377d77ac8178cc6b21783fcf1 Mon Sep 17 00:00:00 2001
From: heng.zhang1 <512061637@qq.com>
Date: Wed, 16 Sep 2020 16:54:24 +0800
Subject: [PATCH] 盘口优化

---
 src/main/java/com/xcong/excoin/trade/CoinTrader.java |   20 +++++++++-----------
 1 files changed, 9 insertions(+), 11 deletions(-)

diff --git a/src/main/java/com/xcong/excoin/trade/CoinTrader.java b/src/main/java/com/xcong/excoin/trade/CoinTrader.java
index fc4a8fc..fd62c5f 100644
--- a/src/main/java/com/xcong/excoin/trade/CoinTrader.java
+++ b/src/main/java/com/xcong/excoin/trade/CoinTrader.java
@@ -527,7 +527,7 @@
      * @param buyTradePlate sellTradePlate
      */
     public void sendTradePlateMessage(TradePlate buyTradePlate, TradePlate sellTradePlate) {
-        //防止并发引起数组越界,造成盘口倒挂 TODO
+        //防止并发引起数组越界,造成盘口倒挂
         List<List<BigDecimal>> plate;
         List<BigDecimal> plateItem;
         TradePlateModel tradePlateModel = new TradePlateModel();
@@ -535,10 +535,10 @@
         if (buyTradePlate != null && buyTradePlate.getItems() != null) {
             plate = new ArrayList<>();
             LinkedList<TradePlateItem> items = buyTradePlate.getItems();
-            for (TradePlateItem item : items) {
+            for (int i = items.size() - 1; i >= 0; i--) {
                 plateItem = new ArrayList<>(2);
-                BigDecimal price = item.getPrice();
-                BigDecimal amount = item.getAmount();
+                BigDecimal price = items.get(i).getPrice();
+                BigDecimal amount = items.get(i).getAmount();
                 plateItem.add(price);
                 plateItem.add(amount);
                 plate.add(plateItem);
@@ -549,10 +549,10 @@
         if (sellTradePlate != null && sellTradePlate.getItems() != null) {
             plate = new ArrayList<>();
             LinkedList<TradePlateItem> items = sellTradePlate.getItems();
-            for (TradePlateItem item : items) {
+            for (int i = items.size() - 1; i >= 0; i--) {
                 plateItem = new ArrayList<>(2);
-                BigDecimal price = item.getPrice();
-                BigDecimal amount = item.getAmount();
+                BigDecimal price = items.get(i).getPrice();
+                BigDecimal amount = items.get(i).getAmount();
                 plateItem.add(price);
                 plateItem.add(amount);
                 plate.add(plateItem);
@@ -560,8 +560,7 @@
             tradePlateModel.setSell(plate);
         }
 
-        // 盘口发生变化通知TODO
-
+        // 盘口发生变化通知
         exchangeProducer.sendPlateMsg(JSON.toJSONString(tradePlateModel));
     }
 
@@ -571,7 +570,7 @@
      * @param
      */
     public String sendTradePlateMessage() {
-        //防止并发引起数组越界,造成盘口倒挂 TODO
+        //防止并发引起数组越界,造成盘口倒挂
         List<List<BigDecimal>> plate;
         List<BigDecimal> plateItem;
         TradePlateModel tradePlateModel = new TradePlateModel();
@@ -606,7 +605,6 @@
 
         // 盘口发生变化通知TODO
         return JSON.toJSONString(tradePlateModel);
-        //exchangeProducer.sendPlateMsg(JSON.toJSONString(tradePlateModel));
     }
 
     /**

--
Gitblit v1.9.1