| | |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | 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.symbols.service.SymbolsService; |
| | | import com.xcong.excoin.netty.common.ServerChannelManager; |
| | | import com.xcong.excoin.netty.common.NettyTools; |
| | | import com.xcong.excoin.rabbit.pricequeue.WebsocketPriceService; |
| | | import com.xcong.excoin.utils.CoinTypeConvert; |
| | | import com.xcong.excoin.utils.RedisUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | @Autowired |
| | | private SubscriptionClient subscriptionClient; |
| | | |
| | | @PostConstruct |
| | | // @PostConstruct |
| | | public void initNewestPrice() { |
| | | log.info("#=======价格更新开启=======#"); |
| | | |
| | | subscriptionClient.subscribeTradeEvent("btcusdt,ethusdt,xrpusdt,ltcusdt,bchusdt,eosusdt,etcusdt", tradeEvent -> { |
| | | String symbol = tradeEvent.getSymbol(); |
| | | ServerChannelManager.getTcpGroup().writeAndFlush(NettyTools.textBytes(JSONObject.toJSONString(tradeEvent))); |
| | | // String symbol = tradeEvent.getSymbol(); |
| | | // // 根据symbol判断做什么操作 |
| | | symbol = CoinTypeConvert.convert(symbol); |
| | | if (null != symbol) { |
| | | String price = tradeEvent.getTradeList().get(0).getPrice().toPlainString(); |
| | | redisTemplate.convertAndSend("channel:newprice", symbol + "_" + price); |
| | | // symbol = CoinTypeConvert.convert(symbol); |
| | | // if (null != symbol) { |
| | | // String price = tradeEvent.getTradeList().get(0).getPrice().toPlainString(); |
| | | // // TODO 测试环境关闭这个插入redis |
| | | // redisUtils.set(CoinTypeConvert.convertToKey(symbol), price); |
| | | // // 比较 |
| | |
| | | // websocketPriceService.wholeBomb(); |
| | | // //System.out.println("比较完毕:"+symbol+"-"+price); |
| | | // |
| | | } |
| | | // } |
| | | |
| | | }); |
| | | // subscriptionClient.subscribeCandlestickEvent("btcusdt,ethusdt,eosusdt,etcusdt,ltcusdt,bchusdt,xrpusdt", CandlestickInterval.DAY1, (candlestickEvent) -> { |