今天要寫service、serviceImpl兩個部分,
(1)第一部分,service新增oneMinKbar方法
public interface ShioajiService {
public String test(String tickdate) throws Exception;
public String oneMinKbar(String start_date,String end_date, String stock_code) throws Exception;
}
(2)第2部分,serviceImpl新增oneMinKbar方法,
帶入3個參數開始時間、結束時間、股票代碼來呼叫python api
public String oneMinKbar(String start_date,String end_date, String stock_code) {
log.info(" excute oneMinKbar time is {}", dateFormat.format(new Date()));
String data = "";
RestTemplate restTemplate = new RestTemplate();
HttpEntity<String> entity = new HttpEntity<>("");
try {
ResponseEntity<String> getTick =
restTemplate.exchange(
apiUrl+"kbars?date_start="+start_date+"&date_end="+end_date+"&stock_code="+stock_code,
HttpMethod.GET,
entity,
new ParameterizedTypeReference<String>() {});
data = getTick.getBody();
}catch(Exception ex) {
log.error(ex.getMessage(),ex);
throw ex;
}
return data;
}
明天要繼續寫controller的部分!