fix:修改指数信息

This commit is contained in:
xiaoliuhu
2024-01-10 11:01:44 +08:00
parent bc5cf91a88
commit a968f61a05
5 changed files with 54 additions and 6 deletions

View File

@@ -945,8 +945,10 @@ public class StockService {
market.setName("BSESENSEX指数");
vo1.setIndexVo(market);
String type = "min";
List<JSONObject> list = InvestingApis.of().kline(StockCode.of(stockCode), type);
String period = "P1D";
String interval = "PT1H";
String type = "day";
List<JSONObject> list = InvestingApis.of().kIndex(stockCode,period,interval, type);
if(list == null || list.size() == 0){
type = "day";
list = InvestingApis.of().kline(StockCode.of(stockCode), type);
@@ -963,8 +965,10 @@ public class StockService {
market.setName("NIFTY50指数");
vo2.setIndexVo(market);
String type = "min";
List<JSONObject> list = InvestingApis.of().kline(StockCode.of(stockCode), type);
String period = "P1D";
String interval = "PT1H";
String type = "day";
List<JSONObject> list = InvestingApis.of().kIndex(stockCode,period,interval, type);
if(list == null || list.size() == 0){
type = "day";
list = InvestingApis.of().kline(StockCode.of(stockCode), type);

View File

@@ -153,7 +153,6 @@ public class InvestingApis {
"Time": "1698055197",
"Url": "/equities/aditya-birla",
"Volume": 3693615
* @param httpClient
* @param currPage
* @param pageSize
* @return
@@ -252,6 +251,34 @@ public class InvestingApis {
.collect(Collectors.toList())
;
}
public List<JSONObject> kIndex(String code,String period, String interval,String type) throws IOException {
if(code == null) {
throw new RuntimeException("找不到股票信息");
}
Date nowDate = new Date();
JSONObject json = InvestingInvokerApis.of().__IndiaIndex(code, period,interval);
return json
.getJSONArray("data")
.stream()
.map(val -> {
JSONArray _ar = (JSONArray) val;
JSONObject item = new JSONObject();
item.put("date", _ar.get(0));
item.put("open", _ar.get(1));
item.put("high", _ar.get(2));
item.put("low", _ar.get(3));
item.put("close", _ar.get(4));
item.put("volume", _ar.get(5));
return item;
}).filter(val -> {
if("min".equalsIgnoreCase(type)) {
return DateUtil.isSameDay(nowDate, new Date(val.getLong("date")));
}
return true;
})
.collect(Collectors.toList())
;
}
public static InvestingApis of() {
return new InvestingApis();

View File

@@ -202,6 +202,15 @@ public class InvestingInvokerApis {
return JSON.parseObject(body);
}
public JSONObject __IndiaIndex(String code,String period, String interval)throws IOException {
String tmpl = "https://api.investing.com/api/financialdata/{}/historical/chart/?period={}&interval={}&pointscount=160";
String url = StrFormatter.format(tmpl, code, period, interval);
Builder builder = builderGet(url);
String body = httpClient().newCall(builder.build()).execute().body().string();
return JSON.parseObject(body);
}
public static InvestingInvokerApis of() {
return new InvestingInvokerApis();
}

View File

@@ -71,4 +71,10 @@ public class BtodayStockPO {
/**
* 上次更新时间 */
Date lastUpdateTime;
/** 是否锁定 0否 1是 */
Integer isLock;
/** 是否展示 0是 1否 */
Integer isShow;
}

View File

@@ -257,6 +257,8 @@ public class Scraper {
btodayStock.setSelfUrl(url);
btodayStock.setUrl(detailUrl);
btodayStock.setLastUpdateTime(new Date());
btodayStock.setIsLock(0);
btodayStock.setIsShow(0);
btodayStockRepo.save(btodayStock);
/* if (webInfo != null) {