use of com.mistra.plank.pojo.dto.StockRealTimePrice in project plank by MistraR.
the class Barbarossa method monitor.
/**
* 实时监测数据 显示股票实时涨跌幅度,最高,最低价格
*/
public void monitor() {
executorService.submit(() -> {
try {
List<Stock> stocks = stockMapper.selectList(new QueryWrapper<Stock>().eq("track", true));
Map<String, Stock> stockMap = stocks.stream().collect(Collectors.toMap(Stock::getName, e -> e));
List<StockRealTimePrice> realTimePrices = new ArrayList<>();
while (DateUtil.hour(new Date(), true) <= 15 && DateUtil.hour(new Date(), true) >= 9) {
for (Stock stock : stocks) {
String url = plankConfig.getXueQiuStockDetailUrl().replace("{code}", stock.getCode()).replace("{time}", String.valueOf(System.currentTimeMillis())).replace("{recentDayNumber}", "1");
String body = HttpUtil.getHttpGetResponseString(url, plankConfig.getXueQiuCookie());
JSONObject data = JSON.parseObject(body).getJSONObject("data");
JSONArray list = data.getJSONArray("item");
if (org.apache.commons.collections.CollectionUtils.isNotEmpty(list)) {
for (Object o : list) {
double v = ((JSONArray) o).getDoubleValue(5);
double rate = -(double) Math.round(((v - stock.getPurchasePrice().doubleValue()) / v) * 100) / 100;
realTimePrices.add(StockRealTimePrice.builder().todayRealTimePrice(v).name(stock.getName()).todayHighestPrice(((JSONArray) o).getDoubleValue(3)).todayLowestPrice(((JSONArray) o).getDoubleValue(4)).purchasePrice(stock.getPurchasePrice()).rate((int) (rate * 100)).increaseRate(((JSONArray) o).getDoubleValue(7)).build());
}
}
}
// 暴跌
List<StockRealTimePrice> slump = realTimePrices.stream().filter(e -> e.getIncreaseRate() < -5).collect(Collectors.toList());
List<StockRealTimePrice> buy = realTimePrices.stream().filter(e -> e.getRate() >= -3).collect(Collectors.toList());
Collections.sort(realTimePrices);
Collections.sort(slump);
Collections.sort(buy);
System.out.println("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
log.error("----------------------------------------持仓----------------------------------------");
for (StockRealTimePrice realTimePrice : realTimePrices) {
if (stockMap.get(realTimePrice.getName()).getShareholding()) {
Barbarossa.log.warn(convertLog(realTimePrice));
}
}
log.error("--------------------------------------接近建仓点--------------------------------------");
for (StockRealTimePrice realTimePrice : buy) {
if (!stockMap.get(realTimePrice.getName()).getShareholding()) {
if (realTimePrice.getRate() >= -1) {
Barbarossa.log.warn(convertLog(realTimePrice));
} else {
Barbarossa.log.info(convertLog(realTimePrice));
}
}
}
log.error("----------------------------------------暴跌----------------------------------------");
for (StockRealTimePrice realTimePrice : slump) {
if (!stockMap.get(realTimePrice.getName()).getShareholding()) {
Barbarossa.log.warn(convertLog(realTimePrice));
}
}
realTimePrices.clear();
Thread.sleep(10000);
}
} catch (Exception e) {
e.printStackTrace();
}
});
}
Aggregations