namespace Easychart.Finance.DataClient { using Easychart.Finance; using Easychart.Finance.DataProvider; using System; using System.Collections; using System.Runtime.CompilerServices; using System.Text.RegularExpressions; using System.Threading; public class YahooDataClient : DataClientBase { public event DataProgress OnProgress; public event StreamingDataChanged OnStreamingData; public event EventHandler OnStreamingStopped; public override void DownloadStreaming() { try { while (true) { foreach (DataPacket packet in DataPacket.DownloadMultiFromYahoo(base.GetStreamingSymbol(","))) { if ((packet != null) && !packet.IsZeroValue) { if (base.UtcStreamingTime) { packet.Date = packet.Date.Date + packet.Date.AddHours(-packet.TimeZone).TimeOfDay; } if (this.OnStreamingData != null) { this.OnStreamingData(this, packet); } } } Thread.Sleep(0x1388); } } finally { if (this.OnStreamingStopped != null) { this.OnStreamingStopped(this, new EventArgs()); } } } public override CommonDataProvider GetData(string symbols, DataCycle dataCycle, DateTime startTime, DateTime endTime) { string format = "http://table.finance.yahoo.com/table.csv?s={0}&d={4}&e={5}&f={6}&g=d&a={1}&b={2}&c={3}&ignore=.csv"; string uRL = string.Format(format, new object[] { symbols, startTime.Month - 1, startTime.Day, startTime.Year, endTime.Month - 1, endTime.Day, endTime.Year }); byte[] data = base.DownloadBinary(symbols, uRL); return new YahooCSVDataManager().LoadYahooCSV(data); } public override DataPacket[] GetEodData(string Exchanges, string[] symbols, DateTime time) { string format = "http://table.finance.yahoo.com/table.csv?s={0}&d={4}&e={5}&f={6}&g=d&a={1}&b={2}&c={3}&ignore=.csv"; DataPacket[] packetArray = new DataPacket[symbols.Length]; DateTime time2 = time.AddDays(-1.0); for (int i = 0; i < symbols.Length; i++) { string symbol = symbols[i]; string uRL = string.Format(format, new object[] { symbol, time2.Month - 1, time2.Day, time2.Year, time.Month - 1, time.Day, time.Year }); byte[] data = base.DownloadBinary(symbol, uRL); packetArray[i] = new YahooCSVDataManager().LoadYahooCSV(data).GetLastPackage(); if (this.OnProgress != null) { this.OnProgress(this, new DataProgressArgs(symbol, i, symbols.Length)); } } return packetArray; } public override string[] GetMarket() { return new string[] { "US=U.S. & Canada", "=World Markets" }; } public override string[] GetStockType() { return new string[] { "S=Stocks", "E=ETF", "I=Indices", "M=Mutual Fund", "O=Options" }; } public override string[] LookupSymbols(string Key, string Exchanges, string StockType, string Market) { if (StockType == null) { StockType = ""; } if (Market == null) { Market = ""; } MatchCollection matchs = Regex.Matches(base.DownloadString("http://finance.yahoo.com/l?s=" + Key + "&t=" + StockType + "&m=" + Market), "