Merge branch 'bug/update_kline_format' into 'develop'
update See merge request india/india_market_java!46
This commit is contained in:
@@ -55,6 +55,10 @@ import org.springframework.web.util.UriUtils;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.time.YearMonth;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@@ -722,17 +726,17 @@ public class MoneyApiController {
|
|||||||
}else if(StringUtils.equals("D",resolution)){
|
}else if(StringUtils.equals("D",resolution)){
|
||||||
to = (long) (System.currentTimeMillis() / 1000);
|
to = (long) (System.currentTimeMillis() / 1000);
|
||||||
from = to - (2 * 30 * 24 * 60 * 60 );
|
from = to - (2 * 30 * 24 * 60 * 60 );
|
||||||
countback = 329;
|
countback = 730;
|
||||||
request.setResolution("1D");
|
request.setResolution("1D");
|
||||||
} else if (StringUtils.equals("W", resolution)) {
|
} else if (StringUtils.equals("W", resolution)) {
|
||||||
to = (long) (System.currentTimeMillis() / 1000);
|
to = (long) (System.currentTimeMillis() / 1000);
|
||||||
from = to - (7 * 24 * 60 * 60);
|
from = to - (7 * 24 * 60 * 60);
|
||||||
countback = 471;
|
countback = 730;
|
||||||
request.setResolution("1W");
|
request.setResolution("1W");
|
||||||
} else if (StringUtils.equals("M", resolution)) {
|
} else if (StringUtils.equals("M", resolution)) {
|
||||||
to = (long) (System.currentTimeMillis() / 1000);
|
to = (long) (System.currentTimeMillis() / 1000);
|
||||||
from = to - (2 * 30 * 24 * 60 * 60 );
|
from = to - (15 * 30 * 24 * 60 * 60);
|
||||||
countback = 329;
|
countback = 730;
|
||||||
request.setResolution("1D");
|
request.setResolution("1D");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -772,10 +776,53 @@ public class MoneyApiController {
|
|||||||
double low = lowNode.get(i).asDouble();
|
double low = lowNode.get(i).asDouble();
|
||||||
double high = highNode.get(i).asDouble();
|
double high = highNode.get(i).asDouble();
|
||||||
|
|
||||||
stocks.add(new StockChartDto(timestamp, openPrice, closePrice, volume, low, high));
|
stocks.add(new StockChartDto(timestamp, openPrice, high, low, closePrice, volume));
|
||||||
}
|
}
|
||||||
|
|
||||||
response = restTemplate.getForObject(apiUrl, StockHistoryResponse.class);
|
Map<String, List<StockChartDto>> groupedByMonth = stocks.stream()
|
||||||
|
.collect(Collectors.groupingBy(
|
||||||
|
sp -> Instant.ofEpochSecond(sp.getTimestamp())
|
||||||
|
.atZone(ZoneId.systemDefault())
|
||||||
|
.toLocalDate()
|
||||||
|
.format(DateTimeFormatter.ofPattern("yyyy-MM")),
|
||||||
|
LinkedHashMap::new,
|
||||||
|
Collectors.toList()
|
||||||
|
));
|
||||||
|
|
||||||
|
List<Long> timestamps = new ArrayList<>();
|
||||||
|
List<Double> opens = new ArrayList<>();
|
||||||
|
List<Double> closes = new ArrayList<>();
|
||||||
|
List<Double> highs = new ArrayList<>();
|
||||||
|
List<Double> lows = new ArrayList<>();
|
||||||
|
List<Long> volumes = new ArrayList<>();
|
||||||
|
|
||||||
|
response = new StockHistoryResponse();
|
||||||
|
groupedByMonth.forEach((month, prices) -> {
|
||||||
|
double open = prices.get(0).getOpen();
|
||||||
|
double close = prices.get(prices.size() - 1).getClose();
|
||||||
|
double high = prices.stream().mapToDouble(StockChartDto::getHigh).max().orElse(0);
|
||||||
|
double low = prices.stream().mapToDouble(StockChartDto::getLow).min().orElse(0);
|
||||||
|
double volume = prices.stream().mapToDouble(StockChartDto::getVolume).sum();
|
||||||
|
|
||||||
|
long timestamp = YearMonth.parse(month, DateTimeFormatter.ofPattern("yyyy-MM")).atDay(1).atStartOfDay(ZoneId.systemDefault()).toInstant().toEpochMilli() / 1000;
|
||||||
|
timestamps.add(timestamp);
|
||||||
|
opens.add(open);
|
||||||
|
closes.add(close);
|
||||||
|
highs.add(high);
|
||||||
|
lows.add(low);
|
||||||
|
volumes.add((long) volume);
|
||||||
|
|
||||||
|
System.out.println("Month: " + month);
|
||||||
|
System.out.println("Open: " + open + ", Close: " + close + ", High: " + high + ", Low: " + low);
|
||||||
|
});
|
||||||
|
|
||||||
|
response.setS("ok");
|
||||||
|
response.setT(timestamps);
|
||||||
|
response.setL(lows);
|
||||||
|
response.setH(highs);
|
||||||
|
response.setO(opens);
|
||||||
|
response.setC(closes);
|
||||||
|
response.setV(volumes);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
response = restTemplate.getForObject(apiUrl, StockHistoryResponse.class);
|
response = restTemplate.getForObject(apiUrl, StockHistoryResponse.class);
|
||||||
@@ -800,9 +847,6 @@ public class MoneyApiController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (response != null && !response.getS().equals("error")) {
|
if (response != null && !response.getS().equals("error")) {
|
||||||
if (StringUtils.equals("M", resolution)) {
|
|
||||||
|
|
||||||
}
|
|
||||||
// setResponse(response, resolution);
|
// setResponse(response, resolution);
|
||||||
// API request successful, return the response
|
// API request successful, return the response
|
||||||
return ResponseEntity.ok(response);
|
return ResponseEntity.ok(response);
|
||||||
|
|||||||
Reference in New Issue
Block a user