大家好,又见面了,我是你们的朋友全栈君。
实时股票数据接口
腾讯股票接口、和讯网股票接口、新浪股票接口、雪球股票数据、网易股票数据
http://money.finance.sina.com.cn/quotes_service/api/json_v2.php/CN_MarketData.getKLineData?symbol=sz000001&scale=5&ma=5&datalen=1023
(参数:股票编号、分钟间隔(5、15、30、60)、均值(5、10、15、20、25)、查询个数点(最大值242))
public class HistoryModel { public String day; public String close; public HistoryModel(String day, String close) { this.day = day; this.close = close; } }
public class HistoryModels { public String name; public String code; public String now; public List<HistoryModel> list; public HistoryModels(String name, String code, String now, List<HistoryModel> list) { this.name = name; this.code = code; this.now = now; this.list = list; } }
3、将需要查询的股票的代码带进url里通过HTTP请求json数据,我这里用的Volley请求的:
// Instantiate the RequestQueue. RequestQueue queue = Volley.newRequestQueue(Home.context); String url1 = "http://money.finance.sina.com.cn/quotes_service/api/json_v2.php/CN_MarketData.getKLineData?symbol=" + Home.myChoiceModelList.get(ii).code + "&scale=60&ma=no&datalen=1023"; // Request a string response from the provided URL. StringRequest stringRequest1 = new StringRequest(Request.Method.GET, url1, new Response.Listener<String>() { @Override public void onResponse(String response) { List<HistoryModel> historyList = Convert(response,new TypeToken<List<HistoryModel>>() { }.getType()); List<HistoryModel> historyList2 = new ArrayList<>(); if(historyList!=null) { for (int j = 0; j < historyList.size(); j++) { if (historyList.get(j).day.split(" ")[1].equals("15:00:00")) { historyList2.add(historyList.get(j)); } } } HistoryModels model = new HistoryModels(Home.myChoiceModelList.get(ii).name, Home.myChoiceModelList.get(ii).code, Home.myChoiceModelList.get(ii).now, historyList2); cllList.add(model); Message msg = new Message(); msg.what = 0x002; handler.sendMessage(msg); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { } }); queue.add(stringRequest1);
/* * Json转换泛型 */ public static <T> T Convert(String jsonString, Type cls) { T t = null; try { if (jsonString != null && !jsonString.equals("")) { Gson gson = new Gson(); t = gson.fromJson(jsonString, cls); } } catch (Exception e) { e.printStackTrace(); } return t; }
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/152678.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...