/// <summary>
 /// Constructor
 /// </summary>
 /// <param name="controller">Price API controller</param>
 internal OffersForm(PriceAPIController controller)
 {
     InitializeComponent();
     mController = controller;
     //subscribe for the offer update event of the controller
     mController.OnPriceUpdate += PriceAPIController_PriceUpdate;
     listViewOffers.VirtualListSize = mController.Offers.Count;
 }
 /// <summary>
 /// Disposes the object data
 /// </summary>
 public void Dispose()
 {
     if (mPeriods != null)
     {
         mPeriods.Clear();
         mPeriods = null;
     }
     if (mController != null)
     {
         mController.OnPriceUpdate -= OnPriceUpdate;
         mController = null;
     }
 }
示例#3
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="controller">PriceHistory API controller</param>
        internal RequestHistoryForm(PriceAPIController controller)
        {
            InitializeComponent();

            // Fills the list of the offers available
            for (int i = 0; i < controller.Offers.Count; i++)
            {
                comboBoxInstrument.Items.Add(controller.Offers[i].Instrument);
            }
            if (comboBoxInstrument.Items.Count > 0)
            {
                comboBoxInstrument.SelectedIndex = 0;
            }

            // Fills the list of the timeframes available except tick timeframes (as
            // ticks are not supported by PriceHistory API)
            O2GTimeframeCollection timeframes = controller.Timeframes;

            for (int i = 0; i < timeframes.Count; i++)
            {
                O2GTimeframe tf = timeframes[i];
                if (tf.Unit == O2GTimeframeUnit.Tick)
                {
                    continue;
                }
                TimeframeItem item = new TimeframeItem(tf);
                comboBoxTimeframe.Items.Add(item);
            }

            if (comboBoxTimeframe.Items.Count > 0)
            {
                comboBoxTimeframe.SelectedIndex = 0;
            }

            // Initialize the range for date/time controls
            dateTimePickerFrom.MinDate = new DateTime(1980, 1, 1);
            dateTimePickerFrom.MaxDate = DateTime.Now;
            dateTimePickerTo.MinDate   = new DateTime(1980, 1, 1);
        }
示例#4
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="collection">The collection of the prices to be displayed</param>
        /// <param name="controller">The Price API controller</param>
        internal PriceHistoryForm(IPeriodCollection collection, PriceAPIController controller)
        {
            InitializeComponent();
            mCollection = collection;

            // find the offer for the collection instrument and
            // make the proper numeric format to display the prices
            // of the collection.
            foreach (IOffer offer in controller.Offers)
            {
                if (offer.Instrument == collection.Instrument)
                {
                    mNumberFormat = "0." + new string('0', offer.Digits);
                }
            }

            if (mNumberFormat == null)
            {
                mNumberFormat = "0.00";
            }

            // add items to the list view (for the real application virtual list view
            // will be more effective solution)
            for (int i = 0; i < collection.Count; i++)
            {
                AddItem(i);
            }

            // set the window title to the collection parameters
            this.Text = string.Format("History:{0}[{1}]{2}", collection.Instrument, collection.Timeframe, collection.IsAlive ? " (live)" : "");

            // and subscribe for the collection update event if the collection is subscribed
            // for the price updates, so it will be changed every time when a new tick is received
            if (collection.IsAlive)
            {
                mCollection.OnCollectionUpdate += this.IPeriodCollection_Updated;
            }
        }
        /// <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, PriceAPIController 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;
            }
        }