继续优化代码
This commit is contained in:
14
src/main/java/cn/stock/market/dto/StockHistoryRequest.java
Normal file
14
src/main/java/cn/stock/market/dto/StockHistoryRequest.java
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
package cn.stock.market.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class StockHistoryRequest {
|
||||||
|
private String symbol;
|
||||||
|
private String resolution;
|
||||||
|
private long from;
|
||||||
|
private long to;
|
||||||
|
private int countback;
|
||||||
|
private String currencyCode;
|
||||||
|
|
||||||
|
}
|
||||||
17
src/main/java/cn/stock/market/dto/StockHistoryResponse.java
Normal file
17
src/main/java/cn/stock/market/dto/StockHistoryResponse.java
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package cn.stock.market.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class StockHistoryResponse {
|
||||||
|
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<Long> v;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -3,6 +3,8 @@ package cn.stock.market.web;
|
|||||||
import cn.stock.market.MoneyStockSuggestDTO;
|
import cn.stock.market.MoneyStockSuggestDTO;
|
||||||
import cn.stock.market.domain.basic.entity.MoneyStock;
|
import cn.stock.market.domain.basic.entity.MoneyStock;
|
||||||
import cn.stock.market.domain.basic.repository.MoneyStockRepository;
|
import cn.stock.market.domain.basic.repository.MoneyStockRepository;
|
||||||
|
import cn.stock.market.dto.StockHistoryRequest;
|
||||||
|
import cn.stock.market.dto.StockHistoryResponse;
|
||||||
import cn.stock.market.infrastructure.db.po.QMoneyStockPO;
|
import cn.stock.market.infrastructure.db.po.QMoneyStockPO;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
@@ -49,6 +51,9 @@ public class MoneyApiController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private MoneyStockRepository moneyStockRepository;
|
private MoneyStockRepository moneyStockRepository;
|
||||||
|
|
||||||
|
private static final String EXTERNAL_API_URL = "https://priceapi.moneycontrol.com/techCharts/indianMarket/stock/history";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ApiOperation(value = "股票详情信息",httpMethod = "GET")
|
@ApiOperation(value = "股票详情信息",httpMethod = "GET")
|
||||||
@ApiImplicitParams({
|
@ApiImplicitParams({
|
||||||
@@ -576,6 +581,50 @@ public class MoneyApiController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@GetMapping("/api/market/money/history/kLine")
|
||||||
|
@ApiOperation(value = "获取kline的money数据源", notes = "获取kline的money数据源",response = StockHistoryResponse.class)
|
||||||
|
@ApiImplicitParams({
|
||||||
|
@ApiImplicitParam(name = "symbol", value = "Stock symbol", required = true, dataType = "String", paramType = "query"),
|
||||||
|
@ApiImplicitParam(name = "resolution", value = "Resolution", required = true, dataType = "String", paramType = "query"),
|
||||||
|
@ApiImplicitParam(name = "from", value = "Start timestamp", required = true, dataType = "long", paramType = "query"),
|
||||||
|
@ApiImplicitParam(name = "to", value = "End timestamp", required = true, dataType = "long", paramType = "query"),
|
||||||
|
@ApiImplicitParam(name = "countback", value = "Countback", required = true, dataType = "int", paramType = "query"),
|
||||||
|
@ApiImplicitParam(name = "currencyCode", value = "Currency code", required = true, dataType = "String", paramType = "query")
|
||||||
|
})
|
||||||
|
@ResponseBody
|
||||||
|
public ResponseEntity<StockHistoryResponse> getStockHistory( @RequestParam String symbol,
|
||||||
|
@RequestParam String resolution,
|
||||||
|
@RequestParam long from,
|
||||||
|
@RequestParam long to,
|
||||||
|
@RequestParam int countback,
|
||||||
|
@RequestParam String currencyCode) {
|
||||||
|
// 创建一个RestTemplate实例
|
||||||
|
RestTemplate restTemplate = new RestTemplate();
|
||||||
|
// 向外部API发起请求,并获取响应
|
||||||
|
StockHistoryRequest request = new StockHistoryRequest();
|
||||||
|
request.setSymbol(symbol);
|
||||||
|
request.setResolution(resolution);
|
||||||
|
request.setFrom(from);
|
||||||
|
request.setTo(to);
|
||||||
|
request.setCountback(countback);
|
||||||
|
request.setCurrencyCode(currencyCode);
|
||||||
|
String apiUrl = buildApiUrl(request);
|
||||||
|
StockHistoryResponse response = restTemplate.getForObject(apiUrl, StockHistoryResponse.class);
|
||||||
|
|
||||||
|
// 返回响应
|
||||||
|
return ResponseEntity.ok(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private String buildApiUrl(StockHistoryRequest request) {
|
||||||
|
// 构建外部API的URL
|
||||||
|
return String.format("%s?symbol=%s&resolution=%s&from=%d&to=%d&countback=%d¤cyCode=%s",
|
||||||
|
EXTERNAL_API_URL, request.getSymbol(), request.getResolution(), request.getFrom(),
|
||||||
|
request.getTo(), request.getCountback(), request.getCurrencyCode());
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
private static String extractLastSegment(String url) {
|
private static String extractLastSegment(String url) {
|
||||||
if (url == null) {
|
if (url == null) {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
Reference in New Issue
Block a user