| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- namespace Easychart.Finance.DataProvider
- {
- using Easychart.Finance;
- using System;
- using System.Net;
- using System.Text;
- public class YahooDataManager : YahooCSVDataManager
- {
- public static string DownloadRealtimeFromYahoo(string Code, string Param)
- {
- string str = "";
- string str2 = Code.ToLower();
- Encoding encoding = Encoding.ASCII;
- byte[] bytes = FormulaHelper.DownloadData(string.Format("http://" + str + "finance.yahoo.com/d/quotes.csv?s=" + Code + "&f=" + Param, Code));
- return encoding.GetString(bytes);
- }
- public override IDataProvider GetData(string Code, int Count)
- {
- DateTime date;
- IDataProvider provider2;
- if (Count > 0x6815)
- {
- Count = 0x6815;
- date = new DateTime(0x78a, 1, 1);
- }
- else
- {
- date = DateTime.Now.AddDays((double) -Count).Date;
- }
- DateTime now = DateTime.Now;
- if (base.EndTime != DateTime.MinValue)
- {
- now = base.EndTime.AddDays(1.0);
- }
- if (base.StartTime != DateTime.MinValue)
- {
- date = base.StartTime;
- }
- string format = "http://table.finance.yahoo.com/table.csv?s={0}&a={1}&b={2}&c={3}&d={4}&e={5}&f={6}&g=d&ignore=.csv";
- string uRL = string.Format(format, new object[] { Code, date.Month - 1, date.Day, date.Year, now.Month - 1, now.Day, now.Year });
- try
- {
- byte[] data = FormulaHelper.DownloadData(uRL);
- CommonDataProvider cdp = base.LoadYahooCSV(data);
- this.SetStrings(cdp, Code);
- provider2 = cdp;
- }
- catch (WebException)
- {
- throw new Exception("Symbol " + Code + " not found!");
- }
- catch (Exception exception)
- {
- throw new Exception("Invalid data format!" + Code + ";" + exception.Message);
- }
- return provider2;
- }
- public static string[] GetStockName(string Code)
- {
- string[] strArray = new string[0];
- string str = DownloadRealtimeFromYahoo(Code, "snx");
- if (str != null)
- {
- strArray = str.Split(new char[] { ',' });
- for (int i = 0; i < 3; i++)
- {
- strArray[i] = strArray[i].Trim();
- if (strArray[i].Length > 2)
- {
- strArray[i] = strArray[i].Substring(1, strArray[i].Length - 2);
- strArray[i] = strArray[i].Trim();
- }
- }
- }
- return strArray;
- }
- public override void SetStrings(CommonDataProvider cdp, string Code)
- {
- cdp.SetStringData("Code", Code);
- }
- public static string TryDownloadRealtimeFromYahoo(string Code, string Param)
- {
- for (int i = 0; i < 5; i++)
- {
- try
- {
- return DownloadRealtimeFromYahoo(Code, Param);
- }
- catch
- {
- }
- }
- return null;
- }
- }
- }
|