示例#1
0
        public void TickInt()
        {
            Tick[]             tape = TestBarList.SampleData();
            BarListTrackerImpl blt  = new BarListTrackerImpl(new[] { 3 }, new BarInterval[] { BarInterval.CustomTicks });

            foreach (Tick k in tape)
            {
                blt.NewTick(k);
            }

            Assert.Equal(4, blt[tape[0].Symbol].Count);
        }
示例#2
0
        public void DefaultInt()
        {
            BarListTrackerImpl blt = new BarListTrackerImpl();

            blt.GotNewBar += new SymBarIntervalDelegate(blt_GotNewBar);

            Tick[] tape = TestBarList.SampleData();
            // get second tape and change symbol
            Tick[] tape2 = new Tick[tape.Length];
            for (int i = 0; i < tape2.Length; i++)
            {
                TickImpl t = (TickImpl)tape[i];
                t.Symbol = "TST2";
                tape2[i] = t;
            }

            // add ticks from both tape to tracker
            for (int i = 0; i < tape.Length; i++)
            {
                blt.NewTick(tape[i]);
                blt.NewTick(tape2[i]);
            }

            //make sure we got two symbols as bar events
            Assert.Equal(2, syms.Count);
            // make sure our symbols matched barlist count
            Assert.Equal(blt.SymbolCount, syms.Count);

            int    secondcount = 0;
            string symstring   = string.Empty;

            foreach (string sym in blt)
            {
                secondcount++;
                symstring += sym;
            }

            // make sure enumeration equals symbol count
            Assert.Equal(syms.Count, secondcount);
            // make sure symbols are there
            Assert.True(symstring.Contains("TST") && symstring.Contains("TST2"));

            // change default interval
            blt.DefaultInterval = BarInterval.Minute;
            // make sure same on individual bars
            Assert.Equal(blt.DefaultInterval, blt["TST"].DefaultInterval);

            Assert.Equal(9, blt["TST"].IntervalCount(BarInterval.Minute));
            Assert.Equal(3, blt["TST"].IntervalCount(BarInterval.FiveMin));
        }
示例#3
0
 public TestBarList()
 {
     _dailyBarTracker = new BarListTrackerImpl(BarInterval.Day);
     _intraBarTracker = new BarListTrackerImpl(BarInterval.FiveMin);
 }
示例#4
0
        /// <summary>
        /// fill bars with arbitrary price data for a symbol
        /// </summary>
        /// <param name="sym"></param>
        /// <param name="prices"></param>
        /// <param name="startdate"></param>
        /// <param name="starttime"></param>
        /// <param name="blt"></param>
        /// <param name="interval"></param>
        /// <returns></returns>
        public static bool Backfillbars(string sym, decimal[] prices, int startdate, int starttime, ref BarListTrackerImpl blt, int interval)
        {
            // ensure we have closing data
            if (prices.Length == 0)
            {
                Log.Debug(sym + " no price data provided/available, will have to wait until bars are created from market.");
                return(false);
            }
            // make desired numbers of ticks
            DateTime      n   = Util.ToDateTime(startdate, starttime);
            bool          ok  = true;
            List <string> bfd = new List <string>();

            for (int i = prices.Length - 1; i >= 0; i--)
            {
                // get time now - exitlen*60
                var  ndt = n.Subtract(new TimeSpan(0, i * interval, 0));
                int  nt  = Util.ToQLTime(ndt);
                int  nd  = Util.ToQLDate(ndt);
                Tick k   = TickImpl.NewTrade(sym, nd, nt, prices[i], 100, string.Empty);
                ok &= k.IsValid && k.IsTrade;
                bfd.Add(nd + nt.ToString() + "=" + prices[i]);
                if (i <= 2)
                {
                    Log.Debug(nd + " " + nt);
                }
                blt.NewTick(k);
            }
            if (ok)
            {
                Log.Debug("{0} bars backfilled using: {1} bars", sym, bfd.Count);
            }
            return(ok);
        }