Anda di halaman 1dari 5

Yahoo have an (undocumented) Stock Quotes API as part of their Finance API Basically,

s=GOOG&f=ll will retur n the price for GOOG stock in CVS format,v,c1,a2,x The s parameter is the stock symbol. You can specify multiple by separating them with + quotes.csv?s=GOOG+YHOO? where some special tags are (thanks to Mike): a Ask a2 Average Daily Volume a5 Ask Size b Bid b2 Ask (Real-time) b3 Bid (Real-time) b4 Book Value b6 Bid Size c Change & Percent Change c1 Change c3 Commission c6 Change (Real-time) c8 After Hours Change (Real-time) d Dividend/Share d1 Last Trade Date d2 Trade Date e Earnings/Share e1 Error Indication (returned for symbol changed / invalid) e7 EPS Estimate Current Year e8 EPS Estimate Next Year e9 EPS Estimate Next Quarter f6 Float Shares g Day's Low h Day's High j 52-week Low k 52-week High g1 Holdings Gain Percent g3 Annualized Gain g4 Holdings Gain g5 Holdings Gain Percent (Real-time) g6 Holdings Gain (Real-time) i More Info i5 Order Book (Real-time) j1 Market Capitalization j3 Market Cap (Real-time) j4 EBITDA j5 Change From 52-week Low j6 Percent Change From 52-week Low k1 Last Trade (Real-time) With Time k2 Change Percent (Real-time) k3 Last Trade Size k4 Change From 52-week High k5 Percebt Change From 52-week High l Last Trade (With Time) l1 Last Trade (Price Only) l2 High Limit l3 Low Limit

m m2 m3 m4 m5 m6 m7 m8 n n4 o p p1 p2 p5 p6 q r r1 r2 r5 r6 r7 s s1 s7 t1 t6 t7 t8 v v1 v7 w w1 w4 x y

Day's Range Day's Range (Real-time) 50-day Moving Average 200-day Moving Average Change From 200-day Moving Average Percent Change From 200-day Moving Average Change From 50-day Moving Average Percent Change From 50-day Moving Average Name Notes Open Previous Close Price Paid Change in Percent Price/Sales Price/Book Ex-Dividend Date P/E Ratio Dividend Pay Date P/E Ratio (Real-time) PEG Ratio Price/EPS Estimate Current Year Price/EPS Estimate Next Year Symbol Shares Owned Short Ratio Last Trade Time Trade Links Ticker Trend 1 yr Target Price Volume Holdings Value Holdings Value (Real-time) 52-week Range Day's Value Change Day's Value Change (Real-time) Stock Exchange Dividend Yield

The f parameter is the data format code, which I found documented from this Pyth on script (which is also how I discovered the API..): code l1 c1 v a2 x j1 b4 j4 d y e k j m3 m4 r description price change volume avg_daily_volume stock_exchange market_cap book_value ebitda dividend_per_share dividend_yield earnings_per_share 52_week_high 52_week_low 50day_moving_avg 200day_moving_avg price_earnings_ratio

r5 p5 p6 s7

price_earnings_growth_ratio price_sales_ratio price_book_ratio short_ratio,c1,v,a2,x,j1,b4,j4,d,y,e,k,j,m3,m 4,r,r5,p5,p6,s7 "RCOM.BO","REL COM LTD",145.10,"12/31/2010","5:29am",140.10,143.25,139.80,0.00,1 0.00

import import import import import import import import import import;;;;;;;;;;

public class HTTPRequestPoster { /** * Sends an HTTP GET request to a url * * @param endpoint - The URL of the server. (Example: " ch") * @param requestParameters - all the request parameters (Example: "param1=val1&p aram2=val2"). Note: This method will add the question mark (?) to the request DO NOT add it yourself * @return - The response from the end point */ public static String sendGetRequest(String endpoint, String requestParameters) { String result = null; if (endpoint.startsWith("http://")) { // Send a GET request to the servlet try { // Construct data StringBuffer data = new StringBuffer(); // Send data String urlStr = endpoint; if (requestParameters != null && requestParameters.length () > 0) { urlStr += "?" + requestParameters; } URL url = new URL(urlStr); URLConnection conn = url.openConnection (); // Get the response

BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream ())); StringBuffer sb = new StringBuffer(); String line; while ((line = rd.readLine()) != null) { sb.append(line); } rd.close(); result = sb.toString(); } catch (Exception e) { e.printStackTrace(); } } return result; } /** * Reads data from the data reader and posts it to a server via POST request. * data - The data you want to send * endpoint - The server's address * output - writes the server's response to output * @throws Exception */ public static void postData(Reader data, URL endpoint, Writer output) throws Exc eption { HttpURLConnection urlc = null; try { urlc = (HttpURLConnection) endpoint.openConnection(); try { urlc.setRequestMethod("POST"); } catch (ProtocolException e) { throw new Exception("Shouldn't happen: HttpURLConnection doesn't support POST??" , e); } urlc.setDoOutput(true); urlc.setDoInput(true); urlc.setUseCaches(false); urlc.setAllowUserInteraction(false); urlc.setRequestProperty("Content-type", "text/xml; charset=" + "UTF-8"); OutputStream out = urlc.getOutputStream(); try { Writer writer = new OutputStreamWriter(out, "UTF-8"); pipe(data, writer); writer.close(); } catch (IOException e) { throw new Exception("IOException while posting data", e); } finally { if (out != null) out.close();

} InputStream in = urlc.getInputStream(); try { Reader reader = new InputStreamReader(in); pipe(reader, output); reader.close(); } catch (IOException e) { throw new Exception("IOException while reading response", e); } finally { if (in != null) in.close(); } } catch (IOException e) { throw new Exception("Connection error (is server running at " + endpoint + " ?): " + e); } finally { if (urlc != null) urlc.disconnect(); } } /** * Pipes everything from the reader to the writer via a buffer */ private static void pipe(Reader reader, Writer writer) throws IOException { char[] buf = new char[1024]; int read = 0; while ((read = >= 0) { writer.write(buf, 0, read); } writer.flush(); } }