Ejemplo n.º 1
0
        private void btnChartMarket_Click(object sender, EventArgs e)
        {
            WinForms.SetWaitCursor(true);

            try
            {
                zChartInterval interval = (zChartInterval)Enum.Parse(typeof(zChartInterval), comboChartInterval.Text);

                EZInstrument instrument = APIMain.Instance.ShowInstrumentDialog();

                if (instrument == null)
                {
                    status.Text = "No instrument selected.";
                }
                else
                {
                    status.Text = "*** LOADING CHART ***";
                    RequestChartData(instrument, interval, Convert.ToInt32(numericPeriod.Value));
                }
            }
            finally
            {
                WinForms.SetWaitCursor(false);
            }
        }
        private void RequestChartData(EZInstrument instrument, zChartInterval interval, int period)
        {
            ChartDataForm chartForm;

            // Set EndDate to the current trading date.
            //DateTime dtEndDate = selectedContract.GetTradeDate(DateTime.Now);
            DateTime dtEndDate = DateTime.Now;

            DateTime dtStartDate;

            // Pick a different start date depending on if we are viewing DAYS, HOURS, MINUTES, etc...
            if (interval == zChartInterval.Week)
            {
                dtStartDate = dtEndDate.AddMonths(-16);
            }
            else if (interval == zChartInterval.Day)
            {
                dtStartDate = dtEndDate.AddMonths(-5);
            }
            else if (interval == zChartInterval.Minute)
            {
                dtStartDate = dtEndDate;
                if (period <= 15)   // 15 minute (or less) bars
                {
                    dtStartDate = dtStartDate.AddTradeHours(-4);
                }
                else                // more than 15 minute bars
                {
                    dtStartDate = dtStartDate.AddTradeDays(-2);
                }
            }
            else
            {
                // Anything we haven't covered, we'll load a couple days (not ideal - needs to be improved).
                dtStartDate = dtEndDate;
                dtStartDate = dtStartDate.AddTradeDays(-3);

                /*// This little loop here will ensure that we load the previous trade date as well as today and will account for weekends
                 * // and holidays.
                 * while ((selectedContract.GetTradeDate(dtStartDate) == dtEndDate))
                 * {
                 *  dtStartDate = dtStartDate.AddDays(-1);
                 * }*/
            }

            // Create a BarInterval object to tell the API what bar interval we want.
            // So for example, if we wanted a 15 minute bar, we would do:  New ezBarInterval(zChartDataType.Minute, 15)
            ezBarInterval ezbi = new ezBarInterval(interval, period);

            IChartDataProvider provider = new ChartDataProviderCTS(instrument.Name + " : " + ezbi, ezbi, ezSessionTimeRange.Empty);

            chartForm = new ChartDataForm(provider);
            WinForms.SetWaitCursor(true);
            //provider.LoadHistoricalChartData(APIMain.MarketFromInstrument(instrument), dtStartDate, dtEndDate);
            provider.LoadRealTimeChartData(APIMain.MarketFromInstrument(instrument), dtStartDate);

            chartForm.Show();
        }
Ejemplo n.º 3
0
        void provider_DataLoadComplete(object sender, ezDataLoadCompleteEventArgs e)
        {
            WinForms.SetWaitCursor(false);

            this.Invoke((MethodInvoker) delegate
            {
                this.Text = provider.Name;
            });
        }
Ejemplo n.º 4
0
        private void RequestChartData(EZInstrument instrument, zChartInterval interval, int period)
        {
            // Set EndDate to the current trading date.
            //DateTime dtEndDate = selectedContract.GetTradeDate(DateTime.Now);
            DateTime dtEndDate = DateTime.Now;

            DateTime       dtStartDate;
            zChartInterval enBarInterval = zChartInterval.Hour;

            if (interval == zChartInterval.Day)
            {
                enBarInterval = zChartInterval.Day;

                // User select Day bars, load a few months of them.
                dtStartDate = dtEndDate.AddMonths(-3);
            }
            else
            {
                enBarInterval = interval;

                // User selected non-Day bars (Hour, Minute, etc.), load a couple of days of them.
                dtStartDate = dtEndDate;
                dtStartDate = dtStartDate.AddDays(-3);

                /*// This little loop here will ensure that we load the previous trade date as well as today and will account for weekends
                 * // and holidays.
                 * while ((selectedContract.GetTradeDate(dtStartDate) == dtEndDate))
                 * {
                 *  dtStartDate = dtStartDate.AddDays(-1);
                 * }*/
            }

            // Create a BarInterval object to tell the API what bar interval we want.
            // So for example, if we wanted a 15 minute bar, we would do:  New ezBarInterval(zChartDataType.Minute, 15)
            ezBarInterval oBarIntvl = new ezBarInterval(enBarInterval, period);

            string             chartName = instrument.Name + " : " + oBarIntvl;
            IChartDataProvider provider  = new ChartDataProviderCTS(chartName, oBarIntvl, ezSessionTimeRange.Empty);

            if (LoadingNewChart != null)
            {
                LoadingNewChart(provider);
            }
            this.SetChartDataProvider(provider);
            WinForms.SetWaitCursor(true);
            provider.LoadHistoricalChartData(APIMain.MarketFromInstrument(instrument), dtStartDate, dtEndDate);
        }