Merge remote-tracking branch 'origin/retifive' into retifive
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
package cn.stock.market.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class RetifiveStockHistoryResponse {
|
||||
private String s;
|
||||
private List<Long> t;
|
||||
private List<Double> o;
|
||||
private List<Double> h;
|
||||
private List<Double> l;
|
||||
private List<Double> c;
|
||||
private List<Double> v;
|
||||
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.http.HttpResponse;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.stock.market.domain.basic.entity.RetifiveStock;
|
||||
import cn.stock.market.dto.RetifiveStockHistoryResponse;
|
||||
import cn.stock.market.dto.RetifiveStockInfo;
|
||||
import cn.stock.market.dto.StockHistoryResponse;
|
||||
import cn.stock.market.utils.DateTimeUtil;
|
||||
@@ -15,6 +16,7 @@ import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.refinitiv.ema.access.*;
|
||||
import com.refinitiv.ema.rdm.EmaRdm;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
@@ -24,12 +26,17 @@ import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.Instant;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static java.time.format.DateTimeFormatter.ISO_OFFSET_DATE_TIME;
|
||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||
|
||||
/**
|
||||
@@ -257,8 +264,9 @@ public class RefinitivConsumer implements ApplicationRunner {
|
||||
}
|
||||
}
|
||||
|
||||
public StockHistoryResponse getKLink(String symbol,String resolution){
|
||||
StockHistoryResponse result = new StockHistoryResponse();
|
||||
@SneakyThrows
|
||||
public RetifiveStockHistoryResponse getKLink(String symbol, String resolution){
|
||||
RetifiveStockHistoryResponse result = new RetifiveStockHistoryResponse();
|
||||
String token = getToken();
|
||||
if(StringUtils.isBlank(token)){
|
||||
throw new SysTipsException("token为空");
|
||||
@@ -277,16 +285,16 @@ public class RefinitivConsumer implements ApplicationRunner {
|
||||
interval = "PT1M";
|
||||
resourceEndpoint = baseURLToday + symbol;
|
||||
}else
|
||||
if(StringUtils.equals("3m",resolution)){
|
||||
if(StringUtils.equals("5m",resolution)){
|
||||
start = DateTimeUtil.getDayOfMorning(start,0);
|
||||
countback = 150;
|
||||
interval = "PT3M";
|
||||
interval = "PT5M";
|
||||
resourceEndpoint = baseURLToday + symbol;
|
||||
}else
|
||||
if(StringUtils.equals("15m",resolution)){
|
||||
if(StringUtils.equals("10m",resolution)){
|
||||
start = DateTimeUtil.getDayOfMorning(start,0);
|
||||
countback = 50;
|
||||
interval = "PT15M";
|
||||
interval = "PT10M";
|
||||
resourceEndpoint = baseURLToday + symbol;
|
||||
}else
|
||||
if(StringUtils.equals("30m",resolution)){
|
||||
@@ -317,9 +325,11 @@ public class RefinitivConsumer implements ApplicationRunner {
|
||||
resourceEndpoint = baseURLHistory + symbol;
|
||||
}
|
||||
|
||||
DateTimeFormatter formatterIso = DateTimeFormatter.ISO_INSTANT;
|
||||
String startStr = start.toInstant().atZone(ZoneId.of("UTC")).format(formatterIso);
|
||||
HttpResponse response = HttpUtil.createGet(resourceEndpoint)
|
||||
.form("eventTypes","trade,quote")
|
||||
.form("start",start)
|
||||
.form("start",startStr)
|
||||
.form("count",countback)
|
||||
.form("interval",interval)
|
||||
.header("Authorization","Bearer " + token)
|
||||
@@ -334,20 +344,26 @@ public class RefinitivConsumer implements ApplicationRunner {
|
||||
List<Double> h = new ArrayList<>(); // 最高价
|
||||
List<Double> l = new ArrayList<>();//最低价
|
||||
List<Double> c = new ArrayList<>();//当前价
|
||||
List<Long> v = new ArrayList<>();//交易量
|
||||
List<Double> v = new ArrayList<>();//交易量
|
||||
for(int i = 0; i < dateArray.size(); i++){
|
||||
JSONArray date = dateArray.getJSONArray(i);
|
||||
|
||||
Instant instant = Instant.parse(date.get(0).toString());
|
||||
long timestampMillis = instant.toEpochMilli();
|
||||
t.add(timestampMillis);
|
||||
|
||||
if(date.get(1) == null){
|
||||
continue;
|
||||
}
|
||||
if(StringUtils.equals("D",resolution) || StringUtils.equals("W",resolution) || StringUtils.equals("M",resolution)){
|
||||
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
|
||||
Date d = formatter.parse(date.get(0).toString());
|
||||
t.add(d.getTime() / 1000);
|
||||
}else {
|
||||
Instant instant = Instant.parse(date.get(0).toString());
|
||||
long timestampMillis = instant.getEpochSecond();
|
||||
t.add(timestampMillis);
|
||||
}
|
||||
o.add(Double.valueOf(date.get(3).toString()));
|
||||
|
||||
h.add(Double.valueOf(date.get(1).toString()));
|
||||
l.add(Double.valueOf(date.get(2).toString()));
|
||||
c.add(Double.valueOf(date.get(4).toString()));
|
||||
v.add(Long.valueOf(date.get(6).toString()));
|
||||
v.add(Double.valueOf(date.get(6).toString()));
|
||||
}
|
||||
result.setT(t);
|
||||
result.setO(o);
|
||||
@@ -387,7 +403,7 @@ public class RefinitivConsumer implements ApplicationRunner {
|
||||
.basicAuth(appKey,"")
|
||||
.execute();
|
||||
if(response.getStatus() != 200){
|
||||
throw new SysTipsException("获取token失败");
|
||||
return getNewToken();
|
||||
}
|
||||
JSONObject data = JSONObject.parseObject(response.body());
|
||||
data.put("expiry_tm",System.currentTimeMillis() + (Long.valueOf(data.get("expires_in").toString())-10));
|
||||
@@ -396,6 +412,27 @@ public class RefinitivConsumer implements ApplicationRunner {
|
||||
redisTemplate.expire("token",1, TimeUnit.DAYS);
|
||||
return toekn;
|
||||
}
|
||||
// HttpResponse response = HttpUtil.createPost(tokenUrl)
|
||||
// .form("username",tokenUsername)
|
||||
// .form("password",tokenPassword)
|
||||
// .form("grant_type","password")
|
||||
// .form("scope",SCOPE)
|
||||
// .form("takeExclusiveSignOnControl","true")
|
||||
// .header("Content-Type", "application/x-www-form-urlencoded")
|
||||
// .basicAuth(appKey,"")
|
||||
// .execute();
|
||||
// if(response.getStatus() != 200){
|
||||
// throw new SysTipsException("获取token失败");
|
||||
// }
|
||||
// JSONObject data = JSONObject.parseObject(response.body());
|
||||
// data.put("expiry_tm",System.currentTimeMillis() + (Long.valueOf(data.get("expires_in").toString())-10));
|
||||
// String toekn = data.toString();
|
||||
// redisTemplate.opsForValue().set("token",toekn);
|
||||
// redisTemplate.expire("token",1, TimeUnit.DAYS);
|
||||
return getNewToken();
|
||||
}
|
||||
|
||||
public String getNewToken(){
|
||||
HttpResponse response = HttpUtil.createPost(tokenUrl)
|
||||
.form("username",tokenUsername)
|
||||
.form("password",tokenPassword)
|
||||
|
||||
@@ -3,6 +3,7 @@ package cn.stock.market.web;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.stock.market.domain.basic.entity.RetifiveStock;
|
||||
import cn.stock.market.domain.basic.service.RetifiveStockService;
|
||||
import cn.stock.market.dto.RetifiveStockHistoryResponse;
|
||||
import cn.stock.market.dto.RetifiveStockInfo;
|
||||
import cn.stock.market.lesg.RefinitivConsumer;
|
||||
import cn.stock.market.listener.AppClient;
|
||||
@@ -133,7 +134,7 @@ public class RefinitivApiController {
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation(value = "查询股票K线", httpMethod = "GET", response = RetifiveStockInfo.class)
|
||||
@ApiOperation(value = "查询股票K线", httpMethod = "GET", response = RetifiveStockHistoryResponse.class)
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "symbol",value = "股票对应代码(symbol)",dataType ="String",required = true, paramType = "query"),
|
||||
@ApiImplicitParam(name = "symbol",value = "股票对应代码(symbol)",dataType ="String",required = true, paramType = "query"),
|
||||
|
||||
Reference in New Issue
Block a user