Ejemplo n.º 1
0
        private List <Rate> DecodeRates(string packet, ref TickTime origin)
        {
            List <Rate> Rates = new List <Rate>();

            string[] DelimitedData = Asmodat.Abbreviate.String.ToList(packet, "$");
            if (DelimitedData == null)
            {
                return(Rates);
            }



            foreach (string data in DelimitedData)
            {
                Rate Rate = this.ToRate(data, ref origin);
                if (Rate != null)
                {
                    Rates.Add(Rate);
                }
            }

            return(Rates);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Decodes data and sets reciving time if origin != TickTime.MinValue
        /// </summary>
        /// <param name="packet"></param>
        /// <param name="origin"></param>
        /// <returns></returns>
        private List <Rate> DecodeRates(string packet, ref TickTime origin)
        {
            List <Rate> Rates = new List <Rate>();

            string[] DelimitedData = Asmodat.Abbreviate.String.ToList(packet, "$");
            if (DelimitedData == null)
            {
                return(Rates);
            }


            for (int i = 0; i < DelimitedData.Length; i++)
            {
                Rate Rate = this.ToRateOnConnect(DelimitedData[i], ref origin);

                if (Rate != null)
                {
                    Rates.Add(Rate);
                }
            }

            return(Rates);
        }
Ejemplo n.º 3
0
        public void DealRequest(bool TFBuySell, Rate rate, int amount, int tolerance, int expiration = 1000)
        {
            string product = rate.Pair;

            if (!IsReady || !ForexConfiguration.ProductSettings.ContainsKey(product) || !ForexRates.Data.ContainsKey(product))
            {
                return;
            }

            ProductSetting Settings = ForexConfiguration.ProductSettings[product];
            DealRequest    DRequest = new DealRequest(expiration);

            DRequest.Product   = product;
            DRequest.Executed  = false;
            DRequest.Buy       = TFBuySell;
            DRequest.Close     = false;
            DRequest.ASK       = rate.OFFER;
            DRequest.BID       = rate.BID;
            DRequest.Amount    = amount; //DRequest.Lots = (lots * int.Parse(Settings.OrderSize)).ToString();
            DRequest.Tolerance = tolerance;


            this.Save(DRequest);
        }
Ejemplo n.º 4
0
        public bool UpdateDataRate(Rate rate)
        {
            string pair = rate.Pair;

            if (!Data.ContainsKey(pair))
            {
                Data.Add(pair, rate);
                return(false);
            }
            else if (Data[pair].DateTime > rate.DateTime) //Update only new Rates
            {
                return(false);
            }

            Dictionary <object, object> Properties    = Objects.GetProperties(rate, true, true);
            Dictionary <string, object> PropertiesNew = new Dictionary <string, object>();
            bool bSuccess = true;

            foreach (KeyValuePair <object, object> KVP in Properties)
            {
                object oValue = KVP.Value;
                object oKey   = KVP.Key;


                if (!(oKey is string))
                {
                    continue;
                }

                if (oValue == null)
                {
                    continue;
                }
                if (oValue is int || oValue is double)
                {
                    if (System.Convert.ToDouble(oValue) < 0)
                    {
                        continue;
                    }
                }
                else if (oValue is string)
                {
                    if (System.String.IsNullOrEmpty((string)oValue))
                    {
                        continue;
                    }
                }
                else if (oValue is DateTime)
                {
                    if (((DateTime)oValue) < Data[pair].DateTime)
                    {
                        bSuccess = false;
                        break;
                    }
                }

                PropertiesNew.Add((string)oKey, oValue);
            }

            if (!bSuccess)
            {
                return(false);
            }

            Rate rateCurrent = Data[pair];

            if (Objects.SetProperties(ref rateCurrent, PropertiesNew, true))
            {
                Data[pair] = rateCurrent;
            }
            else
            {
                return(false);
            }

            DateUpdateData = DateTime.Now;
            return(true);
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
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);
        }