Topic: java程序查股票价格

  Print this page

1.java程序查股票价格 Copy to clipboard
Posted by: helloworld
Posted on: 2003-08-31 16:07

// 转贴
import java.io.*;
import java.net.*;
public class Stock {

public static void main(String a[]) throws Exception {
if (a.length!=1) {
System.out.println("usage: java Stock <symbol> ");
System.exit(0);
}

String yahoo = "finance.yahoo.com";
final int httpd = 80;
Socket sock = new Socket(yahoo, httpd);

BufferedWriter out =
new BufferedWriter( new OutputStreamWriter( sock.getOutputStream() ) );

String cmd = "GET /q?" +"s=" +a[0] +"\n";
out.write(cmd);
out.flush();

   BufferedReader in =new BufferedReader(
    new InputStreamReader( sock.getInputStream() ) );
   String s=null;
int i, j;
   // pick out the stock price from the pile of HTML
   // it抯 in bold, so get the number following "<b>"
while ( (s=in.readLine()) != null) {
if (s.length()<25) continue;
if ((i=s.indexOf(a[0].toUpperCase())) < 0) continue;
s=s.substring(i);
if ((i=s.indexOf("<b>")) < 0) continue;
j = s.indexOf("</b>");
s=s.substring(i+3,j);
System.out.println(a[0] +" is at "+s);
break;
}
}
}

股票缩写查询: http://investor.stockpoint.com/IndustryListMG.asp?IndustryCode=SOFTWR

使用方法:

java Stock ibm
java Stock beas
java Stock orcl
java Stock msft
java Stock sunw // :-(

2.Re:java程序查股票价格 [Re: helloworld] Copy to clipboard
Posted by: ftang
Posted on: 2003-09-01 09:59

敢问作者,我是否能将原代码下载,编译上传/转载到JAVATOOKIT单元,如可以,请回贴

3.Re:java程序查股票价格 [Re: helloworld] Copy to clipboard
Posted by: floater
Posted on: 2003-09-01 11:45

use http to pass firewall.

4.Re:java程序查股票价格 [Re: floater] Copy to clipboard
Posted by: nothing
Posted on: 2003-09-01 12:37

是<<just java 2>>中第17章中的例子.

5.Re:java程序查股票价格 [Re: helloworld] Copy to clipboard
Posted by: floater
Posted on: 2003-09-02 01:46

no wonder it's not for practical usage, just for illustration.

6.Re:java程序查股票价格 [Re: helloworld] Copy to clipboard
Posted by: helloworld
Posted on: 2003-09-02 07:34

是的,是书上的例子.

7.Re:java程序查股票价格 [Re: nothing] Copy to clipboard
Posted by: jameszhang
Posted on: 2003-09-02 08:26

nothing wrote:
是<<just java 2>>中第17章中的例子.

GG,哈哈....................,我太崇拜你了,Big SmileBig SmileCoolCoolTongueTongue

8.Re:java程序查股票价格 [Re: helloworld] Copy to clipboard
Posted by: yb79528
Posted on: 2003-09-03 09:41

能否写个读国内A股行情的java程序出来?

9.Re:java程序查股票价格 [Re: helloworld] Copy to clipboard
Posted by: jfml
Posted on: 2003-09-03 13:25

关注啊

呵呵

10.Re:java程序查股票价格 [Re: helloworld] Copy to clipboard
Posted by: floater
Posted on: 2003-09-04 01:27

You can get what you get from browsers, no more. So if there is a chinese site where you can get the quotes from, then use http connection to get the data from there.

11.Re:java程序查股票价格 [Re: helloworld] Copy to clipboard
Posted by: ftang
Posted on: 2003-09-04 10:52

floater, 问一下,你们公司是用哪一家公司的MARKET DATA SERVICE的啊, 我们是用的THOMASON FINANCE的叫ILX,全SOCKET的,但是我看好像REDI的也不错,http的quote不行,没法支持streamer类型的application, 我做的一个MARKET DATA SERICE, 结构还不是很好,有机会请你帮忙看一下

12.Re:java程序查股票价格 [Re: helloworld] Copy to clipboard
Posted by: floater
Posted on: 2003-09-04 23:01

I am not sure, although I think it's directly from exchanges since we were part of NY exchange.

I think the connection is determined by the data provider/protocol.

http is good to pass firewalls, but the only http quote I know is from yahoo and it's end-of-day. The return is just a table, easy to parse the data.

I don't have a chance to work on streamers, but I would imagine streamers, like quote.com or others are different, they are more like a broadcast thing, even a loss of a pack is tolerant sometimes. But again, no real experience. It's one of a kind application, very interesting.

13.Re:java程序查股票价格 [Re: helloworld] Copy to clipboard
Posted by: hwx
Posted on: 2003-09-06 18:08

This example cannot fetch the stock price now.
Yahoo just changed its html layout, so the program needs modification
to get the correct stock price result.

14.Re:java程序查股票价格 [Re: helloworld] Copy to clipboard
Posted by: floater
Posted on: 2003-09-06 23:30

Yea, looks like they change it. So we need to modify the url.

15.Re:java程序查股票价格 [Re: helloworld] Copy to clipboard
Posted by: floater
Posted on: 2003-09-06 23:34

Use the following url, it's still working(after 5 years)

public String getURL(KeyPairs quoteParams)
{
String startDate = quoteParams.getStringValue(START_DATE, "");
String endDate = quoteParams.getStringValue(END_DATE, "");
String stockSymbol = quoteParams.getStringValue(STOCK_SYMBOL, "");
String scale = quoteParams.getStringValue(TIME_INTERVAL, "d"); //default to daily

if (!checkDateFormat(startDate) || !checkDateFormat(endDate))
{
return WRONG_DATE_FORMAT;
}
StringTokenizer ssDate = new StringTokenizer(startDate, "/");
StringTokenizer seDate = new StringTokenizer(endDate, "/");
String sMonth = ssDate.nextToken();
String sDay = ssDate.nextToken();
String sYear = ssDate.nextToken();
String eMonth = seDate.nextToken();
String eDay = seDate.nextToken();
String eYear = seDate.nextToken();

String returnURL = new String("http://chart.yahoo.com/");
returnURL += "table.csv?&s=" + stockSymbol;
returnURL += "&a=" + sMonth + "&b=" + sDay + "&c=" + sYear;
returnURL += "&d=" + eMonth + "&e=" + eDay + "&f=" + eYear;
returnURL += "&g=" + scale + "&q=q&y=0&z=" + stockSymbol + "&x=.csv";

return returnURL;

}

16.Re:java程序查股票价格 [Re: helloworld] Copy to clipboard
Posted by: bbbaby
Posted on: 2003-09-08 18:16

good, studying...


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923