feat:K线-季度/半年/年

This commit is contained in:
rplees
2023-12-04 20:56:38 +08:00
parent 93fc03bfa9
commit 19e7fb544e
3 changed files with 22 additions and 14 deletions

View File

@@ -227,18 +227,8 @@ public class InvestingApis {
if(code == null) { if(code == null) {
throw new RuntimeException("找不到股票信息"); throw new RuntimeException("找不到股票信息");
} }
String interval = null;
if("min".equalsIgnoreCase(string)) {
interval = "PT5M";
} else if("day".equalsIgnoreCase(string)) {
interval = "P1D";
} else if("week".equalsIgnoreCase(string)) {
interval = "P1W";
} else if("month".equalsIgnoreCase(string)) {
interval = "P1M";
}
Date nowDate = new Date(); Date nowDate = new Date();
JSONObject json = InvestingInvokerApis.of().__kline(code, interval); JSONObject json = InvestingInvokerApis.of().__kline(code, string);
return json return json
.getJSONArray("data") .getJSONArray("data")
.stream() .stream()

View File

@@ -138,6 +138,7 @@ public class InvestingInvokerApis {
throw new RuntimeException("找不到股票信息"); throw new RuntimeException("找不到股票信息");
} }
String interval = null; String interval = null;
String period = null;
if("min".equalsIgnoreCase(string)) { if("min".equalsIgnoreCase(string)) {
interval = "PT5M"; interval = "PT5M";
} else if("day".equalsIgnoreCase(string)) { } else if("day".equalsIgnoreCase(string)) {
@@ -146,13 +147,30 @@ public class InvestingInvokerApis {
interval = "P1W"; interval = "P1W";
} else if("month".equalsIgnoreCase(string)) { } else if("month".equalsIgnoreCase(string)) {
interval = "P1M"; interval = "P1M";
} else if("3month".equalsIgnoreCase(string)) {
interval = "P1D";
period = "P3M";
} else if("6month".equalsIgnoreCase(string)) {
interval = "P1D";
period = "P6M";
} else if("year".equalsIgnoreCase(string)) {
interval = "P1W";
period = "P1Y";
} }
if(StringUtils.isBlank(interval)) { if(StringUtils.isBlank(interval)) {
interval = string; interval = string;
} }
String url = null;
if(StringUtils.isNotBlank(period)) {
String tmpl = "https://api.investing.com/api/financialdata/{}/historical/chart/?period={}&interval={}&pointscount=160";
url = StrFormatter.format(tmpl, code.getCode(), period, interval);
} else {
String tmpl = "https://api.investing.com/api/financialdata/{}/historical/chart/?interval={}&pointscount=160"; String tmpl = "https://api.investing.com/api/financialdata/{}/historical/chart/?interval={}&pointscount=160";
String url = StrFormatter.format(tmpl, code.getCode(), interval); url = StrFormatter.format(tmpl, code.getCode(), interval);
}
Builder builder = builderGet(url); Builder builder = builderGet(url);
String body = httpClient().newCall(builder.build()).execute().body().string(); String body = httpClient().newCall(builder.build()).execute().body().string();

View File

@@ -144,7 +144,7 @@ public class StockApiController {
@ResponseBody @ResponseBody
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "stockCode",value = "股票对应代码",dataType ="String", paramType = "query", required = true), @ApiImplicitParam(name = "stockCode",value = "股票对应代码",dataType ="String", paramType = "query", required = true),
@ApiImplicitParam(name = "type",value = "type min-时分线 day-日线 week-周线 month-月线",dataType ="String", paramType = "query", required = true), @ApiImplicitParam(name = "type",value = "min-时分线 day-日线 week-周线 month-月线, 3month-季度, 6month-半年, year-年",dataType ="String", paramType = "query", required = true),
}) })
public ServerResponse getINDTimeK(@RequestParam("stockCode") String stockCode, @RequestParam("type") String type) throws IOException { public ServerResponse getINDTimeK(@RequestParam("stockCode") String stockCode, @RequestParam("type") String type) throws IOException {
ParamUtils.verify("股票代码", stockCode, ParamUtils.STRING_NOT_EMPTY_VERIFY_AND_CONVERT_VALUE); ParamUtils.verify("股票代码", stockCode, ParamUtils.STRING_NOT_EMPTY_VERIFY_AND_CONVERT_VALUE);