|  |  |  | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | 
|---|
|  |  |  | import org.springframework.scheduling.annotation.Scheduled; | 
|---|
|  |  |  | import org.springframework.stereotype.Component; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Component | 
|---|
|  |  |  | @Slf4j | 
|---|
|  |  |  | @ConditionalOnProperty(prefix = "app", name = "exchange-trade", havingValue = "true") | 
|---|
|  |  |  | public class KLineGeneratorJob { | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private CoinProcessorFactory processorFactory; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private OrderCoinService orderCoinService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @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; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | long time = calendar.getTimeInMillis(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | processor.generateKLine(1, Calendar.HOUR_OF_DAY, time); | 
|---|
|  |  |  | // 四小时K线 | 
|---|
|  |  |  | int hour = calendar.get(Calendar.HOUR_OF_DAY); | 
|---|
|  |  |  | if(hour%4==0){ | 
|---|
|  |  |  | processor.generateKLine(4, Calendar.HOUR_OF_DAY, time); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } | 
|---|