QuoteComponentProxy.cs 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. using Muchinfo.Quote;
  2. using Muchinfo.Quote.HistoryClient;
  3. using Muchinfo.Quote.SqliteDal;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. namespace MuchInfo.Chart.App.Quote
  8. {
  9. public class QuoteComponentProxy
  10. {
  11. #region Fields
  12. private HistoryClient _historyClient;
  13. private string _uri;
  14. #endregion Fields
  15. #region Constructors
  16. /// <summary>
  17. /// Initializes a new instance of the <see cref="QuoteComponentProxy"/> class.
  18. /// </summary>
  19. public QuoteComponentProxy(bool quoteCycleBySettlementPlan, string uri)
  20. {
  21. try
  22. {
  23. _uri = uri.StartsWith(@"net.tcp://") ? uri : @"net.tcp://" + uri;
  24. _historyClient = new HistoryClient(quoteCycleBySettlementPlan);
  25. _historyClient.AddServerAddr(new string[] { _uri });
  26. _historyClient.ResponseHistoryCycle -= HistoryClient_ResponseHistoryCycle;
  27. _historyClient.ResponseHistoryCycle += HistoryClient_ResponseHistoryCycle;
  28. }
  29. catch (Exception e)
  30. {
  31. //FileLog.Default.Write("初始化行情组件出错, 方法: QuoteComponentProxy.QuoteComponentProxy" + Environment.NewLine + e.Message);
  32. }
  33. }
  34. #endregion Constructors
  35. #region Events
  36. public event EventHandler<HistoryCycleResponseEventArgs> ResponseHistoryCycle;
  37. #endregion Events
  38. #region Methods
  39. #region Public Methods
  40. /// <summary>
  41. /// 获取盘面信息
  42. /// </summary>
  43. /// <param name="symbolList">The symbol list.</param>
  44. /// <returns>DayQuote[][].</returns>
  45. public DayQuote[] GetDayQuote(IEnumerable<string> symbolList)
  46. {
  47. var symbolArray = symbolList == null ? null : symbolList.ToArray();
  48. if (_historyClient == null || symbolArray == null || !symbolArray.Any()) return null;
  49. try
  50. {
  51. return _historyClient.GetDayQuote(symbolArray);
  52. }
  53. catch (Exception e)
  54. {
  55. throw e;
  56. //FileLog.Default.Write("获取盘面信息出错, 方法: QuoteComponentProxy.GetDayQuote" + Environment.NewLine + e.Message);
  57. }
  58. }
  59. /// <summary>
  60. /// Gets the goods property.
  61. /// </summary>
  62. /// <param name="exchangeCode">The exchangecode.</param>
  63. /// <param name="sort">The sort.</param>
  64. /// <returns>GoodsProperty[][].</returns>
  65. public GoodsProperty[] GetGoodsProperty(int exchangeCode, int sort)
  66. {
  67. if (_historyClient == null) return null;
  68. try
  69. {
  70. return _historyClient.GetGoodsProperty(exchangeCode, sort);
  71. }
  72. catch (Exception e)
  73. {
  74. throw e;
  75. //FileLog.Default.Write("获取商品信息出错, 方法: QuoteComponentProxy.GetGoodsProperty" + Environment.NewLine + e.Message);
  76. //return null;
  77. }
  78. }
  79. /// <summary>
  80. /// 获取历史周期行情
  81. /// </summary>
  82. /// <param name="symbol">The symbol.</param>
  83. /// <param name="cycle">The cycle.</param>
  84. /// <param name="dtStartTime">The dt start time.</param>
  85. /// <param name="dtEndTime">The dt end time.</param>
  86. /// <param name="topN">The top N.</param>
  87. /// <param name="ret">The ret.</param>
  88. /// <returns>HistoryCycle[][].</returns>
  89. public HistoryCycle[] GetHistoryCycle(string symbol, Cycle cycle, DateTime dtStartTime, DateTime dtEndTime, short topN, out RetMessageCode ret)
  90. {
  91. ret = RetMessageCode.WCFError;
  92. if (_historyClient == null) return null;
  93. try
  94. {
  95. return _historyClient.GetHistoryCycle(symbol, cycle, dtStartTime, dtEndTime, topN, out ret);
  96. }
  97. catch (Exception e)
  98. {
  99. throw e;
  100. //FileLog.Default.Write("获取历史行情出错, 方法: QuoteComponentProxy.GetHistoryCycle" + Environment.NewLine + e.Message);
  101. //return null;
  102. }
  103. }
  104. /// <summary>
  105. /// 获取历史周期行情
  106. /// </summary>
  107. /// <param name="exchangeCode">The exchange code.</param>
  108. /// <param name="goodsCode">The goods code.</param>
  109. /// <param name="timeSpan">The time span.</param>
  110. /// <param name="dtStartTime">The dt start time.</param>
  111. /// <param name="dtEndTime">The dt end time.</param>
  112. /// <param name="topN">The top N.</param>
  113. /// <param name="ret">The ret.</param>
  114. /// <returns>HistoryCycle[][].</returns>
  115. public HistoryCycle[] GetHistoryCycle(int exchangeCode, string goodsCode, TimeSpan timeSpan, DateTime dtStartTime, DateTime dtEndTime, short topN, out RetMessageCode ret)
  116. {
  117. ret = RetMessageCode.WCFError;
  118. if (_historyClient == null) return null;
  119. try
  120. {
  121. return _historyClient.GetHistoryCycle(exchangeCode, goodsCode, timeSpan, dtStartTime, dtEndTime, topN, out ret);
  122. }
  123. catch (Exception e)
  124. {
  125. throw e;
  126. //FileLog.Default.Write("获取历史行情出错, 方法: QuoteComponentProxy.GetHistoryCycle" + Environment.NewLine + e.Message);
  127. //return null;
  128. }
  129. }
  130. /// <summary>
  131. /// Gets the history tik.
  132. /// </summary>
  133. /// <param name="symbol">The symbol.</param>
  134. /// <param name="dtStartTime">The dt start time.</param>
  135. /// <param name="dtEndTime">The dt end time.</param>
  136. /// <param name="topN">The top N.</param>
  137. /// <returns>HistoryTik[][].</returns>
  138. public HistoryTik[] GetHistoryTik(string symbol, DateTime dtStartTime, DateTime dtEndTime, short topN)
  139. {
  140. if (_historyClient == null) return null;
  141. try
  142. {
  143. return _historyClient.GetHistoryTik(symbol, dtStartTime, dtEndTime, topN);
  144. }
  145. catch (Exception e)
  146. {
  147. throw e;
  148. //FileLog.Default.Write("获取历史Tik行情出错, 方法: QuoteComponentProxy.GetHistoryTik" + Environment.NewLine + e.Message);
  149. //return null;
  150. }
  151. }
  152. /// <summary>
  153. /// Gets the last settlement plans.
  154. /// </summary>
  155. /// <returns>SettlementPlan[][].</returns>
  156. public SettlementPlan[] GetLastSettlementPlans()
  157. {
  158. if (_historyClient == null) return null;
  159. try
  160. {
  161. return _historyClient.GetLastSettlementPlans();
  162. }
  163. catch (Exception e)
  164. {
  165. throw e;
  166. //FileLog.Default.Write("获取结算计划出错, 方法: QuoteComponentProxy.GetLastSettlementPlans" + Environment.NewLine + e.Message);
  167. //return null;
  168. }
  169. }
  170. /// <summary>
  171. /// Gets the settlement plans.
  172. /// </summary>
  173. /// <param name="exchangeCode">The exchange code.</param>
  174. /// <param name="sort">The sort.</param>
  175. /// <param name="dtStartTime">The dt start time.</param>
  176. /// <param name="dtEndTime">The dt end time.</param>
  177. /// <param name="topN">The top N.</param>
  178. /// <returns>SettlementPlan[][].</returns>
  179. public SettlementPlan[] GetSettlementPlans(string exchangeCode, int sort, DateTime dtStartTime, DateTime dtEndTime, short topN)
  180. {
  181. if (_historyClient == null) return null;
  182. try
  183. {
  184. return _historyClient.GetSettlementPlans(exchangeCode, sort, dtStartTime, dtEndTime, topN);
  185. }
  186. catch (Exception e)
  187. {
  188. throw e;
  189. //FileLog.Default.Write("获取结算计划出错, 方法: QuoteComponentProxy.GetSettlementPlans" + Environment.NewLine + e.Message);
  190. //return null;
  191. }
  192. }
  193. #endregion Public Methods
  194. #region Private Methods
  195. /// <summary>
  196. /// Handles the ResponseHistoryCycle event of the HistoryClient control.
  197. /// </summary>
  198. /// <param name="sender">The source of the event.</param>
  199. /// <param name="e">The <see cref="HistoryCycleResponseEventArgs"/> instance containing the event data.</param>
  200. private void HistoryClient_ResponseHistoryCycle(object sender, HistoryCycleResponseEventArgs e)
  201. {
  202. if (ResponseHistoryCycle != null)
  203. {
  204. ResponseHistoryCycle(sender, e);
  205. }
  206. }
  207. #endregion Private Methods
  208. #endregion Methods
  209. #region IServiceProxy
  210. /// <summary>
  211. /// 执行与释放或重置非托管资源相关的应用程序定义的任务。
  212. /// </summary>
  213. public void Dispose()
  214. {
  215. if (_historyClient == null) return;
  216. this._historyClient.Dispose();
  217. }
  218. /// <summary>
  219. /// 终结点地址
  220. /// </summary>
  221. public string EndpointAddress
  222. {
  223. get
  224. {
  225. if (_historyClient == null) return string.Empty;
  226. return _uri;
  227. }
  228. }
  229. #endregion
  230. }
  231. }