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.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 java.lang.reflect.Field;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -17,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) {
|
||||||
@@ -125,13 +130,14 @@ public class RefinitivUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return RetifiveStockInfo.builder()
|
RetifiveStockInfo retifiveStockInfo = RetifiveStockInfo.builder()
|
||||||
.stockCode(stockCode).stockName(stockName).symbol(name).status(status)
|
.stockCode(stockCode).stockName(stockName).symbol(name).status(status)
|
||||||
.openPrice(openPrice).lastPrice(price).highPrice(high).lowPrice(low)
|
.openPrice(openPrice).lastPrice(price).highPrice(high).lowPrice(low)
|
||||||
.previousPrice(previousPrice).perchg(percentChange).volume(volume)
|
.previousPrice(previousPrice).perchg(percentChange).volume(volume)
|
||||||
.week52HighPrice(week52High).week52LowPrice(week52Low).stockType(stockType)
|
.week52HighPrice(week52High).week52LowPrice(week52Low).stockType(stockType)
|
||||||
.change(changeValue)
|
.change(changeValue)
|
||||||
.build();
|
.build();
|
||||||
|
return handleData(retifiveStockInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -166,8 +172,7 @@ public class RefinitivUtil {
|
|||||||
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")) {
|
||||||
@@ -261,6 +266,42 @@ 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 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;
|
return retifiveStockInfo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package cn.stock.market.web;
|
package cn.stock.market.web;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.stock.market.domain.basic.entity.RetifiveStock;
|
import cn.stock.market.domain.basic.entity.RetifiveStock;
|
||||||
import cn.stock.market.domain.basic.service.RetifiveStockService;
|
import cn.stock.market.domain.basic.service.RetifiveStockService;
|
||||||
@@ -107,6 +108,10 @@ public class RefinitivApiController {
|
|||||||
RefreshMsg refreshMsg = appClient.getMessageFuture().get(10, TimeUnit.SECONDS);// 设置超时时间,例如10秒
|
RefreshMsg refreshMsg = appClient.getMessageFuture().get(10, TimeUnit.SECONDS);// 设置超时时间,例如10秒
|
||||||
if (DataType.DataTypes.FIELD_LIST == refreshMsg.payload().dataType()) {
|
if (DataType.DataTypes.FIELD_LIST == refreshMsg.payload().dataType()) {
|
||||||
List<String> strings = RefinitivUtil.decode(refreshMsg.payload().fieldList());
|
List<String> strings = RefinitivUtil.decode(refreshMsg.payload().fieldList());
|
||||||
|
if (CollUtil.isEmpty(strings)) {
|
||||||
|
return ServerResponse.createBySuccess("操作成功", list);
|
||||||
|
}
|
||||||
|
|
||||||
appClient.subscribeList(strings); // 根据itemName订阅
|
appClient.subscribeList(strings); // 根据itemName订阅
|
||||||
// 等待消息
|
// 等待消息
|
||||||
List<RefreshMsg> refreshMsgs = appClient.getMessagesFuture().get(10, TimeUnit.SECONDS);
|
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秒
|
RefreshMsg refreshMsg = appClient.getMessageFuture().get(10, TimeUnit.SECONDS);// 设置超时时间,例如10秒
|
||||||
if (DataType.DataTypes.FIELD_LIST == refreshMsg.payload().dataType()) {
|
if (DataType.DataTypes.FIELD_LIST == refreshMsg.payload().dataType()) {
|
||||||
List<String> strings = RefinitivUtil.decode(refreshMsg.payload().fieldList());
|
List<String> strings = RefinitivUtil.decode(refreshMsg.payload().fieldList());
|
||||||
|
if (CollUtil.isEmpty(strings)) {
|
||||||
|
return ServerResponse.createBySuccess("操作成功", list);
|
||||||
|
}
|
||||||
|
|
||||||
appClient.subscribeList(strings); // 根据itemName订阅
|
appClient.subscribeList(strings); // 根据itemName订阅
|
||||||
// 等待消息
|
// 等待消息
|
||||||
List<RefreshMsg> refreshMsgs = appClient.getMessagesFuture().get(10, TimeUnit.SECONDS);
|
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秒
|
RefreshMsg refreshMsg = appClient.getMessageFuture().get(10, TimeUnit.SECONDS);// 设置超时时间,例如10秒
|
||||||
if (DataType.DataTypes.FIELD_LIST == refreshMsg.payload().dataType()){
|
if (DataType.DataTypes.FIELD_LIST == refreshMsg.payload().dataType()){
|
||||||
List<String> strings = RefinitivUtil.decode(refreshMsg.payload().fieldList());
|
List<String> strings = RefinitivUtil.decode(refreshMsg.payload().fieldList());
|
||||||
|
if (CollUtil.isEmpty(strings)) {
|
||||||
|
return ServerResponse.createBySuccess("操作成功", list);
|
||||||
|
}
|
||||||
|
|
||||||
appClient.subscribeList(strings); // 根据itemName订阅
|
appClient.subscribeList(strings); // 根据itemName订阅
|
||||||
// 等待消息
|
// 等待消息
|
||||||
List<RefreshMsg> refreshMsgs = appClient.getMessagesFuture().get(10, TimeUnit.SECONDS);
|
List<RefreshMsg> refreshMsgs = appClient.getMessagesFuture().get(10, TimeUnit.SECONDS);
|
||||||
|
|||||||
Reference in New Issue
Block a user