From d174d6963d62b3bd176f9e7ba3cf0d7f75a91b69 Mon Sep 17 00:00:00 2001
From: zainali5120 <512061637@qq.com>
Date: Wed, 16 Sep 2020 16:03:22 +0800
Subject: [PATCH] 撮合交易代码提交

---
 src/main/java/com/xcong/excoin/quartz/job/KLineGeneratorJob.java |   79 +++++++++++++++++++++------------------
 1 files changed, 42 insertions(+), 37 deletions(-)

diff --git a/src/main/java/com/xcong/excoin/quartz/job/KLineGeneratorJob.java b/src/main/java/com/xcong/excoin/quartz/job/KLineGeneratorJob.java
index 946af01..5972de9 100644
--- a/src/main/java/com/xcong/excoin/quartz/job/KLineGeneratorJob.java
+++ b/src/main/java/com/xcong/excoin/quartz/job/KLineGeneratorJob.java
@@ -1,10 +1,16 @@
 package com.xcong.excoin.quartz.job;
 
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import com.huobi.client.model.Candlestick;
+import com.xcong.excoin.modules.coin.dao.OrderCoinDealDao;
+import com.xcong.excoin.modules.coin.entity.OrderCoinsDealEntity;
+import com.xcong.excoin.modules.coin.service.OrderCoinService;
 import com.xcong.excoin.processor.CoinProcessorFactory;
 import com.xcong.excoin.trade.TradePlateModel;
 import com.xcong.excoin.utils.RedisUtils;
+import com.xcong.excoin.websocket.CandlestickModel;
+import com.xcong.excoin.websocket.NewCandlestick;
 import com.xcong.excoin.websocket.TradePlateSendWebSocket;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -13,9 +19,11 @@
 
 import javax.annotation.Resource;
 import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.List;
+import java.util.Random;
 
 /**
  * 生成各时间段的K线信息
@@ -28,45 +36,41 @@
     private CoinProcessorFactory processorFactory;
 
     @Resource
-	private TradePlateSendWebSocket plateSendWebSocket;
+	private OrderCoinService orderCoinService;
 
-	@Resource
-	private RedisUtils redisUtils;
 
-	@Scheduled(cron = "0/10 * * * * *")
-    public void tradePlate(){
-		redisUtils.set("NEKK_NEW_PRICE",new BigDecimal(Math.random()*20));
-		Candlestick candlestick = new Candlestick();
-		candlestick.setOpen(new BigDecimal("10.33"));
-		candlestick.setHigh(new BigDecimal("15.23"));
-		candlestick.setVolume(new BigDecimal("12121.34"));
-		candlestick.setLow(new BigDecimal("8.234"));
-		candlestick.setAmount(new BigDecimal("1199"));
-		candlestick.setTimestamp(1599840000);
-		candlestick.setId(1599840000L);
-		candlestick.setCount(100002);
-		candlestick.setClose(new BigDecimal("12.2323"));
-		//redisUtils.set("NEKK/USDT",candlestick);
-		// [[10244.21, 0.000855], [10243.7, 0.008777], [10243.59, 0.14], [10243.37, 0.467663]]
-		TradePlateModel tradePlateModel = new TradePlateModel();
-		List<BigDecimal> buy;
-		List<BigDecimal> sell;
-		for(int i=0;i<5;i++){
-			buy = new ArrayList<>(2);
-			buy.add(new BigDecimal(Math.random()*i));
-			buy.add(new BigDecimal(Math.random()*i));
-			tradePlateModel.getBuy().add(buy);
-			sell = new ArrayList<>(2);
-			sell.add(new BigDecimal(Math.random()*i*2));
-			sell.add(new BigDecimal(Math.random()*i*2));
-			tradePlateModel.getSell().add(sell);
+
+	@Scheduled(cron = "0/1 * * * * *")
+	public void test(){
+//		for(int i=1;i<=2;i++){
+//			OrderCoinsDealEntity detail = new OrderCoinsDealEntity();
+//			detail.setMemberId(13L);
+//			//detail.setOrderId(111);
+//			detail.setOrderNo("tete");
+//			detail.setOrderType(1);
+//			detail.setTradeType(1);
+//			detail.setSymbol("NEKK");
+//			detail.setSymbolCnt(new BigDecimal(10));
+//			detail.setEntrustPrice(new BigDecimal(10));
+//			detail.setDealPrice(new BigDecimal(i*10*Math.random()));
+//			detail.setDealAmount(new BigDecimal(50));
+//			detail.setFeeAmount(new BigDecimal(1));
+//			detail.setOrderStatus(OrderCoinsDealEntity.ORDERSTATUS_DONE);
+//			orderCoinDealDao.insert(detail);
+//		}
+		Random random = new Random();
+		Integer type = OrderCoinsDealEntity.ORDERTYPE_BUY;
+		Integer tradeType = OrderCoinsDealEntity.TRADETYPE_FIXEDPRICE;
+		int i = random.nextInt(100);
+		if(i==0){
+			i=10;
 		}
-        log.info("准备发送消息");
-		plateSendWebSocket.sendMessagePlate("NEKK/USDT",JSON.toJSONString(tradePlateModel),null);
-		plateSendWebSocket.sendMessageKline("NEKK/USDT","1min","{amount: 114419.67835656216,close: 2.7261,count: 782,high: 2.7299,id: 1599632100,low: 2.723,open: 2.7288,vol: 311958.06091543}",null);
-		plateSendWebSocket.sendMessageKline("NEKK/USDT","5min","{amount: 514419.67835656216,close: 2.7261,count: 782,high: 2.7299,id: 1599632100,low: 2.723,open: 2.7288,vol: 911958.06091543}",null);
-		plateSendWebSocket.sendMessageKline("NEKK/USDT","15min","{amount: 514419.67835656216,close: 2.7261,count: 782,high: 2.7299,id: 1599632100,low: 2.723,open: 2.7288,vol: 911958.06091543}",null);
+		BigDecimal price =   new BigDecimal(i);
+		orderCoinService.initOrders("NEKK",type,tradeType,price,new BigDecimal(2),null);
+		orderCoinService.initOrders("NEKK",OrderCoinsDealEntity.ORDERTYPE_SELL,tradeType,price,new BigDecimal(2),null);
+
 	}
+
 
     /**
      * 每分钟定时器,处理分钟K线
@@ -75,7 +79,7 @@
     public void handle5minKLine(){
 
         Calendar calendar = Calendar.getInstance();
-        log.debug("分钟K线:{}",calendar.getTime());
+        //log.debug("分钟K线:{}",calendar.getTime());
         //将秒、微秒字段置为0
         calendar.set(Calendar.SECOND,0);
         calendar.set(Calendar.MILLISECOND,0);
@@ -84,9 +88,10 @@
         int hour = calendar.get(Calendar.HOUR_OF_DAY);
         processorFactory.getProcessorMap().forEach((symbol,processor)->{
         	if(!processor.isStopKline()) {
-	            log.debug("生成{}分钟k线:{}",symbol);
+	            //log.debug("生成{}分钟k线:{}",symbol);
 	            //生成1分钟K线
 	            processor.autoGenerate();
+                processor.generateKLine(1, Calendar.MINUTE, time);
 	            //更新24H成交量
 	            processor.update24HVolume(time);
 	            if(minute%5 == 0) {

--
Gitblit v1.9.1