给梦一个奔跑的方向!
PDF Print E-mail
User Rating: / 1
PoorBest 
Written by xlingfairy
Monday, 22 June 2009 16:01
 原本是想从 xe.com 里抓数据,但是找了半天没有看到有API提供。从网页里取出数据是可以,但是速度就要打折扣了。
 
在Google 上搜 Currency Conversion 无意之间搜出个 Yahoo 来:
 
http://download.finance.yahoo.com/d/quotes.csv?s=USDCNY=X&f=l1
http://download.finance.yahoo.com/d/quotes.txt?s=USDCNY=X&f=sl1c1abg
 
这是搜到的参数 f 的意思:
s - symbol; l1 - last price; c1 - change; d1 = last date
 
quotes.csv 可以是 quotes.txt 、quote 等
 
    public static float CurrencyConversion( string from, string to ) {
        try {
            HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("http://download.finance.yahoo.com/d/quotes?s=" + to.ToUpper() + from.ToUpper() + "=X&f=l1");
            HttpWebResponse rep = (HttpWebResponse)req.GetResponse();
 
            StreamReader sr = new StreamReader(rep.GetResponseStream());
            float rate = float.Parse(sr.ReadToEnd());
            return rate;
        } catch {
            return 1;
        }
    }
 

Add comment


Security code
Refresh

Popular Contents

Recommend

Site Info

Members : 1
Content : 143
Web Links : 7
Content View Hits : 113060

Links

 

Trace