| | |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.xcong.excoin.modules.coin.entity.OrderCoinsEntity; |
| | | import com.xcong.excoin.modules.coin.service.OrderCoinService; |
| | | import com.xcong.excoin.rabbit.producer.ExchangeProducer; |
| | |
| | | //是否暂停交易 |
| | | private boolean tradingHalt = false; |
| | | private boolean ready = false; |
| | | //交易对信息 |
| | | //private ExchangeCoinPublishType publishType; |
| | | |
| | | private String clearTime; |
| | | |
| | | private SimpleDateFormat dateTimeFormat; |
| | |
| | | return; |
| | | } |
| | | // 如果 |
| | | if (exchangeOrder.getEntrustAmount().compareTo(BigDecimal.ZERO) <= 0 || exchangeOrder.getEntrustAmount().subtract(exchangeOrder.getDealAmount()).compareTo(BigDecimal.ZERO) <= 0) { |
| | | return; |
| | | if(OrderCoinsEntity.ORDERTYPE_BUY==exchangeOrder.getOrderType()){ |
| | | if (exchangeOrder.getEntrustAmount().compareTo(BigDecimal.ZERO) <= 0 || exchangeOrder.getEntrustAmount().subtract(exchangeOrder.getDealAmount()).compareTo(BigDecimal.ZERO) <= 0) { |
| | | return; |
| | | } |
| | | }else{ |
| | | if (exchangeOrder.getEntrustCnt().compareTo(BigDecimal.ZERO) <= 0 || exchangeOrder.getEntrustCnt().subtract(exchangeOrder.getDealCnt()).compareTo(BigDecimal.ZERO) <= 0) { |
| | | return; |
| | | } |
| | | } |
| | | |
| | | |
| | | TreeMap<BigDecimal, MergeOrder> limitPriceOrderList; |
| | | LinkedList<OrderCoinsEntity> marketPriceOrderList; |
| | |
| | | while (iterator.hasNext()) { |
| | | OrderCoinsEntity matchOrder = iterator.next(); |
| | | ExchangeTrade trade = processMatch(focusedOrder, matchOrder); |
| | | logger.info(">>>>>" + trade); |
| | | if (trade != null) { |
| | | exchangeTrades.add(trade); |
| | | } |
| | |
| | | //orderCoinService.handleOrder(trades); |
| | | // kafkaTemplate.send("exchange-trade", JSON.toJSONString(trades)); |
| | | } |
| | | // 更新最新K线 TODO |
| | | |
| | | } |
| | | } |
| | |
| | | * @param buyTradePlate sellTradePlate |
| | | */ |
| | | public void sendTradePlateMessage(TradePlate buyTradePlate, TradePlate sellTradePlate) { |
| | | //防止并发引起数组越界,造成盘口倒挂 TODO |
| | | //防止并发引起数组越界,造成盘口倒挂 |
| | | List<List<BigDecimal>> plate; |
| | | List<BigDecimal> plateItem; |
| | | TradePlateModel tradePlateModel = new TradePlateModel(); |
| | |
| | | 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); |
| | |
| | | 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); |
| | |
| | | tradePlateModel.setSell(plate); |
| | | } |
| | | |
| | | // 盘口发生变化通知TODO |
| | | |
| | | // 盘口发生变化通知 |
| | | exchangeProducer.sendPlateMsg(JSON.toJSONString(tradePlateModel)); |
| | | } |
| | | |
| | |
| | | * @param |
| | | */ |
| | | public String sendTradePlateMessage() { |
| | | //防止并发引起数组越界,造成盘口倒挂 TODO |
| | | //防止并发引起数组越界,造成盘口倒挂 |
| | | List<List<BigDecimal>> plate; |
| | | List<BigDecimal> plateItem; |
| | | TradePlateModel tradePlateModel = new TradePlateModel(); |
| | |
| | | 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); |
| | |
| | | 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); |
| | |
| | | tradePlateModel.setSell(plate); |
| | | } |
| | | |
| | | // 盘口发生变化通知TODO |
| | | return JSON.toJSONString(tradePlateModel); |
| | | //exchangeProducer.sendPlateMsg(JSON.toJSONString(tradePlateModel)); |
| | | } |
| | | |
| | | /** |