| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226 |
- 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;
- }
- }
- }
- }
|