| | |
| | | |
| | | 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; |
| | | import org.apache.commons.collections.CollectionUtils; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | |
| | |
| | | if (trade != null) { |
| | | exchangeTrades.add(trade); |
| | | } |
| | | //判断匹配单是否完成 TODO |
| | | //判断匹配单是否完成 |
| | | if (matchOrder.getOrderStatus() == OrderCoinsEntity.ORDERSTATUS_DONE) { |
| | | //当前匹配的订单完成交易,删除该订单 |
| | | orderIterator.remove(); |
| | |
| | | } |
| | | } |
| | | //如果还没有交易完,订单压入列表中,市价买单按成交量算 |
| | | if (focusedOrder.getOrderType() == OrderCoinsEntity.ORDERTYPE_SELL && focusedOrder.getDealCnt().compareTo(focusedOrder.getEntrustCnt()) < 0 |
| | | || focusedOrder.getOrderType() == OrderCoinsEntity.ORDERTYPE_BUY && focusedOrder.getDealAmount().compareTo(focusedOrder.getEntrustAmount()) < 0) { |
| | | if ((focusedOrder.getOrderType() == OrderCoinsEntity.ORDERTYPE_SELL && focusedOrder.getDealCnt().compareTo(focusedOrder.getEntrustCnt()) < 0) |
| | | || (focusedOrder.getOrderType() == OrderCoinsEntity.ORDERTYPE_BUY && focusedOrder.getDealAmount().compareTo(focusedOrder.getEntrustAmount()) < 0)) { |
| | | logger.info("市价单未交易完成:#{}"+JSON.toJSONString(focusedOrder)); |
| | | // 打印此时的限价买单 |
| | | logger.info("此时的买单:#{}"+JSON.toJSONString(lpList)); |
| | | addMarketPriceOrder(focusedOrder); |
| | | } |
| | | //每个订单的匹配批量推送 |
| | |
| | | */ |
| | | private BigDecimal calculateTradedAmount(OrderCoinsEntity order, BigDecimal dealPrice) { |
| | | if (order.getOrderType() == OrderCoinsEntity.ORDERTYPE_BUY && order.getTradeType() == OrderCoinsEntity.TRADETYPE_MARKETPRICE) { |
| | | //剩余成交量 TODO ? |
| | | //剩余成交量 |
| | | // 委托量-成交量=剩余量 |
| | | BigDecimal leftTurnover = order.getEntrustAmount().subtract(order.getDealAmount()); |
| | | return leftTurnover.divide(dealPrice, coinScale, BigDecimal.ROUND_DOWN); |
| | |
| | | focusedOrder.setDealAmount(focusedOrder.getDealAmount().add(turnover)); |
| | | |
| | | // 判断两个单是否完成 |
| | | if(matchOrder.getEntrustAmount()!=null && matchOrder.getEntrustAmount().compareTo(matchOrder.getDealAmount())<=0){ |
| | | if(matchOrder.getEntrustAmount()!=null &&matchOrder.getEntrustAmount().compareTo(BigDecimal.ZERO)>0 && matchOrder.getEntrustAmount().compareTo(matchOrder.getDealAmount())<=0){ |
| | | matchOrder.setOrderStatus(OrderCoinsEntity.ORDERSTATUS_DONE); |
| | | } |
| | | if(matchOrder.getEntrustCnt()!=null && matchOrder.getEntrustCnt().compareTo(matchOrder.getDealCnt())<=0){ |
| | | if(matchOrder.getEntrustCnt()!=null &&matchOrder.getEntrustCnt().compareTo(BigDecimal.ZERO)>0 && matchOrder.getEntrustCnt().compareTo(matchOrder.getDealCnt())<=0){ |
| | | matchOrder.setOrderStatus(OrderCoinsEntity.ORDERSTATUS_DONE); |
| | | } |
| | | |
| | | if(focusedOrder.getEntrustAmount()!=null && focusedOrder.getEntrustAmount().compareTo(focusedOrder.getDealAmount())<=0){ |
| | | if(focusedOrder.getEntrustAmount()!=null && focusedOrder.getEntrustAmount().compareTo(BigDecimal.ZERO)>0 && focusedOrder.getEntrustAmount().compareTo(focusedOrder.getDealAmount())<=0){ |
| | | focusedOrder.setOrderStatus(OrderCoinsEntity.ORDERSTATUS_DONE); |
| | | } |
| | | if(focusedOrder.getEntrustCnt()!=null && focusedOrder.getEntrustCnt().compareTo(focusedOrder.getDealCnt())<=0){ |
| | | if(focusedOrder.getEntrustCnt()!=null &&focusedOrder.getEntrustCnt().compareTo(BigDecimal.ZERO)>0 && focusedOrder.getEntrustCnt().compareTo(focusedOrder.getDealCnt())<=0){ |
| | | focusedOrder.setOrderStatus(OrderCoinsEntity.ORDERSTATUS_DONE); |
| | | } |
| | | |
| | |
| | | for (int index = 0; index < size; index += maxSize) { |
| | | int length = (size - index) > maxSize ? maxSize : size - index; |
| | | List<OrderCoinsEntity> subOrders = orders.subList(index, index + length); |
| | | // TODO 通知订单完成 |
| | | //kafkaTemplate.send("exchange-order-completed", JSON.toJSONString(subOrders)); |
| | | // 通知订单完成 |
| | | exchangeProducer.sendCompleteMsg(JSON.toJSONString(subOrders)); |
| | | } |
| | | } else { |
| | | // kafkaTemplate.send("exchange-order-completed", JSON.toJSONString(orders)); |
| | | exchangeProducer.sendCompleteMsg(JSON.toJSONString(orders)); |
| | | } |
| | | } |
| | | } |