Merge remote-tracking branch 'origin/retifive' into retifive
This commit is contained in:
@@ -5,8 +5,12 @@ import com.google.common.collect.Lists;
|
||||
import com.thomsonreuters.ema.access.DataType;
|
||||
import com.thomsonreuters.ema.access.FieldEntry;
|
||||
import com.thomsonreuters.ema.access.FieldList;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
@@ -17,6 +21,7 @@ import java.util.List;
|
||||
* @author jnerh
|
||||
* @since 2024/04/11 10:20
|
||||
*/
|
||||
@Slf4j
|
||||
public class RefinitivUtil {
|
||||
|
||||
public static RetifiveStockInfo decodeData(FieldList fieldList, String name) {
|
||||
@@ -125,23 +130,24 @@ public class RefinitivUtil {
|
||||
}
|
||||
}
|
||||
}
|
||||
return RetifiveStockInfo.builder()
|
||||
RetifiveStockInfo retifiveStockInfo = RetifiveStockInfo.builder()
|
||||
.stockCode(stockCode).stockName(stockName).symbol(name).status(status)
|
||||
.openPrice(openPrice).lastPrice(price).highPrice(high).lowPrice(low)
|
||||
.previousPrice(previousPrice).perchg(percentChange).volume(volume)
|
||||
.week52HighPrice(week52High).week52LowPrice(week52Low).stockType(stockType)
|
||||
.change(changeValue)
|
||||
.build();
|
||||
return handleData(retifiveStockInfo);
|
||||
}
|
||||
|
||||
|
||||
public static List<String> decode(FieldList fieldList) {
|
||||
List<String> list = Lists.newArrayList();
|
||||
String nextLink = "";
|
||||
for (FieldEntry fieldEntry : fieldList){
|
||||
if(fieldEntry.name().startsWith("BR_LINK")){
|
||||
for (FieldEntry fieldEntry : fieldList) {
|
||||
if (fieldEntry.name().startsWith("BR_LINK")) {
|
||||
nextLink = fieldEntry.load().toString();
|
||||
if(!nextLink.contains("blank data")){
|
||||
if (!nextLink.contains("blank data")) {
|
||||
list.add(nextLink);
|
||||
}
|
||||
}
|
||||
@@ -159,108 +165,143 @@ public class RefinitivUtil {
|
||||
String openPrice = "";
|
||||
String previousPrice = "";
|
||||
String percentChange = "";
|
||||
String week52High ="";
|
||||
String week52High = "";
|
||||
String week52Low = "";
|
||||
String high = "";
|
||||
String low = "";
|
||||
String volume = "";//实时交易数量
|
||||
String stockType = "";
|
||||
String changeValue = "";
|
||||
while (iter.hasNext())
|
||||
{
|
||||
while (iter.hasNext()) {
|
||||
fieldEntry = iter.next();
|
||||
// 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.loadType() == DataType.DataTypes.RMTES) {
|
||||
if (fieldEntry.name().equals("DSPLY_NAME")) {
|
||||
if (fieldEntry.loadType() == DataType.DataTypes.RMTES) {
|
||||
stockName = fieldEntry.load().toString();
|
||||
}
|
||||
}
|
||||
if(fieldEntry.name().equals("PROV_SYMB")){
|
||||
if(fieldEntry.loadType() == DataType.DataTypes.RMTES) {
|
||||
if (fieldEntry.name().equals("PROV_SYMB")) {
|
||||
if (fieldEntry.loadType() == DataType.DataTypes.RMTES) {
|
||||
stockCode = fieldEntry.load().toString();
|
||||
}
|
||||
}
|
||||
|
||||
if(fieldEntry.name().equals("INST_PHASE")){
|
||||
if(fieldEntry.loadType() == DataType.DataTypes.ENUM) {
|
||||
if (fieldEntry.name().equals("INST_PHASE")) {
|
||||
if (fieldEntry.loadType() == DataType.DataTypes.ENUM) {
|
||||
status = fieldEntry.load().toString();
|
||||
}
|
||||
}
|
||||
|
||||
if(fieldEntry.name().equals("OPEN_PRC")){
|
||||
if(fieldEntry.loadType() == DataType.DataTypes.REAL) {
|
||||
if (fieldEntry.name().equals("OPEN_PRC")) {
|
||||
if (fieldEntry.loadType() == DataType.DataTypes.REAL) {
|
||||
openPrice = fieldEntry.load().toString();
|
||||
}
|
||||
}
|
||||
|
||||
if(fieldEntry.name().equals("HST_CLOSE")){
|
||||
if(fieldEntry.loadType() == DataType.DataTypes.REAL) {
|
||||
if (fieldEntry.name().equals("HST_CLOSE")) {
|
||||
if (fieldEntry.loadType() == DataType.DataTypes.REAL) {
|
||||
previousPrice = fieldEntry.load().toString();
|
||||
}
|
||||
}
|
||||
|
||||
if(fieldEntry.name().equals("52WK_HIGH")){
|
||||
if(fieldEntry.loadType() == DataType.DataTypes.REAL) {
|
||||
if (fieldEntry.name().equals("52WK_HIGH")) {
|
||||
if (fieldEntry.loadType() == DataType.DataTypes.REAL) {
|
||||
week52High = fieldEntry.load().toString();
|
||||
}
|
||||
}
|
||||
|
||||
if(fieldEntry.name().equals("52WK_LOW")){
|
||||
if(fieldEntry.loadType() == DataType.DataTypes.REAL) {
|
||||
if (fieldEntry.name().equals("52WK_LOW")) {
|
||||
if (fieldEntry.loadType() == DataType.DataTypes.REAL) {
|
||||
week52Low = fieldEntry.load().toString();
|
||||
}
|
||||
}
|
||||
|
||||
if(fieldEntry.name().equals("PCTCHNG")){ // NETCHNG_1
|
||||
if(fieldEntry.loadType() == DataType.DataTypes.REAL) {
|
||||
if (fieldEntry.name().equals("PCTCHNG")) { // NETCHNG_1
|
||||
if (fieldEntry.loadType() == DataType.DataTypes.REAL) {
|
||||
percentChange = fieldEntry.load().toString();
|
||||
}
|
||||
}
|
||||
|
||||
if(fieldEntry.name().equals("NETCHNG_1")){ // NETCHNG_1
|
||||
if(fieldEntry.loadType() == DataType.DataTypes.REAL) {
|
||||
if (fieldEntry.name().equals("NETCHNG_1")) { // NETCHNG_1
|
||||
if (fieldEntry.loadType() == DataType.DataTypes.REAL) {
|
||||
changeValue = fieldEntry.load().toString();
|
||||
}
|
||||
}
|
||||
|
||||
if(fieldEntry.name().equals("HIGH_1")){
|
||||
if(fieldEntry.loadType() == DataType.DataTypes.REAL) {
|
||||
if (fieldEntry.name().equals("HIGH_1")) {
|
||||
if (fieldEntry.loadType() == DataType.DataTypes.REAL) {
|
||||
high = fieldEntry.load().toString();
|
||||
}
|
||||
}
|
||||
|
||||
if(fieldEntry.name().equals("LOW_1")){
|
||||
if(fieldEntry.loadType() == DataType.DataTypes.REAL) {
|
||||
if (fieldEntry.name().equals("LOW_1")) {
|
||||
if (fieldEntry.loadType() == DataType.DataTypes.REAL) {
|
||||
low = fieldEntry.load().toString();
|
||||
}
|
||||
}
|
||||
if(fieldEntry.name().equals("IRGVOL")){
|
||||
if(fieldEntry.loadType() == DataType.DataTypes.REAL) {
|
||||
if (fieldEntry.name().equals("IRGVOL")) {
|
||||
if (fieldEntry.loadType() == DataType.DataTypes.REAL) {
|
||||
volume = fieldEntry.load().toString();
|
||||
}
|
||||
}
|
||||
|
||||
if(fieldEntry.name().equals("TRDPRC_1")){
|
||||
if(fieldEntry.loadType() == DataType.DataTypes.REAL) {
|
||||
if (fieldEntry.name().equals("TRDPRC_1")) {
|
||||
if (fieldEntry.loadType() == DataType.DataTypes.REAL) {
|
||||
price = fieldEntry.load().toString();
|
||||
}
|
||||
}
|
||||
if(fieldEntry.name().equals("RDN_EXCHID")){
|
||||
if(fieldEntry.loadType() == DataType.DataTypes.ENUM) {
|
||||
if (fieldEntry.name().equals("RDN_EXCHID")) {
|
||||
if (fieldEntry.loadType() == DataType.DataTypes.ENUM) {
|
||||
stockType = fieldEntry.load().toString();
|
||||
if(StringUtils.equals(stockType,"145")){
|
||||
if (StringUtils.equals(stockType, "145")) {
|
||||
stockType = "bse";//孟买国家交易所
|
||||
}else if(StringUtils.equals(stockType,"147")){
|
||||
} else if (StringUtils.equals(stockType, "147")) {
|
||||
stockType = "nse";//印度国家交易所
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
RetifiveStockInfo retifiveStockInfo = RetifiveStockInfo.builder().stockCode(stockCode).stockName(stockName).symbol(name).status(status)
|
||||
RetifiveStockInfo retifiveStockInfo = RetifiveStockInfo.builder().stockCode(stockCode).stockName(stockName).symbol(name).status(status)
|
||||
.openPrice(openPrice).lastPrice(price).highPrice(high).lowPrice(low).previousPrice(previousPrice).perchg(percentChange)
|
||||
.volume(volume).week52HighPrice(week52High).week52LowPrice(week52Low).stockType(stockType).change(changeValue)
|
||||
.build();
|
||||
|
||||
return handleData(retifiveStockInfo);
|
||||
}
|
||||
|
||||
private static RetifiveStockInfo handleData(RetifiveStockInfo retifiveStockInfo) {
|
||||
Field[] fields = retifiveStockInfo.getClass().getDeclaredFields();
|
||||
Arrays.stream(fields).forEach(field -> {
|
||||
ReflectionUtils.makeAccessible(field);
|
||||
try {
|
||||
Object obj = field.get(retifiveStockInfo);
|
||||
if (obj instanceof String) {
|
||||
String objStr = (String) obj;
|
||||
field.set(retifiveStockInfo, objStr.replace("(blank data)", ""));
|
||||
}
|
||||
} catch (IllegalAccessException 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package cn.stock.market.web;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.stock.market.domain.basic.entity.RetifiveStock;
|
||||
import cn.stock.market.domain.basic.service.RetifiveStockService;
|
||||
@@ -107,6 +108,10 @@ public class RefinitivApiController {
|
||||
RefreshMsg refreshMsg = appClient.getMessageFuture().get(10, TimeUnit.SECONDS);// 设置超时时间,例如10秒
|
||||
if (DataType.DataTypes.FIELD_LIST == refreshMsg.payload().dataType()) {
|
||||
List<String> strings = RefinitivUtil.decode(refreshMsg.payload().fieldList());
|
||||
if (CollUtil.isEmpty(strings)) {
|
||||
return ServerResponse.createBySuccess("操作成功", list);
|
||||
}
|
||||
|
||||
appClient.subscribeList(strings); // 根据itemName订阅
|
||||
// 等待消息
|
||||
List<RefreshMsg> refreshMsgs = appClient.getMessagesFuture().get(10, TimeUnit.SECONDS);
|
||||
@@ -136,6 +141,10 @@ public class RefinitivApiController {
|
||||
RefreshMsg refreshMsg = appClient.getMessageFuture().get(10, TimeUnit.SECONDS);// 设置超时时间,例如10秒
|
||||
if (DataType.DataTypes.FIELD_LIST == refreshMsg.payload().dataType()) {
|
||||
List<String> strings = RefinitivUtil.decode(refreshMsg.payload().fieldList());
|
||||
if (CollUtil.isEmpty(strings)) {
|
||||
return ServerResponse.createBySuccess("操作成功", list);
|
||||
}
|
||||
|
||||
appClient.subscribeList(strings); // 根据itemName订阅
|
||||
// 等待消息
|
||||
List<RefreshMsg> refreshMsgs = appClient.getMessagesFuture().get(10, TimeUnit.SECONDS);
|
||||
@@ -166,6 +175,10 @@ public class RefinitivApiController {
|
||||
RefreshMsg refreshMsg = appClient.getMessageFuture().get(10, TimeUnit.SECONDS);// 设置超时时间,例如10秒
|
||||
if (DataType.DataTypes.FIELD_LIST == refreshMsg.payload().dataType()){
|
||||
List<String> strings = RefinitivUtil.decode(refreshMsg.payload().fieldList());
|
||||
if (CollUtil.isEmpty(strings)) {
|
||||
return ServerResponse.createBySuccess("操作成功", list);
|
||||
}
|
||||
|
||||
appClient.subscribeList(strings); // 根据itemName订阅
|
||||
// 等待消息
|
||||
List<RefreshMsg> refreshMsgs = appClient.getMessagesFuture().get(10, TimeUnit.SECONDS);
|
||||
|
||||
Reference in New Issue
Block a user