public void updatePreMergeRTBarSeries(RTDataBar bar)
        {
            if (isDataMerged)
            {
                return;
            }

            DateTime          time           = bar.time;
            MarketDataElement currentRTBData = MarketDataUtil.convertBarToMarketDataElement(bar);

            if (preMergeRTBarSeries == null)
            {
                preMergeRTBarSeries = new SeriesBuilder <DateTime, MarketDataElement>()
                {
                    { time, currentRTBData }
                }.Series;
            }
            else
            {
                if (!preMergeRTBarSeries.ContainsKey(time))
                {
                    preMergeRTBarSeries = preMergeRTBarSeries.Merge(new SeriesBuilder <DateTime, MarketDataElement>()
                    {
                        { time, currentRTBData }
                    }.Series);
                }
            }
            return;
        }
Exemplo n.º 2
0
        public void updateRTBarSeriesActions()
        {
            if (currentCompleteRTBar == null)
            {
                return;
            }

            MarketDataElement data = MarketDataUtil.convertBarToMarketDataElement(currentCompleteRTBar);

            if (!isRTBarMergeNeed || TimeBarSeries != null)
            {
                if (TimeBarSeries != null)
                {
                    if (TimeBarSeries.ContainsKey(data.time))
                    {
                        return;
                    }
                    TimeBarSeries = TimeBarSeries.Merge(new SeriesBuilder <DateTime, MarketDataElement>()
                    {
                        { data.time, data }
                    }.Series);
                }
                else
                {
                    TimeBarSeries = new SeriesBuilder <DateTime, MarketDataElement>()
                    {
                        { data.time, data }
                    }
                }.Series;
        public Boolean updateTimeBarSeries(IBMessage message)
        {
            Boolean isAdded = false;

            if ((!isDataMerged && getNeedMergeFlag()) || !getNeedMergeFlag())
            {
                return(isAdded);
            }
            Series <DateTime, MarketDataElement> TimeBarSeries = appMDManager.getTimeBarSeries();

            if (TimeBarSeries == null)
            {
                return(isAdded);
            }

            HistoricalDataMessage histMessage = (HistoricalDataMessage)message;

            double h   = Convert.ToDouble(histMessage.High);
            double l   = Convert.ToDouble(histMessage.Low);
            double o   = Convert.ToDouble(histMessage.Open);
            double c   = Convert.ToDouble(histMessage.Close);
            double vol = Convert.ToDouble(histMessage.Volume);

            DateTime          time           = DateTime.ParseExact(histMessage.Date.Trim(), "yyyyMMdd  HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal);
            MarketDataElement currentHsiData = MarketDataUtil.createHLOC(time, "HLOC", "HSI", "FUT");

            currentHsiData.volume = vol;
            currentHsiData.time   = time;


            if (TimeBarSeries == null)
            {
                TimeBarSeries = new SeriesBuilder <DateTime, MarketDataElement>()
                {
                    { time, currentHsiData }
                }.Series;
                isAdded = true;
            }
            else
            {
                MarketDataElement element = TimeBarSeries.GetAt(TimeBarSeries.KeyCount - 1);
                if (!TimeBarSeries.ContainsKey(time))
                {
                    TimeBarSeries = TimeBarSeries.Merge(new SeriesBuilder <DateTime, MarketDataElement>()
                    {
                        { time, currentHsiData }
                    }.Series);
                    isAdded = true;
                }
            }
            return(isAdded);
        }
        public Boolean updatePreMergeHistBarSeries(IBMessage message)
        {
            Boolean isAdded = false;

            if (isDataMerged)
            {
                return(isAdded);
            }

            HistoricalDataMessage histMessage = (HistoricalDataMessage)message;

            double h   = Convert.ToDouble(histMessage.High);
            double l   = Convert.ToDouble(histMessage.Low);
            double o   = Convert.ToDouble(histMessage.Open);
            double c   = Convert.ToDouble(histMessage.Close);
            double vol = Convert.ToDouble(histMessage.Volume);

            DateTime          time            = DateTime.ParseExact(histMessage.Date.Trim(), "yyyyMMdd  HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal);
            MarketDataElement currentHistData = MarketDataUtil.createHLOC(time, "HLOC", "HSI", "FUT");

            MarketDataUtil.setHLOC(currentHistData, h, l, o, c);
            currentHistData.volume = vol;
            currentHistData.time   = time;
            if (preMergeHistBarSeries == null)
            {
                preMergeHistBarSeries = new SeriesBuilder <DateTime, MarketDataElement>()
                {
                    { time, currentHistData }
                }.Series;
                isAdded = true;
            }
            else
            {
                if (!preMergeHistBarSeries.ContainsKey(time))
                {
                    preMergeHistBarSeries = preMergeHistBarSeries.Merge(new SeriesBuilder <DateTime, MarketDataElement>()
                    {
                        { time, currentHistData }
                    }.Series);
                    isAdded = true;
                }
            }
            return(isAdded);
        }
Exemplo n.º 5
0
        public static Series <DateTime, MarketDataElement> getLastNMarketData(Series <DateTime, MarketDataElement> series, int n)
        {
            MarketDataElement lastItem      = series.GetAt(series.KeyCount - 1);
            DateTime          tempStartTime = lastItem.time.AddMinutes(-n + 1);
            Series <DateTime, MarketDataElement> tempSeries = series.Between(tempStartTime, lastItem.time);

            if (tempSeries.KeyCount == n)
            {
                return(tempSeries);
            }
            //bool found=false;
            while (true)
            {
                //log.Info("testing 3");
                tempStartTime = tempStartTime.AddMinutes(-1);
                tempSeries    = series.Between(tempStartTime, lastItem.time);
                if (tempSeries.KeyCount == n)
                {
                    return(tempSeries);
                }
            }
        }