| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257 |
- using Muchinfo.Quote;
- using Muchinfo.Quote.HistoryClient;
- using Muchinfo.Quote.SqliteDal;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace MuchInfo.Chart.App.Quote
- {
- public class QuoteComponentProxy
- {
- #region Fields
- private HistoryClient _historyClient;
- private string _uri;
- #endregion Fields
- #region Constructors
- /// <summary>
- /// Initializes a new instance of the <see cref="QuoteComponentProxy"/> class.
- /// </summary>
- public QuoteComponentProxy(bool quoteCycleBySettlementPlan, string uri)
- {
- try
- {
- _uri = uri.StartsWith(@"net.tcp://") ? uri : @"net.tcp://" + uri;
- _historyClient = new HistoryClient(quoteCycleBySettlementPlan);
- _historyClient.AddServerAddr(new string[] { _uri });
- _historyClient.ResponseHistoryCycle -= HistoryClient_ResponseHistoryCycle;
- _historyClient.ResponseHistoryCycle += HistoryClient_ResponseHistoryCycle;
- }
- catch (Exception e)
- {
- //FileLog.Default.Write("初始化行情组件出错, 方法: QuoteComponentProxy.QuoteComponentProxy" + Environment.NewLine + e.Message);
- }
- }
- #endregion Constructors
- #region Events
- public event EventHandler<HistoryCycleResponseEventArgs> ResponseHistoryCycle;
- #endregion Events
- #region Methods
- #region Public Methods
- /// <summary>
- /// 获取盘面信息
- /// </summary>
- /// <param name="symbolList">The symbol list.</param>
- /// <returns>DayQuote[][].</returns>
- public DayQuote[] GetDayQuote(IEnumerable<string> symbolList)
- {
- var symbolArray = symbolList == null ? null : symbolList.ToArray();
- if (_historyClient == null || symbolArray == null || !symbolArray.Any()) return null;
- try
- {
- return _historyClient.GetDayQuote(symbolArray);
- }
- catch (Exception e)
- {
- throw e;
- //FileLog.Default.Write("获取盘面信息出错, 方法: QuoteComponentProxy.GetDayQuote" + Environment.NewLine + e.Message);
- }
- }
- /// <summary>
- /// Gets the goods property.
- /// </summary>
- /// <param name="exchangeCode">The exchangecode.</param>
- /// <param name="sort">The sort.</param>
- /// <returns>GoodsProperty[][].</returns>
- public GoodsProperty[] GetGoodsProperty(int exchangeCode, int sort)
- {
- if (_historyClient == null) return null;
- try
- {
- return _historyClient.GetGoodsProperty(exchangeCode, sort);
- }
- catch (Exception e)
- {
- throw e;
- //FileLog.Default.Write("获取商品信息出错, 方法: QuoteComponentProxy.GetGoodsProperty" + Environment.NewLine + e.Message);
- //return null;
- }
- }
- /// <summary>
- /// 获取历史周期行情
- /// </summary>
- /// <param name="symbol">The symbol.</param>
- /// <param name="cycle">The cycle.</param>
- /// <param name="dtStartTime">The dt start time.</param>
- /// <param name="dtEndTime">The dt end time.</param>
- /// <param name="topN">The top N.</param>
- /// <param name="ret">The ret.</param>
- /// <returns>HistoryCycle[][].</returns>
- public HistoryCycle[] GetHistoryCycle(string symbol, Cycle cycle, DateTime dtStartTime, DateTime dtEndTime, short topN, out RetMessageCode ret)
- {
- ret = RetMessageCode.WCFError;
- if (_historyClient == null) return null;
- try
- {
- return _historyClient.GetHistoryCycle(symbol, cycle, dtStartTime, dtEndTime, topN, out ret);
- }
- catch (Exception e)
- {
- throw e;
- //FileLog.Default.Write("获取历史行情出错, 方法: QuoteComponentProxy.GetHistoryCycle" + Environment.NewLine + e.Message);
- //return null;
- }
- }
- /// <summary>
- /// 获取历史周期行情
- /// </summary>
- /// <param name="exchangeCode">The exchange code.</param>
- /// <param name="goodsCode">The goods code.</param>
- /// <param name="timeSpan">The time span.</param>
- /// <param name="dtStartTime">The dt start time.</param>
- /// <param name="dtEndTime">The dt end time.</param>
- /// <param name="topN">The top N.</param>
- /// <param name="ret">The ret.</param>
- /// <returns>HistoryCycle[][].</returns>
- public HistoryCycle[] GetHistoryCycle(int exchangeCode, string goodsCode, TimeSpan timeSpan, DateTime dtStartTime, DateTime dtEndTime, short topN, out RetMessageCode ret)
- {
- ret = RetMessageCode.WCFError;
- if (_historyClient == null) return null;
- try
- {
- return _historyClient.GetHistoryCycle(exchangeCode, goodsCode, timeSpan, dtStartTime, dtEndTime, topN, out ret);
- }
- catch (Exception e)
- {
- throw e;
- //FileLog.Default.Write("获取历史行情出错, 方法: QuoteComponentProxy.GetHistoryCycle" + Environment.NewLine + e.Message);
- //return null;
- }
- }
- /// <summary>
- /// Gets the history tik.
- /// </summary>
- /// <param name="symbol">The symbol.</param>
- /// <param name="dtStartTime">The dt start time.</param>
- /// <param name="dtEndTime">The dt end time.</param>
- /// <param name="topN">The top N.</param>
- /// <returns>HistoryTik[][].</returns>
- public HistoryTik[] GetHistoryTik(string symbol, DateTime dtStartTime, DateTime dtEndTime, short topN)
- {
- if (_historyClient == null) return null;
- try
- {
- return _historyClient.GetHistoryTik(symbol, dtStartTime, dtEndTime, topN);
- }
- catch (Exception e)
- {
- throw e;
- //FileLog.Default.Write("获取历史Tik行情出错, 方法: QuoteComponentProxy.GetHistoryTik" + Environment.NewLine + e.Message);
- //return null;
- }
- }
- /// <summary>
- /// Gets the last settlement plans.
- /// </summary>
- /// <returns>SettlementPlan[][].</returns>
- public SettlementPlan[] GetLastSettlementPlans()
- {
- if (_historyClient == null) return null;
- try
- {
- return _historyClient.GetLastSettlementPlans();
- }
- catch (Exception e)
- {
- throw e;
- //FileLog.Default.Write("获取结算计划出错, 方法: QuoteComponentProxy.GetLastSettlementPlans" + Environment.NewLine + e.Message);
- //return null;
- }
- }
- /// <summary>
- /// Gets the settlement plans.
- /// </summary>
- /// <param name="exchangeCode">The exchange code.</param>
- /// <param name="sort">The sort.</param>
- /// <param name="dtStartTime">The dt start time.</param>
- /// <param name="dtEndTime">The dt end time.</param>
- /// <param name="topN">The top N.</param>
- /// <returns>SettlementPlan[][].</returns>
- public SettlementPlan[] GetSettlementPlans(string exchangeCode, int sort, DateTime dtStartTime, DateTime dtEndTime, short topN)
- {
- if (_historyClient == null) return null;
- try
- {
- return _historyClient.GetSettlementPlans(exchangeCode, sort, dtStartTime, dtEndTime, topN);
- }
- catch (Exception e)
- {
- throw e;
- //FileLog.Default.Write("获取结算计划出错, 方法: QuoteComponentProxy.GetSettlementPlans" + Environment.NewLine + e.Message);
- //return null;
- }
- }
- #endregion Public Methods
- #region Private Methods
- /// <summary>
- /// Handles the ResponseHistoryCycle event of the HistoryClient control.
- /// </summary>
- /// <param name="sender">The source of the event.</param>
- /// <param name="e">The <see cref="HistoryCycleResponseEventArgs"/> instance containing the event data.</param>
- private void HistoryClient_ResponseHistoryCycle(object sender, HistoryCycleResponseEventArgs e)
- {
- if (ResponseHistoryCycle != null)
- {
- ResponseHistoryCycle(sender, e);
- }
- }
- #endregion Private Methods
- #endregion Methods
- #region IServiceProxy
- /// <summary>
- /// 执行与释放或重置非托管资源相关的应用程序定义的任务。
- /// </summary>
- public void Dispose()
- {
- if (_historyClient == null) return;
- this._historyClient.Dispose();
- }
- /// <summary>
- /// 终结点地址
- /// </summary>
- public string EndpointAddress
- {
- get
- {
- if (_historyClient == null) return string.Empty;
- return _uri;
- }
- }
- #endregion
- }
- }
|