获取连续n天上涨,上涨幅度大于某值得股票

获取连续n天上涨,上涨幅度大于某值得股票

/**
	 * 获取连续n天上涨,上涨幅度大于某值得股票
	 * 
	 * @return
	 */
	public static String gatherNdaysPositive(int n, double fudu) {
		// 获取股票代码表
		BufferedReader br = null;
		String filePath = "./data/code.csv";
		StringBuffer bf = new StringBuffer();
		try {
			// br = new BufferedReader(new FileReader(filePath));
			br = new BufferedReader(new InputStreamReader(new FileInputStream(filePath), Charset.forName("GBK")));
			// 读取的每一行
			String line = "";
			// 临时保存切分的每一行
			String[] temp = null;
			// 读取每一行
			int k = 0;
			while ((line = br.readLine()) != null) {
				temp = line.split(",");
				String[][] data = getLatestInfoJson(n, temp[0]);
				if (data != null) {
					boolean flag = MathUtil.continuePositive(data);
					if (flag) {
						double nzhangfu = MathUtil.nzhangfu(data);
						if (nzhangfu > fudu
								&& (temp[0].startsWith("0") || temp[1].startsWith("6") || temp[0].startsWith("7"))) {
							bf.append(k + ". " + "股票名称:" + temp[2] + "\t" + "股票代码: " + temp[0] + "\t" + "股票价格: " + data[0][1]
									+ "\t    " + n + "日涨幅:" + nzhangfu + "\n");
							// 获取股票基本信息
							Map map = basicInfo(temp[0]);
							bf.append(map.toString() + "\n");
							k = k +1;
						}
					} else {
						continue;
					}
				} else {
					continue;
				}

			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		return bf.toString();
	}

/**
	 * 获取最近n天的数据 n < 30
	 * 
	 * @param n
	 * @param stockCode
	 * @return
	 */
	public static String[][] getLatestInfoJson(int n, String stockCode) {
		String start = DateUtil.getNowDate();
		// 首先获取30天数据
		String end = DateUtil.getNDaysBefore(10);

		String url = "http://q.stock.sohu.com/hisHq?code=cn_" + stockCode + "&start=" + end + "&end=" + start
				+ "&stat=1&order=D&period=d&callback=historySearchHandler&rt=jsonp";
		String stock = HttpUtil.HttpClientGet(url);

		// 没有数据直接返回
		if (!stock.contains("hq")) {
			return null;
		}

		stock = stock.substring(stock.indexOf("[[") + 2, stock.lastIndexOf("]]"));

		stock = stock.replace("\"", "");
		stock = stock.replace("],[", "##");
		String[] infoA = stock.split("##");

		if (n > infoA.length) {
			return null;
		}

		String[][] infoB = new String[n][10];
		// 开盘
		// 收盘
		// 涨跌额
		// 涨跌幅
		// 最低
		// 最高
		// 成交量(手)
		// 成交额(万元)
		// 换手率

		// 保留n天数据
		for (int i = 0; i < infoB.length; i++) {
			infoB[i] = infoA[i].split(",");
		}

		return infoB;
	}

你可能感兴趣的:(通用网络技术)