Exemplo n.º 1
0
        private void ForwardTimeLineData()
        {
            if (timeLineData.BarPos >= timeLineData.Length - 1)
            {
                int nextTradingDay = DataPackage.GetTradingDayReader().GetNextTradingDay(this.currentTradingDay);
                if (nextTradingDay < 0)
                {
                    return;
                }
                this.currentTradingDay = nextTradingDay;
                this.timeLineData      = DataPackage.GetTimeLineData(this.currentTradingDay);
            }

            if (mainKLineData.BarPos >= mainKLineData.Length - 1)
            {
                return;
            }
            double nextTime_KLine     = mainKLineData.Arr_Time[mainKLineData.BarPos + 1];
            int    nextTimeLineBarPos = timeLineData.BarPos;
            double nextTime_TimeLine  = timeLineData.Arr_Time[nextTimeLineBarPos];

            while (nextTime_TimeLine < nextTime_KLine && nextTimeLineBarPos < timeLineData.Length - 1)
            {
                nextTimeLineBarPos++;
                nextTime_TimeLine = timeLineData.Arr_Time[nextTimeLineBarPos];
            }
            timeLineData.BarPos = nextTimeLineBarPos;
        }
Exemplo n.º 2
0
        public void TestTransferTimeLineData()
        {
            IKLineData    klineData    = MockDataLoader.GetKLineData("m1505", 20150107, 20150107, KLinePeriod.KLinePeriod_1Minute);
            ITimeLineData timeLineData = DataTransfer_KLine2TimeLine.ConvertTimeLineData(klineData, 2849);

            AssertUtils.AssertEqual_TimeLineData("KLine2TimeLine_M05_20150107", GetType(), timeLineData);
        }
Exemplo n.º 3
0
        public TimeLineData_Extend(ITimeLineData timeLineData, IList <double[]> tradingTimeStartEndInfo)
        {
            this.timeLineData = timeLineData;
            this.startEndInfo = tradingTimeStartEndInfo;

            this.tradingTimeStartBarPos     = new List <int>();
            this.tradingTimeEndBarPos       = new List <int>();
            this.set_TradingTimeStartBarPos = new HashSet <int>();
            ISet <double> set_TradingTimeStart = GetSet_TradingTimeStart(tradingTimeStartEndInfo);

            for (int i = 0; i < timeLineData.Length; i++)
            {
                double time = timeLineData.Arr_Time[i];
                if (set_TradingTimeStart.Contains(time))
                {
                    this.tradingTimeStartBarPos.Add(i);
                    this.set_TradingTimeStartBarPos.Add(i);
                    if (i != 0)
                    {
                        tradingTimeEndBarPos.Add(i - 1);
                    }
                }
            }
            tradingTimeEndBarPos.Add(timeLineData.Length - 1);
        }
Exemplo n.º 4
0
        private PriceRectangle GetPriceRectangle()
        {
            ITimeLineData realData   = DataProvider.GetRealData();
            int           startIndex = 0;
            int           endIndex   = DataProvider.CurrentIndex;

            float priceBottom = realData.Arr_Price[startIndex];
            float priceTop    = realData.Arr_Price[startIndex];

            for (int i = startIndex + 1; i <= endIndex; i++)
            {
                if (priceBottom > realData.Arr_Price[i])
                {
                    priceBottom = realData.Arr_Price[i];
                }
                if (priceTop < realData.Arr_Price[i])
                {
                    priceTop = realData.Arr_Price[i];
                }
            }

            float yesterdayEnd = realData.YesterdayEnd;
            float b1           = Math.Abs(priceTop - yesterdayEnd);
            float b2           = Math.Abs(priceBottom - yesterdayEnd);
            float b            = (float)Math.Round((b1 > b2 ? b1 : b2) * 1.05, 2);

            return(new PriceRectangle(startIndex, realData.Length - 1, yesterdayEnd + b, yesterdayEnd - b));
        }
Exemplo n.º 5
0
        private void DrawHorizonal(Graphics g, ITimeLineData realData)
        {
            Pen pen2 = this.ColorConfig.Pen_FrameLine;

            pen2.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
            float percent = (PriceMapping.PriceRect.PriceHeight / realData.YesterdayEnd * 100) / 10;

            for (int i = -4; i <= 4; i++)
            {
                float horizonalPercent = (float)Math.Round(percent * i, 2);
                float price            = (float)Math.Round(realData.YesterdayEnd * (1 + horizonalPercent / 100), 2);
                float y = PriceMapping.CalcY(price);

                float x1 = FrameRect.X;
                float x2 = FrameRect.Right;
                g.DrawLine(pen2, x1, y, x2, y);
                Brush b;
                if (i < 0)
                {
                    b = ColorConfig.Brush_CandleBlockDown;
                }
                else if (i == 0)
                {
                    b = ColorConfig.Brush_CandleFlat;
                }
                else
                {
                    b = ColorConfig.Brush_CandleBlockUp;
                }
                Font   f    = ColorConfig.Font_CandleFrameScaleFont;
                String pstr = price.ToString();
                g.DrawString(pstr, f, b, x1 - pstr.Length * 6 - 4, y - 5);
                g.DrawString(horizonalPercent + "%", f, b, x2 + 2, y - 5);
            }
        }
Exemplo n.º 6
0
 public static void PrintTimeLineData(ITimeLineData timeLineData)
 {
     for (int i = 0; i < timeLineData.Length; i++)
     {
         Console.WriteLine(timeLineData.GetBar(i));
     }
 }
Exemplo n.º 7
0
        private void InitData()
        {
            int currentTradingDay = tradingDays[0];

            this.currentTickData = dataPackage.GetTickData(currentTradingDay);
            foreach (KLinePeriod period in dic_Period_KLineData.Keys)
            {
                IKLineData_RealTime klineData = dic_Period_KLineData[period];
                klineData.ChangeCurrentBar(GetKLineBar(currentTickData));
                if (period == forwardPeriod.KlineForwardPeriod)
                {
                    mainKlineData = klineData;
                }
            }

            //初始化分时线
            //int lastTradingDay = dataReader.TradingDayReader.GetPrevTradingDay(currentTradingDay);
            //IKLineData lastDayklineData = dataReader.KLineDataReader.GetData(code, lastTradingDay, lastTradingDay, KLinePeriod.KLinePeriod_1Day);
            //if (lastDayklineData.Length == 0)
            //    lastEndPrice = currentTickData.Arr_Price[0];
            //else
            //    lastEndPrice = lastDayklineData.End;
            this.lastEndPrice = dataPackage.GetLastEndPrice(currentTradingDay);
            if (useTimeLineData)
            {
                ITimeLineData timeLineData = dataPackage.GetTimeLineData(currentTradingDay);
                if (timeLineData != null)
                {
                    this.currentTimeLineData = new TimeLineData_RealTime(timeLineData);
                    this.currentTimeLineData.ChangeCurrentBar(GetTimeLineBar(currentTickData, lastEndPrice));
                }
            }
        }
Exemplo n.º 8
0
 public void ChangeData(TimeLineData timeLineData)
 {
     this.data = timeLineData;
     if (OnGraphicDataChange != null)
     {
         OnGraphicDataChange(this, new GraphicDataChangeArgument());
     }
 }
Exemplo n.º 9
0
        private void RefreshTimeLineDrawer()
        {
            ITimeLineData timeLineData = compDataController.CurrentRealTimeDataReader_Code.GetTimeLineData();

            this.graphicData_TimeLine         = GraphicDataFactory.CreateGraphicData_TimeLine(timeLineData);
            this.drawer_TimeLine.DataProvider = graphicData_TimeLine;
            this.graphicDrawer.Switch(1);
        }
Exemplo n.º 10
0
        private void TestGetTimeLineData(string code, int date)
        {
            IDataReader   dataReader   = DataReaderFactory.CreateDataReader(DataCenterUri.URI);
            ITimeLineData timeLineData = dataReader.TimeLineDataReader.GetData(code, date);

            AssertUtils.PrintTimeLineData(timeLineData);
            AssertUtils.AssertEqual_TimeLineData("TimeLineData_M05_20100108", GetType(), timeLineData);
        }
Exemplo n.º 11
0
 public DayNavigate(DataReaderFactory dataReaderFactory, string code, int date)
 {
     this.dataReaderFactory = dataReaderFactory;
     this.code         = code;
     this.date         = date;
     this.tickData     = dataReaderFactory.TickDataReader.GetTickData(code, date);
     this.timeLineData = dataReaderFactory.TimeLineDataReader.GetData(code, date);
 }
Exemplo n.º 12
0
        public override void Paint(Graphics graphic)
        {
            this.BlockWidth = this.DisplayRect.Width / (DataProvider.GetRealData().Length - 1);
            ITimeLineData realData = DataProvider.GetRealData();

            DrawFrame(graphic, realData);
            DrawReal(graphic, realData);
        }
Exemplo n.º 13
0
        public override void DrawGraph(Graphics graphic, Rectangle rect)
        {
            //TODO 只画区块
            this.BlockWidth = this.DisplayRect.Width / (DataProvider.GetRealData().Length - 1);
            ITimeLineData realData = DataProvider.GetRealData();

            DrawFrame(graphic, realData);
            DrawReal(graphic, realData);
        }
Exemplo n.º 14
0
        private int GetHoldAdd(int index)
        {
            ITimeLineData data = drawer.DataProvider.GetRealData();

            if (index == 0)
            {
                return(data.Arr_Hold[0]);
            }
            return(data.Arr_Hold[index] - data.Arr_Hold[index - 1]);
        }
Exemplo n.º 15
0
 public static void AssertEqual_TimeLineData(string expectedResult, ITimeLineData timeLineData)
 {
     string[] periodArr = expectedResult.Split('\r');
     Assert.AreEqual(periodArr.Length, timeLineData.Length);
     for (int i = 0; i < timeLineData.Length; i++)
     {
         string periodStr = periodArr[i].Trim();
         Assert.AreEqual(periodStr, timeLineData.GetBar(i).ToString());
     }
 }
Exemplo n.º 16
0
 public TimeLineData_RealTime(ITimeLineData timeLineData)
 {
     this.timeLineData   = timeLineData;
     this.list_time      = new ReadOnlyList_TmpValue <double>(timeLineData.Arr_Time);
     this.list_price     = new ReadOnlyList_TmpValue <float>(timeLineData.Arr_Price);
     this.list_mount     = new ReadOnlyList_TmpValue <int>(timeLineData.Arr_Mount);
     this.list_hold      = new ReadOnlyList_TmpValue <int>(timeLineData.Arr_Hold);
     this.list_upPercent = new ReadOnlyList_TmpValue <float>(timeLineData.Arr_UpPercent);
     this.list_upRange   = new ReadOnlyList_TmpValue <float>(timeLineData.Arr_UpRange);
 }
        private static void PrintOnBar(IDataForward_Code klineDataForward)
        {
            Console.WriteLine("tick:" + klineDataForward.GetTickData());
            Console.WriteLine("1minute:" + klineDataForward.GetKLineData(KLinePeriod.KLinePeriod_1Minute));
            Console.WriteLine("5minute:" + klineDataForward.GetKLineData(KLinePeriod.KLinePeriod_5Minute));
            Console.WriteLine("15minute:" + klineDataForward.GetKLineData(KLinePeriod.KLinePeriod_15Minute));
            Console.WriteLine("1day:" + klineDataForward.GetKLineData(KLinePeriod.KLinePeriod_1Day));
            ITimeLineData timeLineData = klineDataForward.GetTimeLineData();

            Console.WriteLine("timeline:" + timeLineData);
        }
Exemplo n.º 18
0
        private void DrawFrame(Graphics g, ITimeLineData realData)
        {
            Rectangle rectangleScale = FrameRect;
            Pen       pen            = this.ColorConfig.Pen_FrameLine;

            pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
            g.DrawRectangle(pen, rectangleScale);

            DrawVerticals(g, realData);
            DrawHorizonal(g, realData);
        }
Exemplo n.º 19
0
 public static void Save(string path, ITimeLineData data)
 {
     string[] contents = new string[data.Length + 1];
     contents[0] = data.YesterdayEnd.ToString();
     for (int i = 1; i < contents.Length; i++)
     {
         data.BarPos = i - 1;
         contents[i] = data.ToString();
     }
     FileUtils.EnsureParentDirExist(path);
     File.WriteAllLines(path, contents);
 }
Exemplo n.º 20
0
        private GraphicDrawer_TimeLine InitGraphicDrawer_TimeLine()
        {
            this.drawer_TimeLine = new GraphicDrawer_TimeLine();
            ITimeLineData timeLineData = compDataController.CurrentRealTimeDataReader_Code.GetTimeLineData();

            int barPos = TimeIndeierUtils.IndexOfTime_TimeLine(timeLineData, compData.Time);

            timeLineData.BarPos = barPos;

            this.graphicData_TimeLine    = GraphicDataFactory.CreateGraphicData_TimeLine(timeLineData);
            drawer_TimeLine.DataProvider = graphicData_TimeLine;
            return(this.drawer_TimeLine);
        }
Exemplo n.º 21
0
        private void DrawMount(Graphics g, ITimeLineData realData)
        {
            Pen pen = ColorConfig.Pen_Line_RealMount;

            for (int i = 0; i <= DataProvider.CurrentIndex; i++)
            {
                int   mount = realData.Arr_Mount[i];
                float x     = PriceMapping.CalcX(i);
                float y1    = priceMapping.DrawRect.Bottom;
                float y2    = PriceMapping.CalcY(mount);
                g.DrawLine(pen, x, y1, x, y2);
            }
        }
        private void HistoryDataForward_OnTick(object sender, IForwardOnTickArgument argument)
        {
            Console.WriteLine(code + ":" + argument.TickInfo.TickBar);
            Console.WriteLine(code2 + ":" + argument.GetOtherData(code2).GetTickData());
            Console.WriteLine(code2 + ":" + argument.GetOtherData(code2).GetKLineData(KLinePeriod.KLinePeriod_1Minute));
            Console.WriteLine(code2 + ":" + argument.GetOtherData(code2).GetTimeLineData());

            ITickData     tickData     = argument.GetOtherData(code2).GetTickData();
            IKLineData    klineData    = argument.GetOtherData(code2).GetKLineData(KLinePeriod.KLinePeriod_1Minute);
            ITimeLineData timeLineData = argument.GetOtherData(code2).GetTimeLineData();

            Assert.AreEqual(tickData.Price, klineData.End);
            Assert.AreEqual(tickData.Price, timeLineData.Price);
        }
Exemplo n.º 23
0
        private CurrentInfo GetCurrentInfo(ITickData tick)
        {
            CurrentInfo chartinfo = new CurrentInfo();

            chartinfo.code = this.chartComponentController.ChartComponentData.Code;
            if (tick == null)
            {
                return(chartinfo);
            }
            //ITickData tick = null;
            //CurrentInfo chartinfo = new CurrentInfo();
            ////ITickData tick = navigate.CurrentTickData;
            ITickBar tickBar = tick.GetCurrentBar();

            //////List<RealDataInfo> reals = currentInfo.GetReal();
            //////List<ChartInfo> charts = currentInfo.GetChart(ChartPeriod.DAY, 1);
            ////ITickBar tickChart = tick.GetBar(navigate.CurrentTickIndex);
            chartinfo.currentPrice = Math.Round(tick.Price, 2);
            chartinfo.currentHand  = tickBar.Mount;
            chartinfo.totalHand    = tickBar.TotalMount;
            chartinfo.totalHold    = tickBar.Hold;
            chartinfo.dailyAdd     = 0;
            chartinfo.outMount     = 0;
            chartinfo.outPercent   = 0.5;
            chartinfo.inMount      = 0;
            chartinfo.inPercent    = 0.5;

            //////RealDataInfo r = reals[reals.Count - 1];
            //////ChartInfo chart = charts[0];
            ITimeLineData realData = chartComponentController.CurrentRealTimeDataReader_Code.GetTimeLineData();

            if (realData != null)
            {
                ITimeLineBar realChart = realData.GetCurrentBar();
                chartinfo.upRange   = Math.Round(realChart.UpRange, 2);
                chartinfo.upPercent = realChart.UpPercent;
                chartinfo.upSpeed   = 0;
            }
            //chartinfo.open = realData.StartPrice;
            //chartinfo.high = chart.HighPrice;
            //chartinfo.low = chart.LowPrice;
            ////chartinfo.jsPrice = 0;
            ////chartinfo.lastJsPrice = Math.Round(r.LastJs, 2);
            ////double maxUprange = (int)(r.LastJs * 0.04);
            ////chartinfo.maxUp = r.LastJs + maxUprange;
            ////chartinfo.maxDown = r.LastJs - maxUprange;
            ////return chartinfo;
            //return chartinfo;
            return(chartinfo);
        }
Exemplo n.º 24
0
        public SelectedPointInfo GetBlockInfo(int index, int timeIndex)
        {
            ITimeLineData data = drawer.DataProvider.GetRealData();

            SelectedPointInfo info = new SelectedPointInfo();

            info.LineHeight = 20;
            info.Width      = 58;
            info.StartPoint = new Point(drawer.DisplayRect.X - info.Width, drawer.DisplayRect.Y);

            Brush brushNormal = new SolidBrush(Color.White);
            Font  font        = new Font("New Times Roman", 10, FontStyle.Regular);
            Brush brushRed    = drawer.ColorConfig.Brush_CandleBlockUp;
            Brush brushGreen  = drawer.ColorConfig.Brush_CandleBlockDown;

            //TODO
            info.Lines.Add(new BlockLineInfo("----", new SolidBrush(ColorUtils.GetColor("#CCCC00")), font));
            info.Lines.Add(new BlockLineInfo("时间", brushNormal, font));
            info.Lines.Add(new BlockLineInfo(GetTimeString(data.Arr_Time[timeIndex]), brushNormal, font));
            info.Lines.Add(new BlockLineInfo("价格", brushNormal, font));
            info.Lines.Add(new BlockLineInfo(data.Arr_Price[index].ToString(), brushNormal, font));
            info.Lines.Add(new BlockLineInfo("均价", brushNormal, font));
            //TODO
            info.Lines.Add(new BlockLineInfo("----", brushNormal, font));
            info.Lines.Add(new BlockLineInfo("涨跌", brushNormal, font));
            info.Lines.Add(new BlockLineInfo(data.Arr_UpRange[index].ToString(), brushNormal, font));
            info.Lines.Add(new BlockLineInfo((data.Arr_UpPercent[index] + "%").ToString(), brushNormal, font));
            info.Lines.Add(new BlockLineInfo("量", brushNormal, font));
            info.Lines.Add(new BlockLineInfo(data.Arr_Mount[index].ToString(), brushNormal, font));
            info.Lines.Add(new BlockLineInfo("持仓", brushNormal, font));
            info.Lines.Add(new BlockLineInfo(data.Arr_Hold[index].ToString(), brushNormal, font));
            int   add = GetHoldAdd(index);
            Brush b;

            if (index == 0 || add == 0)
            {
                b = brushNormal;
            }
            else if (add > 0)
            {
                b = brushRed;
            }
            else
            {
                b = brushGreen;
            }
            info.Lines.Add(new BlockLineInfo(add.ToString(), b, font));
            return(info);
        }
Exemplo n.º 25
0
 public ITimeLineData GetRealData()
 {
     if (realData == null)
     {
         lock (lockObj_Real)
         {
             if (realData == null)
             {
                 realData = DataTransfer_KLine2TimeLine.ConvertTimeLineData(minuteKLineData, lastEndPrice);
             }
         }
     }
     //TODO realdata是可以被修改的,所以此处线程不安全
     //应该给IRealData提供两个实现,一个是静态的,一个是动态的,缓存静态的实现,给外部生成时提供动态实现。
     return(realData);
 }
Exemplo n.º 26
0
 public DataNavigater_Code_KLinePeriod(IDataPackage_Code dataPackage, IList <KLinePeriod> periods, KLinePeriod mainKLinePeriod, bool useTimeLineData)
 {
     this.code                 = dataPackage.Code;
     this.periods              = periods;
     this.dataPackage          = dataPackage;
     this.dic_Period_KLineData = this.dataPackage.CreateKLineData_RealTimes(periods);
     this.mainKLineData        = this.dic_Period_KLineData[mainKLinePeriod];
     this.currentTradingDay    = dataPackage.StartDate;
     this.useTimeLineData      = useTimeLineData;
     if (useTimeLineData)
     {
         this.timeLineData = dataPackage.GetTimeLineData(dataPackage.StartDate);
     }
     this.forwardPeriod = new ForwardPeriod(false, mainKLineData.Period);
     this.onBarArgument = new ForwardOnBarArgument(this.barFinishedInfos);
     InitKLine();
 }
Exemplo n.º 27
0
        private PriceRectangle GetPriceRectangle()
        {
            ITimeLineData realData   = DataProvider.GetRealData();
            int           startIndex = 0;
            int           endIndex   = DataProvider.CurrentIndex;

            float mountTop = realData.Arr_Mount[startIndex];

            for (int i = startIndex + 1; i <= endIndex; i++)
            {
                if (mountTop < realData.Arr_Mount[i])
                {
                    mountTop = realData.Arr_Mount[i];
                }
            }

            return(new PriceRectangle(startIndex, realData.Length - 1, mountTop, 0));
        }
Exemplo n.º 28
0
        public void TestRealDataReader_GetData()
        {
            DataReaderFactory   fac      = ResourceLoader.GetDefaultDataReaderFactory();
            IRealTimeDataReader reader   = new RealTimeDataReader(fac, "m05", 20100104.093002);
            ITickData           tickData = reader.GetTickData();

            Console.WriteLine(tickData);
            Assert.AreEqual("20100104.093002,3127,2,44492,0,3127,25,3128,173,0", tickData.ToString());
            IKLineData klineData = reader.GetKLineData(KLinePeriod.KLinePeriod_15Minute);

            Console.WriteLine(klineData);
            Assert.AreEqual("20100104.093,3127,3127,3127,3127,40,0,523048", klineData.ToString());

            ITimeLineData timeLineData = reader.GetTimeLineData();

            Console.WriteLine(timeLineData);
            Assert.AreEqual("20100104.093,3127,11,0.35,40,524676", timeLineData.ToString());
        }
Exemplo n.º 29
0
        public void TestTimeLineToKLine()
        {
            string code  = "RB1710";
            int    start = 20170601;
            int    end   = 20170605;

            IDataPackage_Code datapackage = DataCenter.Default.DataPackageFactory.CreateDataPackage_Code(code, start, end, 0, 0);
            IKLineData_Extend klineData   = datapackage.GetKLineData(KLinePeriod.KLinePeriod_1Minute);
            //IKLineData_Extend klineData = datapackage.GetKLineData(KLinePeriod.KLinePeriod_5Minute);
            IList <int>            tradingDays  = datapackage.GetTradingDays();
            ITimeLineData          timeLineData = datapackage.GetTimeLineData(tradingDays[0]);
            TimeLineToKLineIndeier indeier      = new TimeLineToKLineIndeier(klineData, timeLineData);

            int  tradingDayIndex = 0;
            bool isFirst         = true;

            for (int i = klineData.BarPos; i < klineData.Length; i++)
            {
                if (!isFirst && klineData.IsDayStart(i))
                {
                    tradingDayIndex++;
                    if (tradingDayIndex >= tradingDays.Count)
                    {
                        return;
                    }
                    timeLineData = datapackage.GetTimeLineData(tradingDays[tradingDayIndex]);
                    indeier.ChangeTradingDay(timeLineData);
                }
                isFirst          = false;
                klineData.BarPos = i;
                Console.WriteLine(klineData.Period + ":" + klineData.GetBar(i));
                int barPos = indeier.GetTimeLineBarPosIfFinished(i);
                if (barPos >= 0)
                {
                    timeLineData.BarPos = barPos;
                    Console.WriteLine("分时线:" + timeLineData.GetBar(barPos));
                }
                Assert.AreEqual(klineData.Time, timeLineData.Time);
                Assert.AreEqual(klineData.End, timeLineData.Price);
            }
        }
Exemplo n.º 30
0
        public ITimeLineData GetRealData(string code, int date)
        {
            DayDataKey key = new DayDataKey(code, date);

            if (dicRealData.ContainsKey(key))
            {
                return(dicRealData[key]);
            }

            ITimeLineData realdata = dataReaderFac.TimeLineDataReader.GetData(code, date);

            if (keies.Count > 10)
            {
                DayDataKey firstKey = keies[0];
                keies.RemoveAt(0);
                dicRealData.Remove(firstKey);
                keies.Add(key);
                dicRealData.Add(key, realdata);
            }
            return(realdata);
        }