コード例 #1
0
ファイル: KLineFactory.cs プロジェクト: handayu/TFS-WebKit
 /// <summary>
 /// 构造方法。
 /// </summary>
 /// <param name="instrument">处理合约。</param>
 /// <param name="publisher">发布者。</param>
 /// <param name="tradeRange">交易时段。</param>
 public KLineFactory(USeInstrument instrument, IKLinePublisher publisher, DayTradeRange tradeRange, IAppLogger eventLogger)
 {
     m_instrument  = instrument;
     m_publisher   = publisher;
     m_tradeRange  = tradeRange;
     m_eventLogger = eventLogger;
 }
コード例 #2
0
        /// <summary>
        /// 获取K线生成器。
        /// </summary>
        /// <param name="instrument"></param>
        /// <returns></returns>
        private List <KLineFactory> GetIndexKLineFactory(USeInstrument instrument)
        {
            Debug.Assert(instrument.Market != USeMarket.Unknown);
            string varieties = USeTraderProtocol.GetVarieties(instrument.InstrumentCode);


            List <KLineFactory> factoryList = null;

            if (m_indexkLineFactoryDic.TryGetValue(varieties, out factoryList) == false)
            {
                USeProduct product = m_productManager.GetPruduct(varieties);

                factoryList = new List <KLineFactory>();
                DayTradeRange tradeRange      = m_tradeRangeManager.CreateTradeRange(varieties);
                DateTime      tradeDay        = tradeRange.GetTradeDay(DateTime.Now);
                USeInstrument indexInstrument = USeTraderProtocol.GetVarietiesIndexCode(product);
                USeKLine      dayKLine        = GetDayKLine(tradeDay, indexInstrument);

                List <USeInstrument> instrumentList = m_instrumentManager.GetAllInstruments(varieties, product.Market);


                IndexDayKLineFactory dayFactory = new IndexDayKLineFactory(product, instrumentList, dayKLine, m_dayKLinePublishInterval, m_kLinePublisher, tradeRange, m_eventLogger, m_instrumentManager);
                factoryList.Add(dayFactory);
                IndexMinKLineFactory min1Factory = new IndexMinKLineFactory(product, instrumentList, USeCycleType.Min1, m_kLinePublisher, tradeRange, m_eventLogger, m_instrumentManager);
                factoryList.Add(min1Factory);

                m_indexkLineFactoryDic.Add(varieties, factoryList);
            }

            Debug.Assert(factoryList != null && factoryList.Count == 2);
            return(factoryList);
        }
コード例 #3
0
        /// <summary>
        /// 获取K线生成器。
        /// </summary>
        /// <param name="instrument"></param>
        /// <returns></returns>
        private List <KLineFactory> GetKLineFactory(USeInstrument instrument)
        {
            Debug.Assert(instrument.Market != USeMarket.Unknown);
            List <KLineFactory> factoryList = null;

            if (m_kLineFactoryDic.TryGetValue(instrument.InstrumentCode, out factoryList) == false)
            {
                factoryList = new List <KLineFactory>();
                DayTradeRange tradeRange    = m_tradeRangeManager.CreateTradeRange(instrument);
                bool          isMainConract = m_mainContractManager.IsMainContract(instrument.InstrumentCode);
                DateTime      tradeDay      = tradeRange.GetTradeDay(DateTime.Now);
                USeKLine      dayKLine      = GetDayKLine(tradeDay, instrument);

                DayKLineFactory dayFactory = new DayKLineFactory(instrument, dayKLine, m_kLinePublisher, tradeRange, m_eventLogger, m_dayKLinePublishInterval, isMainConract, m_instrumentManager);
                factoryList.Add(dayFactory);
                MinKLineFactory min1Factory = new MinKLineFactory(instrument, m_kLinePublisher, tradeRange, m_eventLogger, USeCycleType.Min1, isMainConract);
                factoryList.Add(min1Factory);

                m_kLineFactoryDic.Add(instrument.InstrumentCode, factoryList);
            }

            Debug.Assert(factoryList != null && factoryList.Count == 2);

            return(new List <KLineFactory>(factoryList));
        }
コード例 #4
0
        /// <summary>
        /// 创建交易区间。
        /// </summary>
        /// <param name="varieties">品种。</param>
        /// <returns></returns>
        public DayTradeRange CreateTradeRange(string varieties)
        {
            List <TradeRangeItem> tradeRangeList = null;

            if (m_tradeRangeDic.TryGetValue(varieties, out tradeRangeList) == false)
            {
                Debug.Assert(false);
                tradeRangeList = new List <TradeRangeItem>();
            }

            DayTradeRange dayTradeRange = new DayTradeRange(m_tradeCalendarList, tradeRangeList);

            return(dayTradeRange);
        }
コード例 #5
0
        private List <USeInstrumentDetail> m_insDetailList = null;        //合约的信息列表

        #endregion

        #region construction
        /// <summary>
        /// 构造方法。
        /// </summary>
        /// <param name="product">品种。</param>
        /// <param name="publisher">发布者。</param>
        /// <param name="tradeRange">交易时段。</param>
        /// <param name="publishInterval">发布间隔。</param>
        public IndexDayKLineFactory(USeProduct product, List <USeInstrument> instrumentList, USeKLine initKLine, TimeSpan publishInterval,
                                    IKLinePublisher publisher, DayTradeRange tradeRange, IAppLogger eventLogger, USeTradingInstrumentManager instrumentManager)
            : base(USeTraderProtocol.GetVarietiesIndexCode(product),
                   publisher, tradeRange, eventLogger)
        {
            Debug.Assert(product.PriceTick > 0);
            Debug.Assert(instrumentList != null && instrumentList.Count > 0);

            m_publishInterval = publishInterval;
            m_nextPublishTime = DateTime.Now.AddTicks(publishInterval.Ticks);
            m_product         = product;
            m_componentDic    = new Dictionary <string, USeMarketData>();
            foreach (USeInstrument instrument in instrumentList)
            {
                m_componentDic.Add(instrument.InstrumentCode, null);
            }

            if (initKLine != null)
            {
                Debug.Assert(initKLine.InstrumentCode == USeTraderProtocol.GetVarietiesIndexCode(product).InstrumentCode);
                m_kLine = initKLine;
            }
            else
            {
                m_kLine = CreateDefaultKLine();
            }

            //获取该数据库下的合约详细信息
            try
            {
                Debug.Assert(instrumentManager != null);
                m_insDetailList = instrumentManager.GetAllInstrumentDetails();
            }
            catch (Exception ex)
            {
                throw new Exception("IndexDayKLineFactory 获取全部合约详细信息异常:" + ex.Message);
            }
        }
コード例 #6
0
        /// <summary>
        /// 构造方法。
        /// </summary>
        /// <param name="instrument">合约。</param>
        /// <param name="publisher">发布者。</param>
        /// <param name="tradeRange">交易时段。</param>
        /// <param name="publishInterval">发布间隔(单位:秒)。</param>
        public DayKLineFactory(USeInstrument instrument, USeKLine initKLine, IKLinePublisher publisher, DayTradeRange tradeRange, IAppLogger eventLogger, TimeSpan publishInterval, bool isMainContract, USeTradingInstrumentManager instrumentManager)
            : base(instrument, publisher, tradeRange, eventLogger)
        {
            m_publishInterval = publishInterval;
            m_nextPublishTime = DateTime.Now.AddTicks(publishInterval.Ticks);

            m_isMainContract = isMainContract;

            if (initKLine != null)
            {
                Debug.Assert(initKLine.InstrumentCode == instrument.InstrumentCode);
                m_kLine = initKLine;
            }

            if (isMainContract)
            {
                string varieties = USeTraderProtocol.GetVarieties(instrument.InstrumentCode);
                m_mainContractCode = USeTraderProtocol.GetMainContractCode(varieties, instrument.Market);
            }

            //获取该数据库下的合约详细信息
            try
            {
                Debug.Assert(instrumentManager != null);
                m_insDetailList = instrumentManager.GetAllInstrumentDetails();
            }
            catch (Exception ex)
            {
                throw new Exception("IndexDayKLineFactory 获取全部合约详细信息异常:" + ex.Message);
            }
        }
コード例 #7
0
ファイル: MinKLineFactory.cs プロジェクト: handayu/TFS-WebKit
        /// <summary>
        /// 构造方法。
        /// </summary>
        /// <param name="instrument">合约。</param>
        /// <param name="klinePublisher">发布者。</param>
        /// <param name="cycle">周期。</param>
        /// <param name="eventLogger">日志。</param>
        public MinKLineFactory(USeInstrument instrument, IKLinePublisher klinePublisher, DayTradeRange tradeRange, IAppLogger eventLogger, USeCycleType cycle, bool isMainContract)
            : base(instrument, klinePublisher, tradeRange, eventLogger)
        {
            if (cycle != USeCycleType.Min1)
            {
                throw new NotSupportedException(string.Format("Not support {0} ", cycle));
            }

            m_cycle          = cycle;
            m_isMainContract = isMainContract;

            if (isMainContract)
            {
                string varieties = USeTraderProtocol.GetVarieties(instrument.InstrumentCode);
                m_mainContract = USeTraderProtocol.GetMainContractCode(varieties, instrument.Market);
            }
        }
コード例 #8
0
        /// <summary>
        /// 构造方法。
        /// </summary>
        /// <param name="indexInstrument">指数合约。</param>
        /// <param name="klinePublisher">发布者。</param>
        /// <param name="cycle">周期。</param>
        /// <param name="eventLogger">日志。</param>
        public IndexMinKLineFactory(USeProduct product, List <USeInstrument> instrumentList, USeCycleType cycle, IKLinePublisher klinePublisher, DayTradeRange tradeRange, IAppLogger eventLogger, USeTradingInstrumentManager instrumentManager)
            : base(USeTraderProtocol.GetVarietiesIndexCode(product),
                   klinePublisher, tradeRange, eventLogger)
        {
            if (cycle != USeCycleType.Min1)
            {
                throw new NotSupportedException(string.Format("Not support {0} ", cycle));
            }
            Debug.Assert(product.PriceTick > 0);
            Debug.Assert(instrumentList != null && instrumentList.Count > 0);

            m_cycle        = cycle;
            m_product      = product;
            m_componentDic = new Dictionary <string, USeMarketData>();
            foreach (USeInstrument instrument in instrumentList)
            {
                m_componentDic.Add(instrument.InstrumentCode, null);
            }

            //if (initKLine != null)
            //{
            //    Debug.Assert(initKLine.InstrumentCode == USeTraderProtocol.GetVarietiesIndexCode(product).InstrumentCode);
            //    m_kLine = initKLine;
            //}

            //获取该数据库下的合约详细信息
            try
            {
                Debug.Assert(instrumentManager != null);
                m_insDetailList = instrumentManager.GetAllInstrumentDetails();
            }
            catch (Exception ex)
            {
                throw new Exception("IndexDayKLineFactory 获取全部合约详细信息异常:" + ex.Message);
            }
        }