From 3af20297ca45b2161bfe51cbd8fd918b293223c2 Mon Sep 17 00:00:00 2001
From: xiaoyong931011 <15274802129@163.com>
Date: Mon, 23 Nov 2020 14:55:55 +0800
Subject: [PATCH] 20201123
---
src/main/java/com/xcong/excoin/quartz/job/CoinTradeInitJob.java | 34 +++++++++++++++++++++++++++++++---
1 files changed, 31 insertions(+), 3 deletions(-)
diff --git a/src/main/java/com/xcong/excoin/quartz/job/CoinTradeInitJob.java b/src/main/java/com/xcong/excoin/quartz/job/CoinTradeInitJob.java
index 91a81fd..a72ee84 100644
--- a/src/main/java/com/xcong/excoin/quartz/job/CoinTradeInitJob.java
+++ b/src/main/java/com/xcong/excoin/quartz/job/CoinTradeInitJob.java
@@ -1,13 +1,16 @@
package com.xcong.excoin.quartz.job;
+import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.huobi.client.SubscriptionClient;
import com.huobi.client.SubscriptionOptions;
import com.huobi.client.model.Candlestick;
import com.huobi.client.model.enums.CandlestickInterval;
+import com.xcong.excoin.modules.coin.dao.OrderCoinDealDao;
import com.xcong.excoin.modules.coin.dao.OrderCoinsDao;
import com.xcong.excoin.modules.coin.entity.OrderCoinsEntity;
import com.xcong.excoin.modules.coin.service.OrderCoinService;
+import com.xcong.excoin.modules.symbols.constants.SymbolsConstats;
import com.xcong.excoin.modules.symbols.service.SymbolsService;
import com.xcong.excoin.processor.CoinProcessor;
import com.xcong.excoin.processor.CoinProcessorFactory;
@@ -17,6 +20,7 @@
import com.xcong.excoin.rabbit.producer.ExchangeProducer;
import com.xcong.excoin.trade.CoinTrader;
import com.xcong.excoin.trade.CoinTraderFactory;
+import com.xcong.excoin.trade.ExchangeTrade;
import com.xcong.excoin.utils.CoinTypeConvert;
import com.xcong.excoin.utils.RedisUtils;
import lombok.extern.slf4j.Slf4j;
@@ -30,6 +34,7 @@
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
/**
* 开启撮合交易
@@ -39,17 +44,19 @@
**/
@Slf4j
@Component
-//@ConditionalOnProperty(prefix = "app", name = "trade", havingValue = "true")
+@ConditionalOnProperty(prefix = "app", name = "exchange-trade", havingValue = "true")
public class CoinTradeInitJob {
@Resource
private OrderCoinsDao orderCoinsDao;
+ @Resource
+ private OrderCoinDealDao orderCoinDealDao;
@Resource
private CoinTraderFactory factory;
@Resource
- private OrderCoinService coinService;
+ private RedisUtils redisUtils;
@Resource
private MarketService marketService;
@@ -63,7 +70,7 @@
@PostConstruct
public void initCoinTrade() {
log.info("#=======撮合交易器开启=======#");
- String symbol = "NEKK";
+ String symbol = SymbolsConstats.ROC;
CoinTrader newTrader = new CoinTrader(symbol);
newTrader.setExchangeProducer(exchangeProducer);
//newTrader.setKafkaTemplate(kafkaTemplate);
@@ -80,6 +87,12 @@
List<OrderCoinsEntity> tradingOrders = new ArrayList<>();
List<OrderCoinsEntity> completedOrders = new ArrayList<>();
orders.forEach(order -> {
+ if(order.getDealCnt()==null){
+ order.setDealCnt(BigDecimal.ZERO);
+ }
+ if(order.getDealAmount()==null){
+ order.setDealAmount(BigDecimal.ZERO);
+ }
tradingOrders.add(order);
});
try {
@@ -94,11 +107,26 @@
// 创建K线生成器
CoinProcessor processor = new DefaultCoinProcessor(symbol, "USDT");
processor.setMarketService(marketService);
+ processor.setRedisUtils(redisUtils);
//processor.setExchangeRate(exchangeRate);
processor.initializeThumb();
//processor.initializeUsdRate();
processor.setIsHalt(false);
+ List<ExchangeTrade> nekk = orderCoinDealDao.selectOrderCoinDealByTime(SymbolsConstats.ROC, null, null);
+ processor.process(nekk);
+ String symbolUsdt = symbol;
+ if(!symbol.contains("USDT")){
+ symbolUsdt = symbol+"/USDT";
+ }
+ String key = "NEW_KINE_{}";
+ key = StrUtil.format(key, symbolUsdt);
+ Object o = redisUtils.get(key);
+ if(o!=null){
+ Map<String, Candlestick> currentKlineMap = (Map<String, Candlestick> )o;
+ ((DefaultCoinProcessor) processor).setCurrentKlineMap(currentKlineMap);
+ }
processorFactory.addProcessor(symbol, processor);
+
}
}
--
Gitblit v1.9.1