/// <summary> /// Price collection event: When a period in the collection is changed /// </summary> /// <param name="collection">The period collection</param> /// <param name="index">The index of element of the collection</param> void IPeriodCollection_Updated(IPeriodCollection collection, int index) { IPeriod period = collection[index]; Console.WriteLine("Price updated: DateTime={0}, BidOpen={1}, BidHigh={2}, BidLow={3}, BidClose={4}, AskOpen={5}, AskHigh={6}, AskLow={7}, AskClose={8}, Volume={9}", period.Time, period.Bid.Open, period.Bid.High, period.Bid.Low, period.Bid.Close, period.Ask.Open, period.Ask.High, period.Ask.Low, period.Ask.Close, period.Volume); }
/// <summary> /// PriceHisitoryAPI controller event: A history is received from the server /// </summary> /// <param name="collection"></param> private void PriceAPIController_CollectionLoaded(IPeriodCollection collection) { // The event will be sent from another thread if (this.InvokeRequired) { this.BeginInvoke(new PriceAPIController_CollectionLoaded(PriceAPIController_CollectionLoaded), collection); } else { // Create a from which displays the collection PriceHistoryForm form = new PriceHistoryForm(collection, mController); form.MdiParent = this; form.Show(); } }
/// <summary> /// Price collection event: When a period in the collection is changed /// </summary> /// <param name="collection"></param> /// <param name="index"></param> void IPeriodCollection_Updated(IPeriodCollection collection, int index) { // The event may be sent asynchronously if (this.InvokeRequired) { this.Invoke(new IPeriodCollection_Updated(IPeriodCollection_Updated), null, index); } else { // update corrsponding list view item while (listViewHistory.Items.Count < mCollection.Count) { AddItem(listViewHistory.Items.Count); } fillItem(index, listViewHistory.Items[index]); } }
/// <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; } }