我想对股票发出RSI警报。
这是Alpha Vantage API响应我的请求的数据。每当我运行代码时,我都想提取最新的RSI。
在这种情况下,它是77.0835。由于日期和时间(即2020-01-24 14:30)不断变化,请问有什么方法可以获取最新的RSI?
摘录自Alpha Vantage的回复:
public void getRepo() {
Json reporte = new Json("{\"template\":{\"shortid\":\"ytyg1Ho\"},\"data\":null}");
List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>();
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
/* MENSAGE CONVERTER */
messageConverters.add(new ByteArrayHttpMessageConverter());
converter.setSupportedMediaTypes(Collections.singletonList(MediaType.ALL));
messageConverters.add(converter);
RestTemplate restTemplate = new RestTemplate(messageConverters);
// REQUEST
HttpEntity<Object> entity = new HttpEntity<>(reporte, this.getHeaders());
/* RESPONSE */
try {
byte[] response = restTemplate.postForObject(base_url, entity, byte[].class);
System.out.println("Response "+new String(response));
}catch (Exception e) {
System.out.println(e.getMessage() +" "+ e);
}
答案 0 :(得分:2)
怎么样?
data = {
"Meta Data": {
"1: Symbol": "tlt",
"2: Indicator": "Relative Strength Index (RSI)",
"3: Last Refreshed": "2020-01-24 14:30:46",
"4: Interval": "60min",
"5: Time Period": 14,
"6: Series Type": "close",
"7: Time Zone": "US/Eastern Time"
},
"Technical Analysis: RSI": {
"2020-01-24 14:30": {
"RSI": "77.0835"
},
"2020-01-24 13:30": {
"RSI": "78.0121"
},
"2020-01-24 12:30": {
"RSI": "75.8201"
},
"2020-01-24 11:30": {
"RSI": "75.7447"
},
"2020-01-24 10:30": {
"RSI": "73.9965"
},
"2020-01-24 09:30": {
"RSI": "73.8768"
}
}
}
most_recent_rsi = data['Technical Analysis: RSI'][sorted(data['Technical Analysis: RSI'])[-1]]