use of com.mistra.plank.pojo.entity.DragonList in project plank by MistraR.
the class DragonListProcessor method execute.
private void execute(Date date, String timeStr) {
try {
String url = plankConfig.getDragonListUrl().replace("{time}", timeStr);
String body = HttpUtil.getHttpGetResponseString(url, null);
body = body.substring(body.indexOf("(") + 1, body.indexOf(")"));
JSONObject data = JSON.parseObject(body).getJSONObject("result");
if (Objects.isNull(data)) {
return;
}
log.info("抓取{}日龙虎榜数据!", sdf.format(date));
JSONArray list = data.getJSONArray("data");
List<DragonList> dragonLists = new ArrayList<>();
if (CollectionUtils.isNotEmpty(list)) {
JSONObject stock;
for (Object o : list) {
try {
stock = (JSONObject) o;
DragonList dragonList = new DragonList();
dragonList.setDate(date);
String[] split = stock.getString("SECUCODE").split("\\.");
dragonList.setCode(split[1] + split[0]);
dragonList.setName(stock.getString("SECURITY_NAME_ABBR"));
dragonList.setNetBuy(stock.getBigDecimal("BILLBOARD_NET_AMT").longValue());
BigDecimal buyAmt = stock.getBigDecimal("BILLBOARD_BUY_AMT");
dragonList.setBuy(Objects.nonNull(buyAmt) ? buyAmt.longValue() : 0);
BigDecimal sellAmt = stock.getBigDecimal("BILLBOARD_SELL_AMT");
dragonList.setSell(Objects.nonNull(sellAmt) ? sellAmt.longValue() : 0);
dragonList.setPrice(stock.getBigDecimal("CLOSE_PRICE"));
dragonList.setMarketValue(stock.getBigDecimal("FREE_MARKET_CAP").longValue());
dragonList.setAccumAmount(stock.getBigDecimal("ACCUM_AMOUNT").longValue());
dragonList.setChangeRate(stock.getBigDecimal("CHANGE_RATE").setScale(2, RoundingMode.HALF_UP));
dragonLists.add(dragonList);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Map<String, List<DragonList>> collect = dragonLists.stream().collect(Collectors.groupingBy(DragonList::getCode));
for (Map.Entry<String, List<DragonList>> entry : collect.entrySet()) {
dragonListMapper.insert(entry.getValue().get(0));
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.mistra.plank.pojo.entity.DragonList in project plank by MistraR.
the class Barbarossa method checkCanBuyStock.
/**
* 检查可以买的票 首板或者2板 10日涨幅介于10-22% 计算前8天的振幅在15%以内
*
* @return List<String>
*/
private List<Stock> checkCanBuyStock(Date date) {
List<DragonList> dragonLists = dragonListMapper.selectList(new QueryWrapper<DragonList>().ge("date", date).lt("date", DateUtils.addDays(date, 1)).ge("price", 5).le("price", 100).notLike("name", "%ST%").notLike("name", "%st%").notLike("name", "%A%").notLike("name", "%C%").notLike("name", "%N%").notLike("name", "%U%").notLike("name", "%W%").notLike("code", "%BJ%").notLike("code", "%688%"));
if (CollectionUtils.isEmpty(dragonLists)) {
return null;
}
List<DailyRecord> dailyRecords = new ArrayList<>();
for (DragonList dragonList : dragonLists) {
Page<DailyRecord> page = dailyRecordMapper.selectPage(new Page<>(1, 30), new QueryWrapper<DailyRecord>().eq("code", dragonList.getCode()).le("date", date).ge("date", DateUtils.addDays(date, -30)).orderByDesc("date"));
if (page.getRecords().size() > 10) {
dailyRecords.addAll(page.getRecords().subList(0, 10));
}
}
Map<String, List<DailyRecord>> map = dailyRecords.stream().collect(Collectors.groupingBy(DailyRecord::getCode));
List<String> stockCode = new ArrayList<>();
for (Map.Entry<String, List<DailyRecord>> entry : map.entrySet()) {
// 近8日涨幅
BigDecimal eightRatio = entry.getValue().get(0).getClosePrice().divide(entry.getValue().get(8).getClosePrice(), 2, RoundingMode.HALF_UP);
// 近3日涨幅
BigDecimal threeRatio = entry.getValue().get(0).getClosePrice().divide(entry.getValue().get(3).getClosePrice(), 2, RoundingMode.HALF_UP);
// 前3个交易日大跌的也排除
if (eightRatio.doubleValue() <= 1.22 && eightRatio.doubleValue() >= 1.1 && threeRatio.doubleValue() < 1.22 && entry.getValue().get(0).getIncreaseRate().doubleValue() > 0.04 && entry.getValue().get(1).getIncreaseRate().doubleValue() > -0.04 && entry.getValue().get(2).getIncreaseRate().doubleValue() > -0.04) {
stockCode.add(entry.getKey());
}
}
dragonLists = dragonLists.stream().filter(dragonList -> stockCode.contains(dragonList.getCode())).collect(Collectors.toList());
dragonLists = dragonLists.stream().sorted((a, b) -> b.getNetBuy().compareTo(a.getNetBuy())).collect(Collectors.toList());
List<Stock> result = new ArrayList<>();
for (DragonList dragonList : dragonLists) {
result.add(stockMapper.selectOne(new QueryWrapper<Stock>().eq("code", dragonList.getCode())));
}
return result;
}
Aggregations