private void Client_HistoricalDataReceived(object sender, HistoricalDataEventArgs e)
        {
            StatusLabelText = $"Loaded {e.Data.Count} Bars";

            //find largest significant decimal by sampling the prices at the start and end of the series
            var decPlaces = new List <int>();

            for (var i = 0; i < Math.Min(20, e.Data.Count); i++)
            {
                decPlaces.Add(e.Data[i].Open.CountDecimalPlaces());
                decPlaces.Add(e.Data[e.Data.Count - 1 - i].Close.CountDecimalPlaces());
            }

            //set the column format to use that number so we don't get any useless trailing 0s
            var decimalPlaces = 5;

            if (decPlaces.Count > 0)
            {
                decimalPlaces = decPlaces.Max();
            }

            foreach (var bar in e.Data)
            {
                var newBar = DataUtils.BarWithRoundedPrices(bar, decimalPlaces);

                uiContext.Send(x => Data.Add(newBar), null);
            }
        }
Ejemplo n.º 2
0
        private void LoadData()
        {
            Data.Clear();

            //grab the data
            using (var localStorage = DataStorageFactory.Get())
            {
                if (BarSizes.Count == 1)
                {
                    SelectedBarsize = BarSizes.FirstOrDefault();
                }
                var bars = localStorage.GetData(TheInstrument, StartTime, EndTime, SelectedBarsize);

                //find largest significant decimal by sampling the prices at the start and end of the series
                var decPlaces = new List <int>();
                for (var i = 0; i < Math.Min(bars.Count, 20); i++)
                {
                    decPlaces.Add(bars[i].Open.CountDecimalPlaces());
                    decPlaces.Add(bars[bars.Count - 1 - i].Close.CountDecimalPlaces());
                }


                foreach (var bar in bars)
                {
                    //do any required time zone coversions
                    if (SelectedTimezone == Timezone.Utc)
                    {
                        bar.DateTimeClose = TimeZoneInfo.ConvertTimeToUtc(bar.DateTimeClose, timeZoneInfo);
                    }
                    else if (SelectedTimezone == Timezone.Local)
                    {
                        bar.DateTimeClose = TimeZoneInfo.ConvertTime(bar.DateTimeClose, timeZoneInfo, TimeZoneInfo.Local);
                    }

                    var newBar = DataUtils.BarWithRoundedPrices(bar, decPlaces.Max());
                    Data.Add(newBar);
                }
                loadedBarsize  = SelectedBarsize;
                loadedTimeZone = SelectedTimezone;
            }

            StatusLabelText = $"Loaded {Data.Count} Bars";
        }