| | |
| | | if (list.isEmpty()) { |
| | | return; |
| | | } |
| | | List<String> stockCodeList = list.stream().map(StockRealTimeBean::getSymbol).collect(Collectors.toList()); |
| | | List<Item> stockList = itemService.list(new QueryWrapper<Item>().in("symbol", stockCodeList)); |
| | | List<String> stockCodeList = list.stream().map(StockRealTimeBean::getId).collect(Collectors.toList()); |
| | | List<Item> stockList = itemService.list(new QueryWrapper<Item>() |
| | | .eq("type", Item.US_STOCKS).in("stock_code", stockCodeList)); |
| | | |
| | | List<Item> indicesList = itemService.list(new QueryWrapper<Item>() |
| | | .eq("type", Item.indices)); |
| | | |
| | | log.info("同步股票 已有数据 {} 获取数据 {}", stockList.size(), list.size()); |
| | | System.out.println(stockList); |
| | | List<Item> updateStockList = new ArrayList<>(); |
| | | for (StockRealTimeBean o : list) { |
| | | //System.out.println(o); |
| | | Item item = stockList.stream() |
| | | .filter(x -> x.getSymbol().equals(o.getSymbol()) && |
| | | x.getStockCode().equals(o.getId())) |
| | | .findFirst() |
| | | .orElse(null); |
| | | if (item != null) { //已有不添加 |
| | | continue; |
| | | } |
| | | item = indicesList.stream() |
| | | .filter(x -> x.getSymbol().equals(o.getSymbol())) |
| | | .findFirst() |
| | | .orElse(null); |
| | | if (item == null) { |
| | | item = new Item(); |
| | | if (item != null) { //已有不添加 |
| | | continue; |
| | | } |
| | | |
| | | item = new Item(); |
| | | String name = StringUtils.trim(o.getName()); |
| | | item.setEnName(name); |
| | | item.setName(name); |
| | |
| | | item.setShowStatus("1"); |
| | | item.setTradeStatus("1"); |
| | | item.setQuoteCurrency("USDT"); |
| | | item.setCrawlStatus("default_active"); |
| | | item.setStockCode(o.getId()); |
| | | |
| | | updateStockList.add(item); |
| | | |
| | |
| | | |
| | | DataCache.putRealtime(realtime.getSymbol(), realtime); |
| | | } |
| | | itemService.saveOrUpdateBatch(updateStockList); |
| | | log.info("同步股票 数据 成功 {} 总共同步数据 {}", eStockType.getCode(), list.size()); |
| | | if (!updateStockList.isEmpty()) { |
| | | itemService.saveOrUpdateBatch(updateStockList); |
| | | } |
| | | log.info("同步股票 数据 成功 {} 总共同步数据 {}", eStockType.getCode(), updateStockList.size()); |
| | | } catch ( |
| | | Exception e) { |
| | | log.error("同步出错", e); |
| | |
| | | items.addAll(itemsTop); |
| | | } else if ("US-stocks".equals(type)) { |
| | | // 只查询指数top6 |
| | | items = itemService.cacheGetAll().stream().filter(item -> "global".equals(item.getCategory())).limit(3).collect(Collectors.toList()); |
| | | List<Item> itemsTop = itemService.cacheGetAll().stream().filter(item -> "technology,prominent".equals(item.getCategory())).sorted(Comparator.comparing(Item::getSorted).reversed()).limit(size) |
| | | items = itemService.cacheGetAll().stream().filter(item -> item.getType().equalsIgnoreCase(Item.US_STOCKS)) |
| | | .sorted(Comparator.comparing(Item::getSorted).reversed()) |
| | | .limit(3).collect(Collectors.toList()); |
| | | /*List<Item> itemsTop = itemService.cacheGetAll().stream().filter(item -> "technology,prominent".equals(item.getCategory())).sorted(Comparator.comparing(Item::getSorted).reversed()).limit(size) |
| | | .collect(Collectors.toList()); |
| | | items.addAll(itemsTop); |
| | | items.addAll(itemsTop);*/ |
| | | } |
| | | // 加密货币、外汇、 top4 |
| | | else { |
| | |
| | | @RequestParam(required = false) Integer pageNo, |
| | | @RequestParam(required = false) Integer pageSize) { |
| | | try { |
| | | pageSize = null == pageSize ? 1000 : pageSize; |
| | | pageSize = null == pageSize ? 50 : pageSize; |
| | | List<Item> itemsTotal; |
| | | List<Item> items = new ArrayList<>(); |
| | | //按字符串排序 |
| | |
| | | int pages = itemsTotal.size() % pageSize == 0 ? itemsTotal.size() / pageSize : itemsTotal.size() / pageSize + 1; |
| | | int start = pageNo <= 0 ? 0 : (pageNo > pages ? (pages - 1) * pageSize : (pageNo - 1) * pageSize); |
| | | items = itemsTotal.stream().skip(start).limit(pageSize).collect(Collectors.toList()); |
| | | items.forEach(x -> x.setCategory("prominent")); |
| | | } |
| | | } else { |
| | | itemsTotal = new ArrayList<>(itemList); |
| | |
| | | symbol = itemService.getSymbolByRemarks(symbol); |
| | | Integer decimal = itemService.getDecimal(symbol); |
| | | Item item = this.itemService.findBySymbol(symbol); |
| | | if (item == null) { |
| | | return; |
| | | } |
| | | //更新行情中的symbol [要不然后续取不到缓存] |
| | | realtime.setSymbol(item.getSymbol()); |
| | | |
| | |
| | | |
| | | if(stockFirstFetch){ |
| | | |
| | | this.realtimeHandleXueQiu(aStockRemarks); |
| | | this.realtimeHandleXueQiu(hkStockRemarks); |
| | | this.realtimeHandleXueQiu(usStockRemarks); |
| | | //this.realtimeHandleXueQiu(aStockRemarks); |
| | | //this.realtimeHandleXueQiu(hkStockRemarks); |
| | | //this.realtimeHandleXueQiu(usStockRemarks); |
| | | //this.realtimeHandleTW(twStockRemarks); |
| | | //this.realtimeHandleCommon(jpStockRemarks); |
| | | //this.realtimeHandleCommon(indiaStockRemarks); |
| | |
| | | |
| | | |
| | | if(MarketOpenChecker.isMarketOpen(Item.A_STOCKS, 30)){ |
| | | this.realtimeHandleXueQiu(aStockRemarks); |
| | | //this.realtimeHandleXueQiu(aStockRemarks); |
| | | } |
| | | if(MarketOpenChecker.isMarketOpen(Item.HK_STOCKS, 30)){ |
| | | this.realtimeHandleXueQiu(hkStockRemarks); |
| | | //this.realtimeHandleXueQiu(hkStockRemarks); |
| | | } |
| | | if(MarketOpenChecker.isMarketOpen(Item.US_STOCKS, 30)){ |
| | | //美股 |
| | |
| | | */ |
| | | public void realtimeHandleTradingViewUsEtf() { |
| | | List<Realtime> realtimeList = this.tradingViewDataService.realtimeUsEtfSingle(); |
| | | List<Item> list = itemService.lambdaQuery().eq(Item::getMarket, Item.US_ETF).list(); |
| | | List<Item> list = itemService.lambdaQuery().eq(Item::getType, Item.indices).list(); |
| | | //去除未存在的symbol |
| | | List<String> collect = list.stream().map(Item::getSymbol).collect(Collectors.toList()); |
| | | realtimeList.removeIf(realtime -> !collect.contains(realtime.getSymbol())); |
| | | |
| | | super.handleRealTimeList(realtimeList); |
| | | } |
| | | |
| | |
| | | |
| | | //etf 跟 美股的行情 |
| | | String etfUsStockSymbols = list.stream() |
| | | .filter(item -> item.getOpenCloseType() != null &&item.getOpenCloseType() |
| | | .equalsIgnoreCase(Item.US_STOCKS)).map(Item::getSymbolData) |
| | | .filter(item -> item.getOpenCloseType() != null &&item.getOpenCloseType().equalsIgnoreCase(Item.US_STOCKS) |
| | | && item.getType().equalsIgnoreCase(Item.indices) |
| | | ).map(Item::getSymbolData) |
| | | .collect(Collectors.joining(",")); |
| | | //外汇 |
| | | String forexSymbols = list.stream() |
| | |
| | | .collect(Collectors.joining(",")); |
| | | |
| | | //港股 |
| | | String hkSymbols = list.stream() |
| | | /*String hkSymbols = list.stream() |
| | | .filter(item -> item.getOpenCloseType() != null && item.getOpenCloseType().equalsIgnoreCase(Item.HK_STOCKS)) |
| | | .map(item -> "HKEX:" + Integer.valueOf(item.getSymbolData())) |
| | | .collect(Collectors.joining(",")); |
| | | .collect(Collectors.joining(","));*/ |
| | | |
| | | // 开始订阅币种 |
| | | tradingViewService.subscribeSymbol(hkSymbols + "," + forexSymbols + "," + etfUsStockSymbols, data -> { |
| | | tradingViewService.subscribeSymbol(/*hkSymbols + "," +*/ forexSymbols + "," + etfUsStockSymbols, data -> { |
| | | // 使用共享线程池,延迟30分钟执行推送 |
| | | Realtime realtime = new Realtime(); |
| | | realtime.setSymbol(data.getShortName()); |
| | |
| | | * 采集所有美国ETF行情 |
| | | */ |
| | | public static List<Realtime> realtimeUsEtfSingle(){ |
| | | log.info(">>>>正在更新美国ETF行情<<<<"); |
| | | String body = HttpRequest.post(ALL_US_ETF_QUOTES_URL) |
| | | //.setHttpProxy("127.0.0.1",7890) |
| | | .body(getUsEtfQuotesParams()) |
| | |
| | | JSONObject bodyJson = JSON.parseObject(body); |
| | | JSONArray dataArr = bodyJson.getJSONArray("data"); |
| | | if (dataArr != null) { |
| | | log.info(">>>>正在更新美国ETF行情<<<<" + dataArr.size()); |
| | | for (int i = 0; i < dataArr.size(); i++) { |
| | | JSONObject item = dataArr.getJSONObject(i); |
| | | //封装行情缓存 |
| | | Realtime realtime = new Realtime(); |
| | | String symbol = item.getString("s"); |
| | | String symbol = item.getString("s").split(":")[1]; |
| | | realtime.setSymbol(symbol); |
| | | JSONArray data = item.getJSONArray("d"); |
| | | realtime.setName(data.get(1) != null ? (String) data.get(1) : ""); |
| | |
| | | import com.google.gson.reflect.TypeToken; |
| | | |
| | | import com.yami.trading.bean.data.domain.Realtime; |
| | | import com.yami.trading.bean.item.domain.Item; |
| | | import com.yami.trading.huobi.data.DataCache; |
| | | import com.yami.trading.huobi.websocket.constant.enums.EStockType; |
| | | import com.yami.trading.service.item.ItemService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.java_websocket.client.WebSocketClient; |
| | | import org.java_websocket.handshake.ServerHandshake; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | |
| | | import java.lang.reflect.Type; |
| | | import java.math.BigDecimal; |
| | |
| | | public class WebsocketRunClient extends WebSocketClient { |
| | | |
| | | private EStockType eStockType; |
| | | |
| | | @Autowired |
| | | ItemService itemService; |
| | | |
| | | public WebsocketRunClient(URI serverUri, EStockType eStockType) { |
| | | // 修改为新的WebSocket服务器地址 |
| | |
| | | if(!s.equals("pong") && !s.equals("身份验证成功")){ |
| | | try { |
| | | Map<String, String> stringObjectMap = jsonToMap(s); |
| | | |
| | | String symbol = stringObjectMap.get("symbol"); |
| | | Item item = itemService.findBySymbol(symbol); |
| | | if (!item.getType().equalsIgnoreCase(Item.US_STOCKS)) { |
| | | return; |
| | | } |
| | | Realtime realtime = new Realtime(); |
| | | realtime.setUuid(stringObjectMap.get("pid")); |
| | | realtime.setSymbol(stringObjectMap.get("symbol")); |
| | |
| | | public enum EStockType { |
| | | |
| | | |
| | | US("US","美国股票","5","http://api-us-v2.js-stock.top/","ws://api-us-v2-ws.js-stock.top","gAFCeL8vaTo7slHJFogb","USD","$"), |
| | | US("US","美国股票","5","http://api-us-v2.js-stock.top/","ws://api-us-v2-ws.js-stock.top","6g5RTSGmHwW1t7IHYwsj","USD","$"), |
| | | ; |
| | | |
| | | private String code; |
| | |
| | | @PostConstruct |
| | | public void init() { |
| | | // 同时初始化多组全局缓存: symbolDecimal symbolItem remarksSymbol itemList |
| | | log.info("init初始化item list"); |
| | | itemList = new ArrayList<>(list()); |
| | | } |
| | | |