EasyChartDataClient.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. namespace Easychart.Finance.DataClient
  2. {
  3. using Easychart.Finance;
  4. using Easychart.Finance.DataProvider;
  5. using System;
  6. using System.Globalization;
  7. using System.IO;
  8. using System.Net;
  9. using System.Runtime.CompilerServices;
  10. using System.Text;
  11. public class EasyChartDataClient : DataClientBase
  12. {
  13. public event EventHandler OnFinished;
  14. public event DataProgress OnProgress;
  15. public event StreamingDataChanged OnStreamingData;
  16. public event EventHandler OnStreamingStopped;
  17. public EasyChartDataClient()
  18. {
  19. this.OnFinished = (EventHandler) Delegate.Remove(this.OnFinished, null);
  20. this.OnProgress = (DataProgress) Delegate.Remove(this.OnProgress, null);
  21. }
  22. public override void DownloadStreaming()
  23. {
  24. try
  25. {
  26. string str2;
  27. HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://data.easychart.net/streaming.aspx?Symbols=" + base.GetStreamingSymbol(";"));
  28. if ((base.Proxy != null) && (base.Proxy != ""))
  29. {
  30. request.Proxy = new WebProxy(base.Proxy);
  31. }
  32. request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)";
  33. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  34. StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.ASCII);
  35. Label_007A:
  36. str2 = reader.ReadLine();
  37. if (str2 != null)
  38. {
  39. string[] strArray = str2.Split(new char[] { ';' });
  40. if (this.OnStreamingData != null)
  41. {
  42. IFormatProvider uSFormat = FormulaHelper.USFormat;
  43. DataPacket dp = new DataPacket(strArray[0], DateTime.Parse(strArray[1], DateTimeFormatInfo.InvariantInfo), (double) float.Parse(strArray[2], uSFormat), double.Parse(strArray[3], uSFormat));
  44. dp.TimeZone = double.MaxValue;
  45. this.OnStreamingData(this, dp);
  46. }
  47. goto Label_007A;
  48. }
  49. }
  50. catch (Exception exception)
  51. {
  52. base.LastError = exception;
  53. }
  54. finally
  55. {
  56. if (this.OnStreamingStopped != null)
  57. {
  58. this.OnStreamingStopped(this, new EventArgs());
  59. }
  60. }
  61. }
  62. public override CommonDataProvider GetData(string symbols, DataCycle dataCycle, DateTime startTime, DateTime endTime)
  63. {
  64. byte[] bs = base.DownloadBinary(symbols, "http://subscribe.easychart.net/member/datafeed.aspx?f=BinaryHistory&AddWhenNoSymbol=1&Symbol=" + symbols);
  65. if (bs != null)
  66. {
  67. CommonDataProvider provider = new CommonDataProvider(null);
  68. provider.LoadByteBinary(bs);
  69. provider.SetStringData("Code", symbols.ToUpper());
  70. return provider;
  71. }
  72. return null;
  73. }
  74. public override DataPacket[] GetEodData(string Exchanges, string[] symbols, DateTime Time)
  75. {
  76. string str = base.DownloadString("http://subscribe.easychart.net/member/datafeed.aspx?f=EndOfDay&Exchanges=" + Exchanges + "&Date=" + Time.ToString("yyyy-MM-dd"));
  77. if ((str != null) && (str != ""))
  78. {
  79. string[] strArray = str.Trim().Split(new char[] { '\r' });
  80. DataPacket[] packetArray = new DataPacket[strArray.Length];
  81. for (int i = 0; i < packetArray.Length; i++)
  82. {
  83. packetArray[i] = DataPacket.ParseEODData(strArray[i].Trim());
  84. }
  85. return packetArray;
  86. }
  87. return base.GetEodData(Exchanges, symbols, Time);
  88. }
  89. public override string[] GetExchanges()
  90. {
  91. 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" };
  92. }
  93. public override string[] GetIndustry()
  94. {
  95. string str = base.DownloadString("http://data.easychart.net/Industry.aspx");
  96. if (str != null)
  97. {
  98. return str.Split(new char[] { '\r' });
  99. }
  100. return base.GetIndustry();
  101. }
  102. public override bool Login(string Username, string Password)
  103. {
  104. base.Ticket = base.DownloadString("http://subscribe.easychart.net/GetTicket.aspx?UserId=" + Username + "&Password=" + Password);
  105. return ((base.Ticket != null) && (base.Ticket != ""));
  106. }
  107. public override string[] LookupSymbols(string Key, string Exchanges, string StockType, string Market)
  108. {
  109. if (base.Logined)
  110. {
  111. string str = base.DownloadString("http://subscribe.easychart.net/member/datafeed.aspx?f=SymbolList&Exchanges=" + Exchanges);
  112. if (str != null)
  113. {
  114. return str.Trim().Split(new char[] { '\r' });
  115. }
  116. }
  117. return null;
  118. }
  119. public override void StopDownload()
  120. {
  121. base.Canceled = true;
  122. }
  123. public override string DataFeedName
  124. {
  125. get
  126. {
  127. return "Easy Chart Demo Data Feed";
  128. }
  129. }
  130. public override string Description
  131. {
  132. get
  133. {
  134. return "This is a free data feed, provided by http://finance.easychart.net.";
  135. }
  136. }
  137. public override string HomePage
  138. {
  139. get
  140. {
  141. return "http://finance.easychart.net";
  142. }
  143. }
  144. public override bool IsFree
  145. {
  146. get
  147. {
  148. return true;
  149. }
  150. }
  151. public override string LoginURL
  152. {
  153. get
  154. {
  155. return "http://subscribe.easychart.net/login.aspx";
  156. }
  157. }
  158. public override string RegURL
  159. {
  160. get
  161. {
  162. return "http://subscribe.easychart.net/reg.aspx";
  163. }
  164. }
  165. public override bool SupportEod
  166. {
  167. get
  168. {
  169. return true;
  170. }
  171. }
  172. public override bool SupportIndustry
  173. {
  174. get
  175. {
  176. return true;
  177. }
  178. }
  179. public override bool SupportIntraday
  180. {
  181. get
  182. {
  183. return false;
  184. }
  185. }
  186. public override bool SupportStreaming
  187. {
  188. get
  189. {
  190. return true;
  191. }
  192. }
  193. public override bool SupportSymbolList
  194. {
  195. get
  196. {
  197. return true;
  198. }
  199. }
  200. }
  201. }