Merge remote-tracking branch 'origin/develop' into develop
This commit is contained in:
114
src/main/java/cn/stock/market/infrastructure/api/TodayApis.java
Normal file
114
src/main/java/cn/stock/market/infrastructure/api/TodayApis.java
Normal file
@@ -0,0 +1,114 @@
|
||||
package cn.stock.market.infrastructure.api;
|
||||
|
||||
import cn.stock.market.utils.HttpClientRequest;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 数据来源网站:https://www.businesstoday.in/stocks
|
||||
*
|
||||
* @auther xiaoliuhu
|
||||
*/
|
||||
public class TodayApis {
|
||||
|
||||
static String get(String url) {
|
||||
return HttpClientRequest.doGet(url);
|
||||
}
|
||||
|
||||
//获取Top Gainers
|
||||
public static List<JSONObject> getTopGainers(String exchange){
|
||||
String url = "https://marketapi.intoday.in/widget/topgainer/view?exchange=" + exchange;
|
||||
//返回字符串对象格式:{"status_code":1,"success":true,"data":[{}],"message":"Successful","fromredis":true}
|
||||
String str = get(url);
|
||||
JSONObject object = JSON.parseObject(str);
|
||||
boolean bool = false;
|
||||
if(object.containsKey("success")){
|
||||
bool = object.getBoolean("success");
|
||||
}
|
||||
if(!bool){
|
||||
return null;
|
||||
}
|
||||
//进行数据转换
|
||||
List<JSONObject> dataObject = new ArrayList<>();
|
||||
JSONArray jsonArray = JSON.parseArray(object.getString("data"));
|
||||
for (Object obj : jsonArray){
|
||||
JSONObject entity = JSON.parseObject(obj.toString());
|
||||
dataObject.add(entity);
|
||||
}
|
||||
return dataObject;
|
||||
}
|
||||
//获取Top Losers
|
||||
public static List<JSONObject> getTopLosers(String exchange){
|
||||
String url = "https://marketapi.intoday.in/widget/toploser/view?exchange=" + exchange;
|
||||
//返回字符串对象格式:{"status_code":1,"success":true,"data":[{}],"message":"Successful","fromredis":true}
|
||||
String str = get(url);
|
||||
JSONObject object = JSON.parseObject(str);
|
||||
boolean bool = false;
|
||||
if(object.containsKey("success")){
|
||||
bool = object.getBoolean("success");
|
||||
}
|
||||
if(!bool){
|
||||
return null;
|
||||
}
|
||||
//进行数据转换
|
||||
List<JSONObject> dataObject = new ArrayList<>();
|
||||
JSONArray jsonArray = JSON.parseArray(object.getString("data"));
|
||||
for (Object obj : jsonArray){
|
||||
JSONObject entity = JSON.parseObject(obj.toString());
|
||||
dataObject.add(entity);
|
||||
}
|
||||
return dataObject;
|
||||
}
|
||||
//获取Most Active Volume
|
||||
public static List<JSONObject> getMostActiveVolume(String exchange){
|
||||
String url = "https://marketapi.intoday.in/widget/mostactivetopper/view?exchange=" + exchange;
|
||||
//返回字符串对象格式:{"status_code":1,"success":true,"data":[{}],"message":"Successful","fromredis":true}
|
||||
String str = get(url);
|
||||
JSONObject object = JSON.parseObject(str);
|
||||
boolean bool = false;
|
||||
if(object.containsKey("success")){
|
||||
bool = object.getBoolean("success");
|
||||
}
|
||||
if(!bool){
|
||||
return null;
|
||||
}
|
||||
//进行数据转换
|
||||
List<JSONObject> dataObject = new ArrayList<>();
|
||||
JSONArray jsonArray = JSON.parseArray(object.getString("data"));
|
||||
for (Object obj : jsonArray){
|
||||
JSONObject entity = JSON.parseObject(obj.toString());
|
||||
dataObject.add(entity);
|
||||
}
|
||||
return dataObject;
|
||||
}
|
||||
//获取Most Active Value
|
||||
public static List<JSONObject> getMostActiveValue(String exchange){
|
||||
String url = "https://marketapi.intoday.in/widget/mostactivetopperbyvalue/view?exchange=" + exchange;
|
||||
//返回字符串对象格式:{"status_code":1,"success":true,"data":[{}],"message":"Successful","fromredis":true}
|
||||
String str = get(url);
|
||||
JSONObject object = JSON.parseObject(str);
|
||||
boolean bool = false;
|
||||
if(object.containsKey("success")){
|
||||
bool = object.getBoolean("success");
|
||||
}
|
||||
if(!bool){
|
||||
return null;
|
||||
}
|
||||
//进行数据转换
|
||||
List<JSONObject> dataObject = new ArrayList<>();
|
||||
JSONArray jsonArray = JSON.parseArray(object.getString("data"));
|
||||
for (Object obj : jsonArray){
|
||||
JSONObject entity = JSON.parseObject(obj.toString());
|
||||
dataObject.add(entity);
|
||||
}
|
||||
return dataObject;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(getTopGainers("nse"));
|
||||
}
|
||||
}
|
||||
@@ -211,4 +211,10 @@ public class HttpClientRequest {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String url = "https://marketapi.intoday.in/widget/topgainer/view?exchange=nse";
|
||||
String str = doGet(url);
|
||||
System.out.println(str);
|
||||
}
|
||||
}
|
||||
|
||||
44
src/main/java/cn/stock/market/web/TodayApiController.java
Normal file
44
src/main/java/cn/stock/market/web/TodayApiController.java
Normal file
@@ -0,0 +1,44 @@
|
||||
package cn.stock.market.web;
|
||||
|
||||
import cn.stock.market.infrastructure.api.TodayApis;
|
||||
import cn.stock.market.utils.ServerResponse;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
@Controller
|
||||
@Api(value = "/TodayApiController", tags = "today股票行情")
|
||||
@RequestMapping({"/api/market/today/"})
|
||||
public class TodayApiController {
|
||||
|
||||
@RequestMapping({"getTopGainers.do"})
|
||||
@ApiOperation(value = "获取Top Gainers",notes = "exchange传nse或者bse", httpMethod = "GET")
|
||||
@ResponseBody
|
||||
public ServerResponse getTopGainers(@RequestParam("exchange") String exchange) {
|
||||
return ServerResponse.createBySuccess(TodayApis.getTopGainers(exchange));
|
||||
}
|
||||
|
||||
@RequestMapping({"getTopLosers.do"})
|
||||
@ApiOperation(value = "获取 Top Losers",notes = "exchange传nse或者bse", httpMethod = "GET")
|
||||
@ResponseBody
|
||||
public ServerResponse getTopLosers(@RequestParam("exchange") String exchange) {
|
||||
return ServerResponse.createBySuccess(TodayApis.getTopLosers(exchange));
|
||||
}
|
||||
|
||||
@RequestMapping({"getMostActiveVolume.do"})
|
||||
@ApiOperation(value = "获取 Most Active Volume",notes = "exchange传nse或者bse", httpMethod = "GET")
|
||||
@ResponseBody
|
||||
public ServerResponse getMostActiveVolume(@RequestParam("exchange") String exchange) {
|
||||
return ServerResponse.createBySuccess(TodayApis.getMostActiveVolume(exchange));
|
||||
}
|
||||
|
||||
@RequestMapping({"getMostActiveValue.do"})
|
||||
@ApiOperation(value = "获取 Most Active Value",notes = "exchange传nse或者bse",httpMethod = "GET")
|
||||
@ResponseBody
|
||||
public ServerResponse getMostActiveValue(@RequestParam("exchange") String exchange) {
|
||||
return ServerResponse.createBySuccess(TodayApis.getMostActiveValue(exchange));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user