Merge branch 'bug/update_symbol' into 'develop'
fix bug chart day See merge request india/india_market_java!54
This commit is contained in:
@@ -823,6 +823,18 @@ public class MoneyApiController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Long convertToTimestamp(String dateStr) {
|
||||||
|
try {
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss a", Locale.US);
|
||||||
|
Date date = sdf.parse(dateStr);
|
||||||
|
return date.getTime();
|
||||||
|
} catch (ParseException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return 0L;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@GetMapping({"/market/api/market/money/history/kLine", "/api/market/money/history/kLine"})
|
@GetMapping({"/market/api/market/money/history/kLine", "/api/market/money/history/kLine"})
|
||||||
@ApiOperation(value = "获取kline的money数据源", notes = "获取kline的money数据源", response = StockHistoryResponse.class)
|
@ApiOperation(value = "获取kline的money数据源", notes = "获取kline的money数据源", response = StockHistoryResponse.class)
|
||||||
@@ -872,6 +884,8 @@ public class MoneyApiController {
|
|||||||
List<Long> volumeList = new ArrayList<>();
|
List<Long> volumeList = new ArrayList<>();
|
||||||
List<Long> dateList = new ArrayList<>();
|
List<Long> dateList = new ArrayList<>();
|
||||||
|
|
||||||
|
Map<String, JsonObject> latestDataMap = new LinkedHashMap<>();
|
||||||
|
|
||||||
if (dataInputValues.size() > 0) {
|
if (dataInputValues.size() > 0) {
|
||||||
JsonObject dataObject = dataInputValues.get(0).getAsJsonObject();
|
JsonObject dataObject = dataInputValues.get(0).getAsJsonObject();
|
||||||
|
|
||||||
@@ -882,12 +896,80 @@ public class MoneyApiController {
|
|||||||
JsonArray volumeArray = dataObject.getAsJsonArray("VolumeData");
|
JsonArray volumeArray = dataObject.getAsJsonArray("VolumeData");
|
||||||
JsonArray dateArray = dataObject.getAsJsonArray("DateData");
|
JsonArray dateArray = dataObject.getAsJsonArray("DateData");
|
||||||
|
|
||||||
openArray.forEach(o -> addToListDouble(openList, o.getAsJsonObject().get("Open").getAsString()));
|
if (resolution.equals("H")) {
|
||||||
highArray.forEach(h -> addToListDouble(highList, h.getAsJsonObject().get("High").getAsString()));
|
openArray.forEach(o -> addToListDouble(openList, o.getAsJsonObject().get("Open").getAsString()));
|
||||||
lowArray.forEach(l -> addToListDouble(lowList, l.getAsJsonObject().get("Low").getAsString()));
|
highArray.forEach(h -> addToListDouble(highList, h.getAsJsonObject().get("High").getAsString()));
|
||||||
closeArray.forEach(c -> addToListDouble(closeList, c.getAsJsonObject().get("Close").getAsString()));
|
lowArray.forEach(l -> addToListDouble(lowList, l.getAsJsonObject().get("Low").getAsString()));
|
||||||
volumeArray.forEach(v -> addToList(volumeList, v.getAsJsonObject().get("Volume").getAsString()));
|
closeArray.forEach(c -> addToListDouble(closeList, c.getAsJsonObject().get("Close").getAsString()));
|
||||||
dateArray.forEach(d -> addDatesToList(dateList, d.getAsJsonObject().get("Date").getAsString()));
|
volumeArray.forEach(v -> addToList(volumeList, v.getAsJsonObject().get("Volume").getAsString()));
|
||||||
|
dateArray.forEach(d -> addDatesToList(dateList, d.getAsJsonObject().get("Date").getAsString()));
|
||||||
|
} else {
|
||||||
|
for (int i = 0; i < openArray.size(); i++) {
|
||||||
|
String open = openArray.get(i).getAsJsonObject().get("Open").getAsString();
|
||||||
|
String high = highArray.get(i).getAsJsonObject().get("High").getAsString();
|
||||||
|
String low = lowArray.get(i).getAsJsonObject().get("Low").getAsString();
|
||||||
|
String close = closeArray.get(i).getAsJsonObject().get("Close").getAsString();
|
||||||
|
String volume = volumeArray.get(i).getAsJsonObject().get("Volume").getAsString();
|
||||||
|
String dateStr = dateArray.get(i).getAsJsonObject().get("Date").getAsString();
|
||||||
|
|
||||||
|
Long timestamp = convertToTimestamp(dateStr);
|
||||||
|
|
||||||
|
String dateTimeKey = dateStr;
|
||||||
|
|
||||||
|
JsonObject dataJson = new JsonObject();
|
||||||
|
dataJson.addProperty("Open", open);
|
||||||
|
dataJson.addProperty("High", high);
|
||||||
|
dataJson.addProperty("Low", low);
|
||||||
|
dataJson.addProperty("Close", close);
|
||||||
|
dataJson.addProperty("Volume", volume);
|
||||||
|
dataJson.addProperty("Date", dateStr);
|
||||||
|
|
||||||
|
latestDataMap.put(dateTimeKey, dataJson);
|
||||||
|
}
|
||||||
|
|
||||||
|
latestDataMap.forEach((key, value) -> {
|
||||||
|
// Lấy giá trị các trường Open, High, Low, Close, Volume, Date từ dữ liệu
|
||||||
|
String openData = value.get("Open").getAsString();
|
||||||
|
String highData = value.get("High").getAsString();
|
||||||
|
String lowData = value.get("Low").getAsString();
|
||||||
|
String closeData = value.get("Close").getAsString();
|
||||||
|
String volumeData = value.get("Volume").getAsString();
|
||||||
|
String dateData = value.get("Date").getAsString();
|
||||||
|
|
||||||
|
// Tách các giá trị trong chuỗi bằng dấu phẩy
|
||||||
|
String[] openValues = openData.split(",");
|
||||||
|
String[] highValues = highData.split(",");
|
||||||
|
String[] lowValues = lowData.split(",");
|
||||||
|
String[] closeValues = closeData.split(",");
|
||||||
|
String[] volumeValues = volumeData.split(",");
|
||||||
|
String[] dateValues = dateData.split(",");
|
||||||
|
|
||||||
|
for (int i = 0; i < openValues.length; i++) {
|
||||||
|
double open = Double.parseDouble(openValues[i]);
|
||||||
|
double high = Double.parseDouble(highValues[i]);
|
||||||
|
double low = Double.parseDouble(lowValues[i]);
|
||||||
|
double close = Double.parseDouble(closeValues[i]);
|
||||||
|
long volume = Math.round(Double.parseDouble(volumeValues[i]));
|
||||||
|
long timestamp = convertToTimestamp(dateValues[i]);
|
||||||
|
|
||||||
|
int index = dateList.indexOf(timestamp);
|
||||||
|
if (index == -1) {
|
||||||
|
dateList.add(timestamp);
|
||||||
|
openList.add(open);
|
||||||
|
highList.add(high);
|
||||||
|
lowList.add(low);
|
||||||
|
closeList.add(close);
|
||||||
|
volumeList.add(volume);
|
||||||
|
} else {
|
||||||
|
openList.set(index, open);
|
||||||
|
highList.set(index, high);
|
||||||
|
lowList.set(index, low);
|
||||||
|
closeList.set(index, close);
|
||||||
|
volumeList.set(index, volume);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
StockHistoryResponse response = new StockHistoryResponse();
|
StockHistoryResponse response = new StockHistoryResponse();
|
||||||
response.setS("ok");
|
response.setS("ok");
|
||||||
|
|||||||
Reference in New Issue
Block a user