/// <summary>
        /// Get the point to draw y axis
        /// </summary>
        /// <param name="stockData"></param>
        /// <param name="y_count"></param>
        /// <returns></returns>
        private List <string> GetMACDKeypointsForYAxis(StockMeta stockData, int y_count)
        {
            var    vals    = new List <string>();
            double lowVal  = Int32.MaxValue;
            double highVal = Int32.MinValue;
            var    points  = stockData.Charts[Constant.ChartMapper[type]];

            foreach (var point in points)
            {
                lowVal  = (lowVal > point.MACD_SIGNAL) ? point.MACD_SIGNAL : lowVal;
                highVal = (highVal < point.MACD_SIGNAL) ? point.MACD_SIGNAL : highVal;
            }
            double delta1 = (0 - lowVal) * priceOffset;
            double delta2 = highVal * priceOffset;

            highVal = highVal + delta2;
            lowVal  = lowVal - delta1;
            double step1 = (0 - lowVal) / (y_count / 2);
            double step2 = highVal / (y_count / 2);
            double start = lowVal;

            for (int i = 0; i < y_count; i++)
            {
                if (i < y_count / 2 + 1)
                {
                    vals.Add((start + i * step1).ToString());
                }
                else
                {
                    vals.Add(((i - (y_count / 2)) * step2).ToString());
                }
            }
            return(vals);
        }
예제 #2
0
        /// <summary>
        /// Based on the symbol and type, get the stockMeta object which include the metadata (symbol....) and the datapoint
        /// </summary>
        /// <param name="symbol"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public StockMeta FetchStockMajorDataObject(string symbol, string type)
        {
            StockMeta result = new StockMeta();
            JObject   stockData, stockDataSMA_1 = new JObject(), stockDataSMA_2 = new JObject(), stockDataSMA_3 = new JObject();
            string    req = GeneralTools.NetworkRequestStringBuilder(symbol, Constant.IntervalMapper[type], Constant.typeMapper[type], string.Empty, string.Empty, _apiKey[0]);

            stockData = OriginalStockData(req);
            if (_memuSetting.ChartSettings["SMA10"])
            {
                string req_s1 = GeneralTools.NetworkRequestStringBuilder(symbol, Constant.IntervalMapper[type], Constant.QUERY_FUNCTION_VALUE_SMA, "10", "close", _apiKey[0]);
                stockDataSMA_1 = OriginalStockData(req_s1);
            }
            if (_memuSetting.ChartSettings["SMA50"])
            {
                string req_s2 = GeneralTools.NetworkRequestStringBuilder(symbol, Constant.IntervalMapper[type], Constant.QUERY_FUNCTION_VALUE_SMA, "50", "close", _apiKey[0]);
                stockDataSMA_2 = OriginalStockData(req_s2);
            }
            if (_memuSetting.ChartSettings["SMA200"])
            {
                string req_s3 = GeneralTools.NetworkRequestStringBuilder(symbol, Constant.IntervalMapper[type], Constant.QUERY_FUNCTION_VALUE_SMA, "200", "close", _apiKey[0]);
                stockDataSMA_3 = OriginalStockData(req_s3);
            }
            //result = BuildStockObject(stockData[Constant.METADATA]);
            AddStockMajorDataToStockObject(ref result, stockData, stockDataSMA_1, stockDataSMA_2, stockDataSMA_3, type);
            return(result);
        }
        /// <summary>
        /// Get the point to draw y axis, give it "K" or "M" multiplier
        /// </summary>
        /// <param name="stockData"></param>
        /// <param name="y_count"></param>
        /// <returns></returns>
        private List <string> GetVolumeKeypointsForYAxis(StockMeta stockData, int y_count)
        {
            var    result     = new List <string>();
            double highVolume = 0;
            string Multiplier = "";
            int    divider    = 1;
            var    points     = stockData.Charts[Constant.ChartMapper[type]];
            int    length     = points.Count;

            for (int i = 0; i < length; i++)
            {
                highVolume = (highVolume < points[i].Volume) ? points[i].Volume : highVolume;
            }
            if (highVolume >= 1000000)
            {
                Multiplier = "K";
                divider    = 1000;
            }
            if (highVolume >= 100000000)
            {
                Multiplier = "M";
                divider    = 1000000;
            }
            highVolume = highVolume * volumeOffset / divider;
            double step = highVolume / (y_count - 1);

            for (int i = 0; i < y_count; i++)
            {
                result.Add((Math.Round(i * step, 2)).ToString() + Multiplier);
            }
            return(result);
        }
        /// <summary>
        /// Get the point to draw y axis
        /// </summary>
        /// <param name="stockData"></param>
        /// <param name="y_count"></param>
        /// <returns></returns>
        private List <string> GetPriceKeypointsForYAxis(StockMeta stockData, int y_count)
        {
            var    prices    = new List <string>();
            double lowPrice  = 9999;
            double highPrice = 0;
            var    points    = stockData.Charts[Constant.ChartMapper[type]];

            foreach (var point in points)
            {
                lowPrice  = (lowPrice > point.ClosePrice) ? point.ClosePrice : lowPrice;
                highPrice = (highPrice < point.ClosePrice) ? point.ClosePrice : highPrice;
            }
            double delta = (highPrice - lowPrice) * priceOffset;

            highPrice = highPrice + delta;
            lowPrice  = lowPrice - delta;
            double step  = (highPrice - lowPrice) / (y_count - 1);
            double start = lowPrice;

            for (int i = 0; i < y_count; i++)
            {
                prices.Add((start + i * step).ToString());
            }
            return(prices);
        }
        /// <summary>
        /// Get the date point to draw x axis
        /// </summary>
        /// <param name="stockData"></param>
        /// <returns></returns>
        private List <string> GetDateKeypointsForXAxis(StockMeta stockData)
        {
            var dates  = new List <string>();
            var points = stockData.Charts[Constant.ChartMapper[type]];

            if (type == Constant.DAILYCHART || type == Constant.WEEKLYCHART)
            {
                foreach (var point in points)
                {
                    var    tmp    = point.Date.Split('-');
                    string result = tmp[1] + "." + tmp[2];
                    dates.Add(result);
                }
            }
            else
            {
                foreach (var point in points)
                {
                    var    tmp    = point.Date.Split(':');
                    string result = tmp[0].Substring(11) + ":" + tmp[1];
                    dates.Add(result);
                }
            }
            return(dates);
        }
예제 #6
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;
        }
예제 #7
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;
                }
            }
        }
 /// <summary>
 /// reset the properties of builder object so that the canvas will get new data
 /// </summary>
 /// <param name="canvas"></param>
 /// <param name="x_count"></param>
 /// <param name="y_count"></param>
 /// <param name="marginX"></param>
 /// <param name="marginY"></param>
 /// <param name="priceOffset"></param>
 /// <param name="volumeOffset"></param>
 /// <param name="symbol"></param>
 /// <param name="type"></param>
 public void Refresh(ref Canvas canvas, int x_count, int y_count, int marginX, int marginY, double priceOffset, int volumeOffset, string symbol, string type)
 {
     canvas.Children.Clear();                                         // clean all old data
     canvas.MouseDown   -= new MouseButtonEventHandler(AddPointInfo); //clear event handler
     canvas.MouseUp     -= new MouseButtonEventHandler(RemovePointInfo);
     this.x_count        = x_count;
     this.y_count        = y_count;
     this.marginX        = marginX;
     this.marginY        = marginY;
     this.priceOffset    = priceOffset;
     this.volumeOffset   = volumeOffset;
     this.type           = type;
     this.stockData      = netReader.FetchStockMajorDataObject("ACB", type);
     datesAxisKeypoint   = GetDateKeypointsForXAxis(stockData);
     pricesAxisKeypoint  = GetPriceKeypointsForYAxis(stockData, y_count);
     volumesAxisKeypoint = GetVolumeKeypointsForYAxis(stockData, y_count);
     DrawStockMajorToCanvas(ref canvas);
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="canvas">canvas object</param>
 /// <param name="x_count">x axis key point number</param>
 /// <param name="y_count">y axis key point number</param>
 /// <param name="margin">coordinate margin</param>
 /// <param name="priceOffset">the percentage range above the highest price and below the lowest price</param>
 /// <param name="meta"></param>
 public CoordinateBuilder(Canvas canvas, MenuSetting menusettings, NetworkDataReader reader, SqlDataReader sqlReader, int x_count, int y_count, int marginX, int marginY, double priceOffset, int volumeOffset, string symbol, string type)
 {
     width               = canvas.Width;
     height              = canvas.Height;
     this.x_count        = x_count;
     this.y_count        = y_count;
     this.marginX        = marginX;
     this.marginY        = marginY;
     this.priceOffset    = priceOffset;
     this.volumeOffset   = volumeOffset;
     this.type           = type;
     netReader           = reader;
     this.sqlReader      = sqlReader;
     this.stockData      = netReader.FetchStockMajorDataObject("ACB", type);
     datesAxisKeypoint   = GetDateKeypointsForXAxis(stockData);
     pricesAxisKeypoint  = GetPriceKeypointsForYAxis(stockData, y_count);
     volumesAxisKeypoint = GetVolumeKeypointsForYAxis(stockData, y_count);
     this.menuSetting    = menusettings;
 }
예제 #10
0
 public void SetSelectStock(StockMeta selectStock) => _selectStock = selectStock;