コード例 #1
0
        /*
         * private StockMeta BuildStockObject(JToken meta)
         * {
         *  StockMeta result = new StockMeta();
         *  result.Infomation = meta[Constant.INFORMATION].ToString();
         *  result.Date = meta[Constant.DATE].ToString();
         *  result.Symbol = meta[Constant.SYMBOL].ToString();
         *  return result;
         * }
         */
        /// <summary>
        /// Based on the original json data, we build the stockMeta object data points. This will be the datasource for the later on drawing
        /// </summary>
        /// <param name="result"></param>
        /// <param name="data"></param>
        /// <param name="SMA_10"></param>
        /// <param name="SMA_50"></param>
        /// <param name="SMA_200"></param>
        /// <param name="Type"></param>

        private void AddStockMajorDataToStockObject(ref StockMeta result, JObject data, JObject SMA_10, JObject SMA_50, JObject SMA_200, string Type)
        {
            var meta = data[Constant.METADATA];
            List <StockPoint> points = new List <StockPoint>();
            var dataPoints           = data[Type];
            IEnumerable <JProperty> dataPoints_SMA_10  = new JObject().OfType <JProperty>();
            IEnumerable <JProperty> dataPoints_SMA_50  = new JObject().OfType <JProperty>();
            IEnumerable <JProperty> dataPoints_SMA_200 = new JObject().OfType <JProperty>();

            if (_memuSetting.ChartSettings["SMA10"])
            {
                dataPoints_SMA_10 = SMA_10[Constant.SMAKEY].OfType <JProperty>();
            }
            if (_memuSetting.ChartSettings["SMA50"])
            {
                dataPoints_SMA_50 = SMA_50[Constant.SMAKEY].OfType <JProperty>();
            }
            if (_memuSetting.ChartSettings["SMA200"])
            {
                dataPoints_SMA_200 = SMA_200[Constant.SMAKEY].OfType <JProperty>();
            }
            int i = 0;  ///for current stage, just hard coded 100 points

            foreach (JProperty point in dataPoints.OfType <JProperty>())
            {
                StockPoint tmp = new StockPoint();
                tmp.Date       = point.Name.ToString();
                tmp.OpenPrice  = GeneralTools.StringParser(point.Value[Constant.OPENPRICE].ToString());
                tmp.ClosePrice = GeneralTools.StringParser(point.Value[Constant.CLOSEPRICE].ToString());
                tmp.HighPrice  = GeneralTools.StringParser(point.Value[Constant.HIGHPRICE].ToString());
                tmp.LowPrice   = GeneralTools.StringParser(point.Value[Constant.LOWPRICE].ToString());
                tmp.Volume     = Int32.Parse(point.Value[Constant.VOLUME].ToString());
                if (_memuSetting.ChartSettings["SMA10"])
                {
                    tmp.SMA_10 = ParseValue("", dataPoints_SMA_10, Constant.SMA, i, 1);
                }
                if (_memuSetting.ChartSettings["SMA50"])
                {
                    tmp.SMA_50 = ParseValue("", dataPoints_SMA_50, Constant.SMA, i, 1);
                }
                if (_memuSetting.ChartSettings["SMA200"])
                {
                    tmp.SMA_200 = ParseValue("", dataPoints_SMA_200, Constant.SMA, i, 1);
                }
                points.Add(tmp);
                i++;
                if (i >= 100)
                {
                    break;
                }
            }
            result.Infomation = meta[Constant.INFORMATION].ToString();
            result.Date       = meta[Constant.DATE].ToString();
            result.Symbol     = meta[Constant.SYMBOL].ToString();
            result.Charts[Constant.ChartMapper[Type]] = points;
        }
コード例 #2
0
        public void AddRSIDataToStockObject(ref StockMeta result, string symbol, string Type)
        {
            var data         = GetRSIData(symbol, Type);
            var dataPoints   = data[Constant.RSIKEY].OfType <JProperty>();
            var resultPoints = result.Charts[Constant.ChartMapper[Type]];
            int i            = 0;

            foreach (JProperty point in dataPoints)
            {
                resultPoints[i].RSI = GeneralTools.StringParser(point.Value[Constant.RSI].ToString());
                i++;
                if (i >= resultPoints.Count)
                {
                    break;
                }
            }
        }
コード例 #3
0
        public void AddAROONDataToStockObject(ref StockSummary result, string symbol)
        {
            var           data        = GetAROONData(symbol);
            var           dataPoints  = data[Constant.AROONKEY].OfType <JProperty>();
            List <double> AROONValues = new List <double>();
            int           i           = 0;

            foreach (JProperty point in dataPoints)
            {
                AROONValues.Add(GeneralTools.StringParser(point.Value[Constant.AROON].ToString()));
                if (i >= 200)
                {
                    break;
                }
                i++;
            }
            result.CacheData.Add(Constant.AROONKEY, AROONValues);
        }
コード例 #4
0
        private double VolumeStringToVolume(string volume)
        {
            var length     = volume.Length;
            int multipiler = 1;

            if (volume[length - 1] == 'M')
            {
                multipiler = 1000000;
            }
            else if (volume[length - 1] == 'K')
            {
                multipiler = 1000;
            }
            else
            {
                return(GeneralTools.StringParser(volume));
            }
            return(GeneralTools.StringParser(volume.Substring(0, length - 1)) * multipiler);
        }
コード例 #5
0
        private void AddStockMajorDataToStockSummary(ref StockSummary result)
        {
            string            req        = GeneralTools.NetworkRequestStringBuilder(result.Symbol, Constant.DAILY, Constant.QUERY_FUNCTION_VALUE_DAILY, string.Empty, string.Empty, _apiKey[0]);
            var               stockData  = OriginalStockData(req);
            var               dataPoints = stockData[Constant.DAILYCHART];
            List <StockPoint> points     = new List <StockPoint>();

            foreach (JProperty point in dataPoints.OfType <JProperty>())
            {
                StockPoint tmp = new StockPoint();
                tmp.Date       = point.Name.ToString();
                tmp.OpenPrice  = GeneralTools.StringParser(point.Value[Constant.OPENPRICE].ToString());
                tmp.ClosePrice = GeneralTools.StringParser(point.Value[Constant.CLOSEPRICE].ToString());
                tmp.HighPrice  = GeneralTools.StringParser(point.Value[Constant.HIGHPRICE].ToString());
                tmp.LowPrice   = GeneralTools.StringParser(point.Value[Constant.LOWPRICE].ToString());
                tmp.Volume     = Int32.Parse(point.Value[Constant.VOLUME].ToString());
                points.Add(tmp);
            }
            result.CacheData.Add(Constant.DAILYCHART, points);
        }
コード例 #6
0
        /// <summary>
        /// currently 0 -> MACD; 1->RSI
        /// </summary>
        /// <param name="canvas"></param>
        /// <param name="y_count"></param>
        /// <param name="type"></param>
        public void DrawMACDToCanvas(ref Canvas canvas, int y_count)
        {
            double ymid  = canvas.Height / 2;
            double xmin  = marginX;
            double xmax  = canvas.Width - marginX;
            double stepX = (xmax - xmin) / (x_count - 1);
            double stepY = canvas.Height / (y_count - 1);

            BuilderTools.Axis(ref canvas, xmin, xmax, ymid, ymid, x_count, 0, datesAxisKeypoint, 1, Brushes.Black);
            BuilderTools.Axis(ref canvas, xmin, xmin, 0, 2 * ymid, y_count, 1, MACDAxisKeypoint, 1, Brushes.Black);

            var lowVal   = GeneralTools.StringParser(MACDAxisKeypoint.First());
            var highVal  = GeneralTools.StringParser(MACDAxisKeypoint.Last());
            var MACDPath = GetMACDChartPath(xmin, ymid, stepX, stepY, lowVal, highVal);

            foreach (var path in MACDPath)
            {
                canvas.Children.Add(path);
            }

            canvas.MouseDown += new MouseButtonEventHandler(AddPointInfo);
            canvas.MouseUp   += new MouseButtonEventHandler(RemovePointInfo);
        }
コード例 #7
0
        /// <summary>
        /// Draw the X,Y axis of the Stock snapshot,  To build up the main stock chart
        /// </summary>
        /// <param name="canvas"></param>
        public void DrawStockMajorToCanvas(ref Canvas canvas)
        {
            double xmin  = marginX;
            double xmax  = width - marginX;
            double ymin  = marginY;
            double ymax  = height - marginY;
            double stepX = (xmax - xmin) / (x_count - 1);
            double stepY = (ymax - ymin) / (y_count - 1);

            BuilderTools.Axis(ref canvas, xmin, xmax, ymax, ymax, x_count, 0, datesAxisKeypoint, 1, Brushes.Black);   // build x
            BuilderTools.Axis(ref canvas, xmin, xmin, ymin, ymax, y_count, 1, pricesAxisKeypoint, 1, Brushes.Black);  //build y1 for price
            BuilderTools.Axis(ref canvas, xmax, xmax, ymin, ymax, y_count, 1, volumesAxisKeypoint, 1, Brushes.Black); // build y2 for volume
            var points = stockData.Charts[Constant.ChartMapper[type]];

            if (menuSetting.ChartSettings["CHARTTYPE"])
            {
                var stockPath = BuilderTools.LineChart(xmin, ymin, ymax, stepX, stepY, points.Select(p => p.ClosePrice).ToList(), 0, GeneralTools.StringParser(pricesAxisKeypoint[0]), GeneralTools.StringParser(pricesAxisKeypoint.Last()), 1, Brushes.Blue, false);
                canvas.Children.Add(stockPath);
            }
            else
            {
                var stockPath = BuilderTools.CandleChart(xmin, ymin, ymax, stepX, stepY, points.Select(p => p.OpenPrice).ToList(), points.Select(p => p.ClosePrice).ToList(), points.Select(p => p.HighPrice).ToList(), points.Select(p => p.LowPrice).ToList(), 0, GeneralTools.StringParser(pricesAxisKeypoint[0]), GeneralTools.StringParser(pricesAxisKeypoint.Last()), 1, Brushes.Blue, false);
                foreach (var p in stockPath)
                {
                    canvas.Children.Add(p);
                }
            }
            if (menuSetting.ChartSettings["SMA10"])
            {
                var sma_10 = BuilderTools.LineChart(xmin, ymin, ymax, stepX, stepY, points.Select(p => p.SMA_10).ToList(), 0, GeneralTools.StringParser(pricesAxisKeypoint[0]), GeneralTools.StringParser(pricesAxisKeypoint.Last()), 2, Brushes.Green, true);
                canvas.Children.Add(sma_10);
            }
            if (menuSetting.ChartSettings["SMA50"])
            {
                var sma_50 = BuilderTools.LineChart(xmin, ymin, ymax, stepX, stepY, points.Select(p => p.SMA_50).ToList(), 0, GeneralTools.StringParser(pricesAxisKeypoint[0]), GeneralTools.StringParser(pricesAxisKeypoint.Last()), 2, Brushes.DarkSeaGreen, true);
                canvas.Children.Add(sma_50);
            }
            if (menuSetting.ChartSettings["SMA200"])
            {
                var sma_200 = BuilderTools.LineChart(xmin, ymin, ymax, stepX, stepY, points.Select(p => p.SMA_200).ToList(), 0, GeneralTools.StringParser(pricesAxisKeypoint[0]), GeneralTools.StringParser(pricesAxisKeypoint.Last()), 2, Brushes.Blue, true);
                canvas.Children.Add(sma_200);
            }

            //start to draw stock
            if (menuSetting.ChartSettings["VOLUME"])
            {
                var volumePath = GetVolumeChartPath(xmin, ymin, ymax, stepX, stepY, VolumeStringToVolume(volumesAxisKeypoint.Last()));
                canvas.Children.Add(volumePath);
            }
            if (menuSetting.ChartSettings["TREND"] && menuSetting.ChartType == Constant.DAILYCHART)
            {
                var TrendPath = GetTrendLineChartPath(xmin, ymin, ymax, stepX, stepY, GeneralTools.StringParser(pricesAxisKeypoint[0]), GeneralTools.StringParser(pricesAxisKeypoint.Last()), 2, Brushes.LightBlue, false);
                canvas.Children.Add(TrendPath[0]);
                canvas.Children.Add(TrendPath[1]);
            }
            canvas.MouseDown += new MouseButtonEventHandler(AddPointInfo);
            canvas.MouseUp   += new MouseButtonEventHandler(RemovePointInfo);
        }