namespace Easychart.Finance.DataClient { using Easychart.Finance; using Easychart.Finance.DataProvider; using System; using System.Globalization; using System.IO; using System.Net; using System.Runtime.CompilerServices; using System.Text; public class EasyChartDataClient : DataClientBase { public event EventHandler OnFinished; public event DataProgress OnProgress; public event StreamingDataChanged OnStreamingData; public event EventHandler OnStreamingStopped; public EasyChartDataClient() { this.OnFinished = (EventHandler) Delegate.Remove(this.OnFinished, null); this.OnProgress = (DataProgress) Delegate.Remove(this.OnProgress, null); } public override void DownloadStreaming() { try { string str2; HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://data.easychart.net/streaming.aspx?Symbols=" + base.GetStreamingSymbol(";")); if ((base.Proxy != null) && (base.Proxy != "")) { request.Proxy = new WebProxy(base.Proxy); } request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)"; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.ASCII); Label_007A: str2 = reader.ReadLine(); if (str2 != null) { string[] strArray = str2.Split(new char[] { ';' }); if (this.OnStreamingData != null) { IFormatProvider uSFormat = FormulaHelper.USFormat; DataPacket dp = new DataPacket(strArray[0], DateTime.Parse(strArray[1], DateTimeFormatInfo.InvariantInfo), (double) float.Parse(strArray[2], uSFormat), double.Parse(strArray[3], uSFormat)); dp.TimeZone = double.MaxValue; this.OnStreamingData(this, dp); } goto Label_007A; } } catch (Exception exception) { base.LastError = exception; } finally { if (this.OnStreamingStopped != null) { this.OnStreamingStopped(this, new EventArgs()); } } } public override CommonDataProvider GetData(string symbols, DataCycle dataCycle, DateTime startTime, DateTime endTime) { byte[] bs = base.DownloadBinary(symbols, "http://subscribe.easychart.net/member/datafeed.aspx?f=BinaryHistory&AddWhenNoSymbol=1&Symbol=" + symbols); if (bs != null) { CommonDataProvider provider = new CommonDataProvider(null); provider.LoadByteBinary(bs); provider.SetStringData("Code", symbols.ToUpper()); return provider; } return null; } public override DataPacket[] GetEodData(string Exchanges, string[] symbols, DateTime Time) { string str = base.DownloadString("http://subscribe.easychart.net/member/datafeed.aspx?f=EndOfDay&Exchanges=" + Exchanges + "&Date=" + Time.ToString("yyyy-MM-dd")); if ((str != null) && (str != "")) { string[] strArray = str.Trim().Split(new char[] { '\r' }); DataPacket[] packetArray = new DataPacket[strArray.Length]; for (int i = 0; i < packetArray.Length; i++) { packetArray[i] = DataPacket.ParseEODData(strArray[i].Trim()); } return packetArray; } return base.GetEodData(Exchanges, symbols, Time); } public override string[] GetExchanges() { return new string[] { "AMEX;Nasdaq;Nyse;^=All US & Index", "AMEX;Nasdaq;Nyse=All US", "AMEX", "Nasdaq", "Nyse", "OTC+BB=OTC BB", "Shanghai", "Shenzhen", "TOR;CDNX=Canada", "TOR=Toronto", "CDNX=Vancouver", "ASX", "^=Global Indices" }; } public override string[] GetIndustry() { string str = base.DownloadString("http://data.easychart.net/Industry.aspx"); if (str != null) { return str.Split(new char[] { '\r' }); } return base.GetIndustry(); } public override bool Login(string Username, string Password) { base.Ticket = base.DownloadString("http://subscribe.easychart.net/GetTicket.aspx?UserId=" + Username + "&Password=" + Password); return ((base.Ticket != null) && (base.Ticket != "")); } public override string[] LookupSymbols(string Key, string Exchanges, string StockType, string Market) { if (base.Logined) { string str = base.DownloadString("http://subscribe.easychart.net/member/datafeed.aspx?f=SymbolList&Exchanges=" + Exchanges); if (str != null) { return str.Trim().Split(new char[] { '\r' }); } } return null; } public override void StopDownload() { base.Canceled = true; } public override string DataFeedName { get { return "Easy Chart Demo Data Feed"; } } public override string Description { get { return "This is a free data feed, provided by http://finance.easychart.net."; } } public override string HomePage { get { return "http://finance.easychart.net"; } } public override bool IsFree { get { return true; } } public override string LoginURL { get { return "http://subscribe.easychart.net/login.aspx"; } } public override string RegURL { get { return "http://subscribe.easychart.net/reg.aspx"; } } public override bool SupportEod { get { return true; } } public override bool SupportIndustry { get { return true; } } public override bool SupportIntraday { get { return false; } } public override bool SupportStreaming { get { return true; } } public override bool SupportSymbolList { get { return true; } } } }