Пример #1
0
        /// <summary>
        /// Converts to five minute bar.
        /// </summary>
        /// <param name="tickerId">The ticker identifier.</param>
        /// <param name="tf">The tf.</param>
        /// <param name="dt">The dt.</param>
        /// <exception cref="ArgumentNullException"></exception>
        private static void ConvertToFiveMinuteBar(string tickerId, int tf, DateTime dt)
        {
            var tickerIdd = tickerId.Substring(0, 2);

            if (tickerIdd != string.Empty)
            {
                var find = Data.MinuteBars.FindLast(
                    x => x.Symbol == tickerId && x.Time.Minute == dt.AddMinutes(-1).Minute&& x.Time.Hour == dt.AddMinutes(-1).Hour);

                //while (find == null)
                //{
                //    find = Data.MinuteBars.FindLast(
                //   x => x.Symbol == tickerId && x.Time.Minute == dt.AddMinutes(-1).Minute && x.Time.Hour == dt.AddMinutes(-1).Hour);
                //    Thread.Sleep(1);
                //}
                var i = 0;
                for (i = 0; i < 60000; i++)
                {
                    if (find == null)
                    {
                        find = Data.MinuteBars.FindLast(
                            x => x.Symbol == tickerId && x.Time.Minute == dt.AddMinutes(-1).Minute&& x.Time.Hour == dt.AddMinutes(-1).Hour);
                        Thread.Sleep(1);
                    }
                    else
                    {
                        break;
                    }
                }
                if (i != 60000)
                {
                    if (dt.Minute == CloseMinute && dt.Hour == CloseHour)
                    {
                        tf = tf - 1;
                    }
                    var minutebars = Data.MinuteBars.FindAll(x => x.Symbol == tickerId).TakeLast(tf).ToList();

                    if (minutebars.Count == tf)
                    {
                        var bar = ConvertListToBar(minutebars, tickerId, tf);
                        if (bar == null)
                        {
                            throw new ArgumentNullException(nameof(bar));
                        }
                        if (dt.Minute == CloseMinute && dt.Hour == CloseHour)
                        {
                            bar.Interval = bar.Interval + 1;
                        }
                        Data.FiveMinuteBars.Add(bar);

                        CheckToMakeOtherBars(dt, tickerId);
                        Db.AddNewBarInDb(bar);
                    }
                    else
                    {
                        Console.WriteLine("Ticker " + tickerId + "/" + tf + " ma Z€R0 baru!");
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Converts to sixty minute bar.
        /// </summary>
        /// <param name="tickerId">The ticker identifier.</param>
        /// <param name="tf">The tf.</param>
        /// <exception cref="ArgumentNullException"></exception>
        private static void ConvertToSixtyMinuteBar(string tickerId, int tf)
        {
            var tickerIdd = tickerId.Substring(0, 2);

            if (tickerIdd != string.Empty)
            {
                var hourbars = Data.HourBars.FindAll(x => x.Symbol == tickerId).TakeLast(tf / 60).ToList();
                if (hourbars.Count == tf / 60)
                {
                    var bar = ConvertListToBar(hourbars, tickerId, tf);
                    if (bar == null)
                    {
                        throw new ArgumentNullException(nameof(bar));
                    }

                    Db.AddNewBarInDb(bar);
                }
                else
                {
                    Console.WriteLine("Ticker " + tickerId + "/" + tf + " ma Z€R0 baru!");
                }
            }
        }
Пример #3
0
        /// <summary>
        ///     Converts to more minute bar.
        /// </summary>
        /// <param name="tickerId"></param>
        /// <param name="tf">The tf.</param>
        /// <param name="dt"></param>
        private static void ConvertToMoreMinuteBar(string tickerId, int tf, DateTime dt)
        {
            var tickerIdd = tickerId.Substring(0, 2);

            if (tickerIdd != string.Empty)
            {
                var fiveMinuteBars = Data.FiveMinuteBars.FindAll(x => x.Symbol == tickerId).TakeLast(tf / 5).ToList();

                // fiveminutebars = fiveminutebars.TakeLast(tf / 5).ToList();

                if (fiveMinuteBars.Count == 12)
                {
                    var bar = ConvertListToBar(fiveMinuteBars, tickerId, tf);
                    if (bar == null)
                    {
                        throw new ArgumentNullException(nameof(bar));
                    }
                    Data.HourBars.Add(bar);
                    Db.AddNewBarInDb(bar);
                }
                else if (fiveMinuteBars.Count == tf / 5)
                {
                    var bar = ConvertListToBar(fiveMinuteBars, tickerId, tf);
                    if (bar == null)
                    {
                        throw new ArgumentNullException(nameof(bar));
                    }
                    //Data.FiveMinuteBars.Add(bar);

                    Db.AddNewBarInDb(bar);
                }
            }
            else
            {
                Console.WriteLine("Ticker: " + tickerId + "/" + tf + " ma Z€R0 baru!");
            }
        }