Refinitiv未开盘时,将当前价设为昨日收盘价
This commit is contained in:
@@ -5,6 +5,7 @@ import com.google.common.collect.Lists;
|
|||||||
import com.thomsonreuters.ema.access.DataType;
|
import com.thomsonreuters.ema.access.DataType;
|
||||||
import com.thomsonreuters.ema.access.FieldEntry;
|
import com.thomsonreuters.ema.access.FieldEntry;
|
||||||
import com.thomsonreuters.ema.access.FieldList;
|
import com.thomsonreuters.ema.access.FieldList;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.util.ReflectionUtils;
|
import org.springframework.util.ReflectionUtils;
|
||||||
|
|
||||||
@@ -20,6 +21,7 @@ import java.util.List;
|
|||||||
* @author jnerh
|
* @author jnerh
|
||||||
* @since 2024/04/11 10:20
|
* @since 2024/04/11 10:20
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
public class RefinitivUtil {
|
public class RefinitivUtil {
|
||||||
|
|
||||||
public static RetifiveStockInfo decodeData(FieldList fieldList, String name) {
|
public static RetifiveStockInfo decodeData(FieldList fieldList, String name) {
|
||||||
@@ -135,17 +137,17 @@ public class RefinitivUtil {
|
|||||||
.week52HighPrice(week52High).week52LowPrice(week52Low).stockType(stockType)
|
.week52HighPrice(week52High).week52LowPrice(week52Low).stockType(stockType)
|
||||||
.change(changeValue)
|
.change(changeValue)
|
||||||
.build();
|
.build();
|
||||||
return handleBlandData(retifiveStockInfo);
|
return handleData(retifiveStockInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static List<String> decode(FieldList fieldList) {
|
public static List<String> decode(FieldList fieldList) {
|
||||||
List<String> list = Lists.newArrayList();
|
List<String> list = Lists.newArrayList();
|
||||||
String nextLink = "";
|
String nextLink = "";
|
||||||
for (FieldEntry fieldEntry : fieldList){
|
for (FieldEntry fieldEntry : fieldList) {
|
||||||
if(fieldEntry.name().startsWith("BR_LINK")){
|
if (fieldEntry.name().startsWith("BR_LINK")) {
|
||||||
nextLink = fieldEntry.load().toString();
|
nextLink = fieldEntry.load().toString();
|
||||||
if(!nextLink.contains("blank data")){
|
if (!nextLink.contains("blank data")) {
|
||||||
list.add(nextLink);
|
list.add(nextLink);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -163,98 +165,97 @@ public class RefinitivUtil {
|
|||||||
String openPrice = "";
|
String openPrice = "";
|
||||||
String previousPrice = "";
|
String previousPrice = "";
|
||||||
String percentChange = "";
|
String percentChange = "";
|
||||||
String week52High ="";
|
String week52High = "";
|
||||||
String week52Low = "";
|
String week52Low = "";
|
||||||
String high = "";
|
String high = "";
|
||||||
String low = "";
|
String low = "";
|
||||||
String volume = "";//实时交易数量
|
String volume = "";//实时交易数量
|
||||||
String stockType = "";
|
String stockType = "";
|
||||||
String changeValue = "";
|
String changeValue = "";
|
||||||
while (iter.hasNext())
|
while (iter.hasNext()) {
|
||||||
{
|
|
||||||
fieldEntry = iter.next();
|
fieldEntry = iter.next();
|
||||||
// System.out.println("Fid: " + fieldEntry.fieldId() + " Name: " + fieldEntry.name() +" Unit: "+DataType.asString(fieldEntry.loadType()) + " value: " + fieldEntry.load());
|
// System.out.println("Fid: " + fieldEntry.fieldId() + " Name: " + fieldEntry.name() +" Unit: "+DataType.asString(fieldEntry.loadType()) + " value: " + fieldEntry.load());
|
||||||
if(fieldEntry.name().equals("DSPLY_NAME")){
|
if (fieldEntry.name().equals("DSPLY_NAME")) {
|
||||||
if(fieldEntry.loadType() == DataType.DataTypes.RMTES) {
|
if (fieldEntry.loadType() == DataType.DataTypes.RMTES) {
|
||||||
stockName = fieldEntry.load().toString();
|
stockName = fieldEntry.load().toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(fieldEntry.name().equals("PROV_SYMB")){
|
if (fieldEntry.name().equals("PROV_SYMB")) {
|
||||||
if(fieldEntry.loadType() == DataType.DataTypes.RMTES) {
|
if (fieldEntry.loadType() == DataType.DataTypes.RMTES) {
|
||||||
stockCode = fieldEntry.load().toString();
|
stockCode = fieldEntry.load().toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(fieldEntry.name().equals("INST_PHASE")){
|
if (fieldEntry.name().equals("INST_PHASE")) {
|
||||||
if(fieldEntry.loadType() == DataType.DataTypes.ENUM) {
|
if (fieldEntry.loadType() == DataType.DataTypes.ENUM) {
|
||||||
status = fieldEntry.load().toString();
|
status = fieldEntry.load().toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(fieldEntry.name().equals("OPEN_PRC")){
|
if (fieldEntry.name().equals("OPEN_PRC")) {
|
||||||
if(fieldEntry.loadType() == DataType.DataTypes.REAL) {
|
if (fieldEntry.loadType() == DataType.DataTypes.REAL) {
|
||||||
openPrice = fieldEntry.load().toString();
|
openPrice = fieldEntry.load().toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(fieldEntry.name().equals("HST_CLOSE")){
|
if (fieldEntry.name().equals("HST_CLOSE")) {
|
||||||
if(fieldEntry.loadType() == DataType.DataTypes.REAL) {
|
if (fieldEntry.loadType() == DataType.DataTypes.REAL) {
|
||||||
previousPrice = fieldEntry.load().toString();
|
previousPrice = fieldEntry.load().toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(fieldEntry.name().equals("52WK_HIGH")){
|
if (fieldEntry.name().equals("52WK_HIGH")) {
|
||||||
if(fieldEntry.loadType() == DataType.DataTypes.REAL) {
|
if (fieldEntry.loadType() == DataType.DataTypes.REAL) {
|
||||||
week52High = fieldEntry.load().toString();
|
week52High = fieldEntry.load().toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(fieldEntry.name().equals("52WK_LOW")){
|
if (fieldEntry.name().equals("52WK_LOW")) {
|
||||||
if(fieldEntry.loadType() == DataType.DataTypes.REAL) {
|
if (fieldEntry.loadType() == DataType.DataTypes.REAL) {
|
||||||
week52Low = fieldEntry.load().toString();
|
week52Low = fieldEntry.load().toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(fieldEntry.name().equals("PCTCHNG")){ // NETCHNG_1
|
if (fieldEntry.name().equals("PCTCHNG")) { // NETCHNG_1
|
||||||
if(fieldEntry.loadType() == DataType.DataTypes.REAL) {
|
if (fieldEntry.loadType() == DataType.DataTypes.REAL) {
|
||||||
percentChange = fieldEntry.load().toString();
|
percentChange = fieldEntry.load().toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(fieldEntry.name().equals("NETCHNG_1")){ // NETCHNG_1
|
if (fieldEntry.name().equals("NETCHNG_1")) { // NETCHNG_1
|
||||||
if(fieldEntry.loadType() == DataType.DataTypes.REAL) {
|
if (fieldEntry.loadType() == DataType.DataTypes.REAL) {
|
||||||
changeValue = fieldEntry.load().toString();
|
changeValue = fieldEntry.load().toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(fieldEntry.name().equals("HIGH_1")){
|
if (fieldEntry.name().equals("HIGH_1")) {
|
||||||
if(fieldEntry.loadType() == DataType.DataTypes.REAL) {
|
if (fieldEntry.loadType() == DataType.DataTypes.REAL) {
|
||||||
high = fieldEntry.load().toString();
|
high = fieldEntry.load().toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(fieldEntry.name().equals("LOW_1")){
|
if (fieldEntry.name().equals("LOW_1")) {
|
||||||
if(fieldEntry.loadType() == DataType.DataTypes.REAL) {
|
if (fieldEntry.loadType() == DataType.DataTypes.REAL) {
|
||||||
low = fieldEntry.load().toString();
|
low = fieldEntry.load().toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(fieldEntry.name().equals("IRGVOL")){
|
if (fieldEntry.name().equals("IRGVOL")) {
|
||||||
if(fieldEntry.loadType() == DataType.DataTypes.REAL) {
|
if (fieldEntry.loadType() == DataType.DataTypes.REAL) {
|
||||||
volume = fieldEntry.load().toString();
|
volume = fieldEntry.load().toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(fieldEntry.name().equals("TRDPRC_1")){
|
if (fieldEntry.name().equals("TRDPRC_1")) {
|
||||||
if(fieldEntry.loadType() == DataType.DataTypes.REAL) {
|
if (fieldEntry.loadType() == DataType.DataTypes.REAL) {
|
||||||
price = fieldEntry.load().toString();
|
price = fieldEntry.load().toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(fieldEntry.name().equals("RDN_EXCHID")){
|
if (fieldEntry.name().equals("RDN_EXCHID")) {
|
||||||
if(fieldEntry.loadType() == DataType.DataTypes.ENUM) {
|
if (fieldEntry.loadType() == DataType.DataTypes.ENUM) {
|
||||||
stockType = fieldEntry.load().toString();
|
stockType = fieldEntry.load().toString();
|
||||||
if(StringUtils.equals(stockType,"145")){
|
if (StringUtils.equals(stockType, "145")) {
|
||||||
stockType = "bse";//孟买国家交易所
|
stockType = "bse";//孟买国家交易所
|
||||||
}else if(StringUtils.equals(stockType,"147")){
|
} else if (StringUtils.equals(stockType, "147")) {
|
||||||
stockType = "nse";//印度国家交易所
|
stockType = "nse";//印度国家交易所
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -265,10 +266,10 @@ public class RefinitivUtil {
|
|||||||
.volume(volume).week52HighPrice(week52High).week52LowPrice(week52Low).stockType(stockType).change(changeValue)
|
.volume(volume).week52HighPrice(week52High).week52LowPrice(week52Low).stockType(stockType).change(changeValue)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
return handleBlandData(retifiveStockInfo);
|
return handleData(retifiveStockInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static RetifiveStockInfo handleBlandData(RetifiveStockInfo retifiveStockInfo) {
|
private static RetifiveStockInfo handleData(RetifiveStockInfo retifiveStockInfo) {
|
||||||
Field[] fields = retifiveStockInfo.getClass().getDeclaredFields();
|
Field[] fields = retifiveStockInfo.getClass().getDeclaredFields();
|
||||||
Arrays.stream(fields).forEach(field -> {
|
Arrays.stream(fields).forEach(field -> {
|
||||||
ReflectionUtils.makeAccessible(field);
|
ReflectionUtils.makeAccessible(field);
|
||||||
@@ -279,10 +280,28 @@ public class RefinitivUtil {
|
|||||||
field.set(retifiveStockInfo, objStr.replace("(blank data)", ""));
|
field.set(retifiveStockInfo, objStr.replace("(blank data)", ""));
|
||||||
}
|
}
|
||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
throw new RuntimeException(e);
|
log.error("Refinitiv数据源处理数据出错,", e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 未开盘时,将当前价设为昨日收盘价
|
||||||
|
try {
|
||||||
|
Field statusField = retifiveStockInfo.getClass().getDeclaredField("status");
|
||||||
|
ReflectionUtils.makeAccessible(statusField);
|
||||||
|
Object obj = statusField.get(retifiveStockInfo);
|
||||||
|
if (obj instanceof String) {
|
||||||
|
String objStr = (String) obj;
|
||||||
|
if (StringUtils.equals(objStr, "1")) {
|
||||||
|
Field lastPriceField = retifiveStockInfo.getClass().getDeclaredField("lastPrice");
|
||||||
|
Field previousPriceField = retifiveStockInfo.getClass().getDeclaredField("previousPrice");
|
||||||
|
ReflectionUtils.makeAccessible(previousPriceField);
|
||||||
|
ReflectionUtils.makeAccessible(lastPriceField);
|
||||||
|
lastPriceField.set(retifiveStockInfo, previousPriceField.get(retifiveStockInfo));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Refinitiv数据源获取status出错,", e);
|
||||||
|
}
|
||||||
return retifiveStockInfo;
|
return retifiveStockInfo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user