Exemplo n.º 1
0
        /// <summary>
        /// @"Token\Pair\BID\OFFER\HIGH\LOW\STATUS\NOTATION\DECIMALS\CLOSINGBID", @"\");
        /// </summary>
        /// <param name="data"></param>
        /// <param name="dateTimeFormat"></param>
        /// <returns></returns>
        public Rate ToRateOnConnect(string data, ref TickTime origin)
        {
            if (System.String.IsNullOrEmpty(data) || data.Length < 10)
            {
                return(null);
            }

            //Ignore token, might be corrupted
            string[] properties = Asmodat.Abbreviate.String.ToList(data, "\\");
            if (properties.Length != 10)
            {
                return(null);
            }


            string status   = properties[6];
            string notation = properties[7];

            if (status != "D" && status != "R")
            {
                return(null);
            }

            if (notation != "E" && notation != "A")
            {
                return(null);
            }

            Rate rate = new Rate();

            try
            {
                rate.Pair       = properties[1];
                rate.DECIMALS   = ForexConfiguration.GetDecimals(rate.Pair);
                rate.BID        = Doubles.Parse(properties[2], rate.DECIMALS);
                rate.OFFER      = Doubles.Parse(properties[3], rate.DECIMALS);
                rate.HIGH       = Doubles.Parse(properties[4], rate.DECIMALS);
                rate.LOW        = Doubles.Parse(properties[5], rate.DECIMALS);
                rate.STATUS     = status;
                rate.NOTATION   = notation;
                rate.CLOSINGBID = Doubles.Parse(properties[8], rate.DECIMALS);

                rate.ChartData.TickTime = (origin += 1);


                //backtest
                double pchange = RateInfo.ChangePercentage(rate.BID, rate.OFFER, rate.HIGH, rate.LOW);
                if (pchange < 25)
                {
                    return(null);
                }
            }
            catch (Exception e)
            {
                Exceptions.Add(e);
                return(null);
            }

            return(rate);
        }
Exemplo n.º 2
0
        /// <summary>
        /// @"DateTime\OPEN\HIGH\LOW\CLOSE"
        /// Example: "2/18/2015 5:45:00 PM\\119.220\\119.228\\119.220\\119.227"
        /// DateTime.ParseExact(SLDecodedData[i], "M/d/yyyy h:mm:ss tt", CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None);
        /// separator - \\
        /// </summary>
        /// <param name="data"></param>
        /// <param name="decimals"></param>
        /// <returns></returns>
        public Rate ToRateChartData(string pair, string data, int decimals)
        {
            if (System.String.IsNullOrEmpty(data) || data.Length < 5)
            {
                return(null);
            }

            string[] properties = Asmodat.Abbreviate.String.ToList(data, "\\");

            if (properties.Length != 5)
            {
                throw new Exception("ServiceCharting.DecodeRates Amount of separators don't match Rate Format !");
            }

            if (Asmodat.Abbreviate.String.IsNullOrEmpty(properties))
            {
                throw new Exception("ServiceCharting.DecodeRates Amount properties cannot be null !");
            }

            Rate rate = new Rate();

            try
            {
                rate.Pair     = pair;
                rate.DateTime = DateTime.ParseExact(properties[0], "M/d/yyyy h:mm:ss tt", CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None);
                //"4/3/2015 12:00:00 AM\\16.76\\17.058\\16.683\\17.033"
                rate.OPEN  = Doubles.Parse(properties[1], decimals);
                rate.HIGH  = Doubles.Parse(properties[2], decimals);
                rate.LOW   = Doubles.Parse(properties[3], decimals);
                rate.CLOSE = Doubles.Parse(properties[4], decimals);

                //backtest
                double pchange = RateInfo.ChangePercentage(rate.OPEN, rate.HIGH, rate.LOW, rate.CLOSE);


                if (pchange < 1.5)
                {
                    return(null);
                }

                if (pchange < 25)
                {
                    pchange = 25;
                }
            }
            catch (Exception e)
            {
                Exceptions.Add(e);
                return(null);
            }
            return(rate);
        }
Exemplo n.º 3
0
        private double FixIt(Rate current_rate, double previous, double current)
        {
            //int ptl = Math.Truncate(previous).ToString().Length;
            //int ctl = Math.Truncate(current).ToString().Length;
            int    decimals = current_rate.DECIMALS;
            double pchange  = RateInfo.ChangePercentage(previous, current);



            if (pchange < 25)//ptl > ctl + 1 ||
            {
                //double parse = Doubles.Parse(value, decimals);

                return(current);
            }

            return(current);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Converts string data into Rate property
        /// Example rate: "EUR/USD\\1.17684\\1.17701\\D\\1.18485\\1.17619\\5\\A\\1.18385\\EUR/USD\\EUR/USD$"
        /// Example data: "Pair\BID\OFFER\STATUS\HIGH\LOW\DECIMALS\NOTATION\CLOSINGBID\CONTRACTPAIR\COUNTERPAIR$"
        ///              @"Pair\BID\OFFER\STATUS\HIGH\LOW\DECIMALS\NOTATION\CLOSINGBID\CONTRACTPAIR\COUNTERPAIR\DateTime\Token\OPEN\CLOSE", @"\");
        /// </summary>
        /// <param name="getRateString">Sting formattes as: Pair\BID\OFFER\STATUS\HIGH\LOW\DECIMALS\NOTATION\CLOSINGBID\CONTRACTPAIR\COUNTERPAIR$ without $ char</param>
        /// <returns>Rate based on string input.</returns>
        private Rate ToRate(string data, ref TickTime origin)
        {
            if (System.String.IsNullOrEmpty(data) || data.Length < 11)
            {
                return(null);
            }

            data = data.Replace("$", "");


            string[] properties = Asmodat.Abbreviate.String.ToList(data, "\\");
            if (properties.Length != 11)
            {
                return(null);
            }

            string status   = properties[3];
            string notation = properties[7];

            if (status != "D" && status != "R")
            {
                return(null);
            }

            if (notation != "E" && notation != "A")
            {
                return(null);
            }


            Rate rate = new Rate();

            try
            {
                rate.Pair     = properties[0];
                rate.DECIMALS = int.Parse(properties[6]);

                if (rate.DECIMALS != ForexConfiguration.GetDecimals(rate.Pair))
                {
                    return(null);
                }

                rate.BID      = Doubles.Parse(properties[1], rate.DECIMALS);
                rate.OFFER    = Doubles.Parse(properties[2], rate.DECIMALS);
                rate.STATUS   = status;
                rate.NOTATION = notation;
                //rate.HIGH = Doubles.Parse(properties[4], rate.DECIMALS);
                //rate.LOW = Doubles.Parse(properties[5], rate.DECIMALS);
                //rate.CLOSINGBID = Doubles.Parse(properties[8], rate.DECIMALS);
                //rate.CONTRACTPAIR = properties[9];
                //rate.COUNTERPAIR = properties[10];

                rate.ChartData.TickTime = (origin += 1);

                //backtest
                double pchange = RateInfo.ChangePercentage(rate.BID, rate.OFFER);
                if (pchange < 25)
                {
                    return(null);
                }
            }
            catch (Exception e)
            {
                Exceptions.Add(e);
                return(null);
            }
            return(rate);
        }
Exemplo n.º 5
0
        /// <summary>
        /// @"Token\BID\OFFER\\\\\"
        /// "R27\\89.514\\89.549\\D\\\\\\02/19/2015 09:25:55\\"
        /// TimeZoneInfo.ConvertTime(DateTime.Now, TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time"));
        /// </summary>
        /// <param name="data"></param>
        /// <param name="dateTimeFormat"></param>
        /// <returns></returns>
        public Rate ToRateOnChange(string data, ref TickTime origin)
        {
            if (System.String.IsNullOrEmpty(data) || data.Length < 7)
            {
                return(null);
            }

            char cMessageType = data[0];

            if (!Char.IsLetter(cMessageType))
            {
                return(null);                          //This is not RateChange frame
            }
            data = data.Substring(1, data.Length - 1); //Remove Message Type Rate

            string[] properties = Asmodat.Abbreviate.String.ToList(data, "\\");
            if (properties.Length != 7)
            {
                return(null);
            }

            string status = properties[3];

            if (status != "D" && status != "R")
            {
                return(null);
            }

            Rate rate = new Rate();

            try
            {
                rate.Token    = int.Parse(properties[0]);
                rate.Pair     = ForexConfiguration.OrderPair[rate.Token];
                rate.DECIMALS = ForexConfiguration.GetDecimals(rate.Pair);



                rate.BID    = Doubles.Parse(properties[1], rate.DECIMALS);
                rate.OFFER  = Doubles.Parse(properties[2], rate.DECIMALS);
                rate.STATUS = status;

                rate.ChartData.TickTime = (origin += 1);

                //backtest
                double pchange = RateInfo.ChangePercentage(rate.BID, rate.OFFER);
                if (pchange < 50)
                {
                    return(null);
                }
            }
            catch (Exception e)
            {
                Exceptions.Add(e);
                return(null);
            }



            return(rate);
        }