Merge remote-tracking branch 'origin/retifive' into retifive

# Conflicts:
#	src/main/java/cn/stock/market/utils/RefinitivUtil.java
This commit is contained in:
zhangjian
2024-05-10 08:30:09 +08:00
8 changed files with 62 additions and 42 deletions

View File

@@ -191,11 +191,11 @@
<version>30.1-jre</version> <version>30.1-jre</version>
</dependency> </dependency>
<dependency> <!--<dependency>
<groupId>com.thomsonreuters.ema</groupId> <groupId>com.thomsonreuters.ema</groupId>
<artifactId>ema</artifactId> <artifactId>ema</artifactId>
<version>3.5.1.0</version> <version>3.5.1.0</version>
</dependency> </dependency>-->
<dependency> <dependency>
<groupId>com.refinitiv.ema</groupId> <groupId>com.refinitiv.ema</groupId>
<artifactId>ema</artifactId> <artifactId>ema</artifactId>

View File

@@ -265,7 +265,7 @@ public class RefinitivConsumer implements ApplicationRunner {
} }
@SneakyThrows @SneakyThrows
public RetifiveStockHistoryResponse getKLink(String symbol, String resolution){ public RetifiveStockHistoryResponse getKLink(String symbol, String resolution,String starttime, String endtime){
RetifiveStockHistoryResponse result = new RetifiveStockHistoryResponse(); RetifiveStockHistoryResponse result = new RetifiveStockHistoryResponse();
String token = getToken(); String token = getToken();
if(StringUtils.isBlank(token)){ if(StringUtils.isBlank(token)){
@@ -278,60 +278,59 @@ public class RefinitivConsumer implements ApplicationRunner {
int countback = 5; int countback = 5;
String interval = null; String interval = null;
String resourceEndpoint = null; String resourceEndpoint = null;
Date start = new Date(); Date start = new SimpleDateFormat("yyyy-MM-dd").parse(starttime);
Date end = new SimpleDateFormat("yyyy-MM-dd").parse(endtime);
long duration = end.getTime() - start.getTime();
long minutes = TimeUnit.MILLISECONDS.toMinutes(duration);
String fields = null; String fields = null;
Integer flag = 0; Integer flag = 0;
if(StringUtils.equals("1m",resolution)){ if(StringUtils.equals("1m",resolution)){
start = DateTimeUtil.getDayOfMorning(start,0);
countback = 360; countback = (int)minutes;
interval = "PT1M"; interval = "PT1M";
resourceEndpoint = baseURLToday + symbol; resourceEndpoint = baseURLToday + symbol;
fields = "DATE,HIGH_1,LOW_1,OPEN_PRC,TRDPRC_1,NUM_MOVES"; fields = "DATE,HIGH_1,LOW_1,OPEN_PRC,TRDPRC_1,NUM_MOVES";
}else }else
if(StringUtils.equals("5m",resolution)){ if(StringUtils.equals("5m",resolution)){
start = DateTimeUtil.getDayOfMorning(start,0); countback = (int) (minutes/5);
countback = 150;
interval = "PT5M"; interval = "PT5M";
resourceEndpoint = baseURLToday + symbol; resourceEndpoint = baseURLToday + symbol;
fields = "DATE,HIGH_1,LOW_1,OPEN_PRC,TRDPRC_1,NUM_MOVES"; fields = "DATE,HIGH_1,LOW_1,OPEN_PRC,TRDPRC_1,NUM_MOVES";
}else }else
if(StringUtils.equals("10m",resolution)){ if(StringUtils.equals("10m",resolution)){
start = DateTimeUtil.getDayOfMorning(start,0); countback = (int) (minutes/10);
countback = 50;
interval = "PT10M"; interval = "PT10M";
resourceEndpoint = baseURLToday + symbol; resourceEndpoint = baseURLToday + symbol;
fields = "DATE,HIGH_1,LOW_1,OPEN_PRC,TRDPRC_1,NUM_MOVES"; fields = "DATE,HIGH_1,LOW_1,OPEN_PRC,TRDPRC_1,NUM_MOVES";
}else }else
if(StringUtils.equals("30m",resolution)){ if(StringUtils.equals("30m",resolution)){
start = DateTimeUtil.getDayOfMorning(start,0); countback = (int) (minutes/30);
countback = 30;
interval = "PT30M"; interval = "PT30M";
resourceEndpoint = baseURLToday + symbol; resourceEndpoint = baseURLToday + symbol;
fields = "DATE,HIGH_1,LOW_1,OPEN_PRC,TRDPRC_1,NUM_MOVES"; fields = "DATE,HIGH_1,LOW_1,OPEN_PRC,TRDPRC_1,NUM_MOVES";
}else }else
if(StringUtils.equals("H",resolution)){ if(StringUtils.equals("H",resolution)){
start = DateTimeUtil.getDayOfMorning(start,0); countback = (int) (minutes/60);
countback = 60;
interval = "PT1H"; interval = "PT1H";
resourceEndpoint = baseURLToday + symbol; resourceEndpoint = baseURLToday + symbol;
fields = "DATE,HIGH_1,LOW_1,OPEN_PRC,TRDPRC_1,NUM_MOVES"; fields = "DATE,HIGH_1,LOW_1,OPEN_PRC,TRDPRC_1,NUM_MOVES";
}else if(StringUtils.equals("D",resolution)){ }else if(StringUtils.equals("D",resolution)){
start = DateTimeUtil.getDayOfMorning(start,-30);
countback = 30; countback = (int)(minutes/24/60);
interval ="P1D"; interval ="P1D";
fields = "DATE,HIGH_1,LOW_1,OPEN_PRC,OFF_CLOSE,NUM_MOVES"; fields = "DATE,HIGH_1,LOW_1,OPEN_PRC,OFF_CLOSE,NUM_MOVES";
flag = 1; flag = 1;
resourceEndpoint = baseURLHistory + symbol; resourceEndpoint = baseURLHistory + symbol;
}else if(StringUtils.equals("W",resolution)){ }else if(StringUtils.equals("W",resolution)){
start = DateTimeUtil.getDayOfMorning(start,-60);
countback = 30; countback = (int)(minutes/7/24/60);
interval ="P1W"; interval ="P1W";
fields = "DATE,HIGH_1,LOW_1,OPEN_PRC,OFF_CLOSE,NUM_MOVES"; fields = "DATE,HIGH_1,LOW_1,OPEN_PRC,OFF_CLOSE,NUM_MOVES";
flag = 2; flag = 2;
resourceEndpoint = baseURLHistory + symbol; resourceEndpoint = baseURLHistory + symbol;
}else if(StringUtils.equals("M",resolution)){ }else if(StringUtils.equals("M",resolution)){
start = DateTimeUtil.getDayOfYear(start,-1);
countback = 30; countback = (int)(minutes/30/24/60);
interval ="P1M"; interval ="P1M";
fields = "DATE,HIGH_1,LOW_1,OPEN_PRC,OFF_CLOSE,NUM_MOVES"; fields = "DATE,HIGH_1,LOW_1,OPEN_PRC,OFF_CLOSE,NUM_MOVES";
flag = 2; flag = 2;
@@ -340,9 +339,11 @@ public class RefinitivConsumer implements ApplicationRunner {
DateTimeFormatter formatterIso = DateTimeFormatter.ISO_INSTANT; DateTimeFormatter formatterIso = DateTimeFormatter.ISO_INSTANT;
String startStr = start.toInstant().atZone(ZoneId.of("UTC")).format(formatterIso); String startStr = start.toInstant().atZone(ZoneId.of("UTC")).format(formatterIso);
String endStr = end.toInstant().atZone(ZoneId.of("UTC")).format(formatterIso);
HttpResponse response = HttpUtil.createGet(resourceEndpoint) HttpResponse response = HttpUtil.createGet(resourceEndpoint)
.form("eventTypes","trade,quote") .form("eventTypes","trade,quote")
.form("start",startStr) .form("start",startStr)
.form("end",endStr)
.form("count",countback) .form("count",countback)
.form("interval",interval) .form("interval",interval)
.form("fields",fields) .form("fields",fields)

View File

@@ -1,3 +1,4 @@
/*
package cn.stock.market.listener; package cn.stock.market.listener;
import com.thomsonreuters.ema.access.AckMsg; import com.thomsonreuters.ema.access.AckMsg;
@@ -79,8 +80,10 @@ public class AppClient implements OmmConsumerClient {
messageFuture.complete(refreshMsg); messageFuture.complete(refreshMsg);
} }
if(expectedItemCount.get()>1){ if(expectedItemCount.get()>1){
/* System.out.println("监听的消息:"+refreshMsg.streamId()+","+refreshMsg.name()+ */
",是否完成:"+refreshMsg.complete());*/ /* System.out.println("监听的消息:"+refreshMsg.streamId()+","+refreshMsg.name()+
",是否完成:"+refreshMsg.complete());*//*
RefreshMsg msg = EmaFactory.createRefreshMsg(refreshMsg); RefreshMsg msg = EmaFactory.createRefreshMsg(refreshMsg);
messages.put(refreshMsg.name()+"", msg); // 假设每个refreshMsg都有一个uniqueIdentifier方法 messages.put(refreshMsg.name()+"", msg); // 假设每个refreshMsg都有一个uniqueIdentifier方法
if (messages.size() == expectedItemCount.get()) { // 使用get()获取当前值 if (messages.size() == expectedItemCount.get()) { // 使用get()获取当前值
@@ -135,3 +138,4 @@ public class AppClient implements OmmConsumerClient {
} }
// 其他消息处理... // 其他消息处理...
} }
*/

View File

@@ -1,3 +1,4 @@
/*
package cn.stock.market.listener; package cn.stock.market.listener;
import com.thomsonreuters.ema.access.AckMsg; import com.thomsonreuters.ema.access.AckMsg;
@@ -17,10 +18,12 @@ import org.springframework.stereotype.Service;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
*/
/** /**
* @author gs * @author gs
* @date 2024/4/8 22:01 * @date 2024/4/8 22:01
*/ *//*
@Service @Service
public class ConcurrentAppClient implements OmmConsumerClient { public class ConcurrentAppClient implements OmmConsumerClient {
private final ConcurrentHashMap<String, CompletableFuture<RefreshMsg>> futures = new ConcurrentHashMap<>(); private final ConcurrentHashMap<String, CompletableFuture<RefreshMsg>> futures = new ConcurrentHashMap<>();
@@ -73,3 +76,4 @@ public class ConcurrentAppClient implements OmmConsumerClient {
} }
} }
*/

View File

@@ -1,3 +1,4 @@
/*
package cn.stock.market.listener; package cn.stock.market.listener;
import com.thomsonreuters.ema.access.EmaFactory; import com.thomsonreuters.ema.access.EmaFactory;
@@ -34,3 +35,4 @@ public class MyAppRunner implements ApplicationRunner {
} }
*/

View File

@@ -5,6 +5,9 @@ import cn.stock.market.domain.basic.entity.RetifiveStock;
import cn.stock.market.dto.RetifiveStockInfo; import cn.stock.market.dto.RetifiveStockInfo;
import cn.stock.market.lesg.InstrumentData; import cn.stock.market.lesg.InstrumentData;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.refinitiv.ema.access.DataType;
import com.refinitiv.ema.access.FieldEntry;
import com.refinitiv.ema.access.FieldList;
import lombok.extern.slf4j.Slf4j; 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;

View File

@@ -1,3 +1,4 @@
/*
package cn.stock.market.web; package cn.stock.market.web;
import cn.stock.market.domain.basic.entity.RetifiveStock; import cn.stock.market.domain.basic.entity.RetifiveStock;
@@ -97,7 +98,8 @@ public class MessageRetifiveController {
} }
/* @GetMapping("/getStockInfoList") */
/* @GetMapping("/getStockInfoList")
@Deprecated @Deprecated
public ServerResponse<?> getStockInfoList() { public ServerResponse<?> getStockInfoList() {
ExecutorService executorService = Executors.newFixedThreadPool(5); // 创建一个固定大小的线程池 ExecutorService executorService = Executors.newFixedThreadPool(5); // 创建一个固定大小的线程池
@@ -146,7 +148,8 @@ public class MessageRetifiveController {
} }
return ServerResponse.createBySuccess("操作成功"); return ServerResponse.createBySuccess("操作成功");
}*/ }*//*
@GetMapping("/testStockInfoList2") @GetMapping("/testStockInfoList2")
@@ -334,7 +337,8 @@ public class MessageRetifiveController {
} }
/* void decode(FieldList fieldList) */
/* void decode(FieldList fieldList)
{ {
for (FieldEntry fieldEntry : fieldList) for (FieldEntry fieldEntry : fieldList)
{ {
@@ -377,7 +381,8 @@ public class MessageRetifiveController {
break; break;
} }
} }
}*/ }*//*
String decode1(FieldList fieldList,String name) String decode1(FieldList fieldList,String name)
{ {
@@ -393,10 +398,12 @@ public class MessageRetifiveController {
String symbol = fieldEntry.load().toString(); String symbol = fieldEntry.load().toString();
if(!symbol.contains("blank data")){ if(!symbol.contains("blank data")){
mongoTemplate.insert(new SymbolRefinitiv(symbol,"bse",name)); mongoTemplate.insert(new SymbolRefinitiv(symbol,"bse",name));
/* RetifiveStock retifiveStockPO = new RetifiveStock(); */
/* RetifiveStock retifiveStockPO = new RetifiveStock();
retifiveStockPO.setSymbol(name); retifiveStockPO.setSymbol(name);
retifiveStockPO.setStockType("bse"); retifiveStockPO.setStockType("bse");
retifiveStockService.repository().save(retifiveStockPO);*/ retifiveStockService.repository().save(retifiveStockPO);*//*
} }
} }
} }
@@ -552,18 +559,22 @@ public class MessageRetifiveController {
} }
} }
/*StockInfoRefinitiv stockInfoRefinitiv = new StockInfoRefinitiv(); */
/*StockInfoRefinitiv stockInfoRefinitiv = new StockInfoRefinitiv();
stockInfoRefinitiv.setStockName(stockName); stockInfoRefinitiv.setStockName(stockName);
stockInfoRefinitiv.setStockCode(stockCode); stockInfoRefinitiv.setStockCode(stockCode);
stockInfoRefinitiv.setStatus(status); stockInfoRefinitiv.setStatus(status);
stockInfoRefinitiv.setStockType("bse"); stockInfoRefinitiv.setStockType("bse");
stockInfoRefinitiv.setCommandStr(name); stockInfoRefinitiv.setCommandStr(name);
mongoTemplate.insert(stockInfoRefinitiv);*/ mongoTemplate.insert(stockInfoRefinitiv);*//*
/* 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).currentPrice(price).highPrice(high).lowPrice(low).previousPrice(previousPrice).changePercent(percentChange) .openPrice(openPrice).currentPrice(price).highPrice(high).lowPrice(low).previousPrice(previousPrice).changePercent(percentChange)
.volume(volume).week52HighPrice(week52High).week52LowPrice(week52Low).stockType(stockType).changeValue(changeValue) .volume(volume).week52HighPrice(week52High).week52LowPrice(week52Low).stockType(stockType).changeValue(changeValue)
.build();*/ .build();*//*
RetifiveStock retifiveStock = RetifiveStock.builder().stockType(stockType).saveTime(new Date()).isLock(0).isShow(0) RetifiveStock retifiveStock = RetifiveStock.builder().stockType(stockType).saveTime(new Date()).isLock(0).isShow(0)
.stockCode(stockCode).symbol(name).stockName(stockName).build(); .stockCode(stockCode).symbol(name).stockName(stockName).build();
@@ -706,3 +717,4 @@ public class MessageRetifiveController {
return itemNames; return itemNames;
} }
} }
*/

View File

@@ -7,7 +7,6 @@ import cn.stock.market.domain.basic.service.RetifiveStockService;
import cn.stock.market.dto.RetifiveStockHistoryResponse; import cn.stock.market.dto.RetifiveStockHistoryResponse;
import cn.stock.market.dto.RetifiveStockInfo; import cn.stock.market.dto.RetifiveStockInfo;
import cn.stock.market.lesg.RefinitivConsumer; import cn.stock.market.lesg.RefinitivConsumer;
import cn.stock.market.listener.AppClient;
import cn.stock.market.utils.ServerResponse; import cn.stock.market.utils.ServerResponse;
import cn.stock.market.web.annotations.EncryptFilter; import cn.stock.market.web.annotations.EncryptFilter;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
@@ -38,8 +37,6 @@ public class RefinitivApiController {
@Resource @Resource
private RefinitivConsumer refinitivConsumer; private RefinitivConsumer refinitivConsumer;
@Resource
private AppClient appClient;
@Autowired @Autowired
private RetifiveStockService retifiveStockService; private RetifiveStockService retifiveStockService;
@@ -63,9 +60,6 @@ public class RefinitivApiController {
return ServerResponse.createBySuccess("操作成功", retifiveStockInfo); return ServerResponse.createBySuccess("操作成功", retifiveStockInfo);
} catch (Exception e) { } catch (Exception e) {
log.error("获取股票详情link:" + symbol, e); log.error("获取股票详情link:" + symbol, e);
} finally {
// 可能需要重置或清理资源
appClient.resetMessageFuture();
} }
return ServerResponse.createBySuccess("操作成功"); return ServerResponse.createBySuccess("操作成功");
@@ -142,13 +136,13 @@ public class RefinitivApiController {
@ApiOperation(value = "查询股票K线", httpMethod = "GET", response = RetifiveStockHistoryResponse.class) @ApiOperation(value = "查询股票K线", httpMethod = "GET", response = RetifiveStockHistoryResponse.class)
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "symbol",value = "股票对应代码symbol",dataType ="String",required = true, paramType = "query"),
@ApiImplicitParam(name = "symbol",value = "股票对应代码symbol",dataType ="String",required = true, paramType = "query"), @ApiImplicitParam(name = "symbol",value = "股票对应代码symbol",dataType ="String",required = true, paramType = "query"),
@ApiImplicitParam(name = "resolution", value = "单位:60 1D 1W 1D 对应H,D,W,Y", required = true, dataType = "String", paramType = "query"), @ApiImplicitParam(name = "resolution", value = "单位:60 1D 1W 1D 对应H,D,W,Y", required = true, dataType = "String", paramType = "query"),
}) })
@GetMapping("/getKlink") @GetMapping("/getKlink")
@EncryptFilter(decryptRequest = false) @EncryptFilter(decryptRequest = false)
public ServerResponse<?> getKlink(@RequestParam("symbol") String symbol, @RequestParam String resolution) { public ServerResponse<?> getKlink(@RequestParam("symbol") String symbol, @RequestParam("resolution") String resolution,
return ServerResponse.createBySuccess(refinitivConsumer.getKLink(symbol,resolution)); @RequestParam("starttime") String starttime,@RequestParam("endtime") String endtime) {
return ServerResponse.createBySuccess(refinitivConsumer.getKLink(symbol,resolution,starttime,endtime));
} }
} }