예제 #1
0
            /// <summary>
            /// Constructor
            /// </summary>
            /// <param name="timeframe">ForexConnect timeframe descriptor</param>
            internal TimeframeItem(O2GTimeframe timeframe)
            {
                mTimeframe = timeframe;
                DateTime start = DateTime.Now.AddDays(-1), end = DateTime.Now;

                // parse the timeframe ID to get Quotes Manager timeframe descriptor
                if (!CandlePeriod.parsePeriod(timeframe.ID, ref mTimeframeUnit, ref mTimeframeLength))
                {
                    throw new ArgumentException("Invalide timeframe", "timeframe");
                }

                // get a candle in that timeframe to get it length
                CandlePeriod.getCandle(DateTime.Now, ref start, ref end, mTimeframeUnit, mTimeframeLength, 0, 0);
                mLength = end.Subtract(start);
            }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="instrument">The instrument name</param>
        /// <param name="timeframe">The timeframe id (e.g. m1)</param>
        /// <param name="alive">The flag indicating whether the collection shall be subscribed for updates</param>
        /// <param name="controller">The price update controller</param>
        public PeriodCollection(string instrument, string timeframe, bool alive, IPriceUpdateController controller)
        {
            mInstrument = instrument;
            mTimeframe  = timeframe;
            mAlive      = alive;
            mFilled     = false;

            if (alive)
            {
                // if collection is alive - we will need to calculate the date/time of the candle
                // to which each tick belongs to, so we need to parse the time frame name for
                // further usage
                if (!CandlePeriod.parsePeriod(timeframe, ref mTimeframeUnit, ref mTimeframeLength))
                {
                    throw new ArgumentException("Invalid timeframe", "timeframe");
                }
                // and we need to subscribe to tick updates
                mWaitingUpdates           = new Queue <IOffer>();
                mTradingDayOffset         = controller.TradingDayOffset;
                controller.OnPriceUpdate += OnPriceUpdate;
                mController = controller;
            }
        }