Exemple #1
0
        public void InsertBar_HistoricalPlusNewBarsPresent()
        {
            string sym = "FTI";
            int    d   = 20070926;
            // historical bar filename
            string filename = sym + d + TikConst.DOT_EXT;
            // case 3 - middle insertion aka (some historical and some new bars already present)
            var org = BarListImpl.FromTIK(filename);

            Assert.IsTrue(org.isValid, "your original bar is not valid 3");
            var orgcount = org.Count;

            Assert.Greater(orgcount, 0);
            // create bar to insert
            var insert = new BarImpl(30, 30, 30, 30, 10000, d, 75500, sym, (int)BarInterval.FiveMin);

            Assert.IsTrue(insert.isValid, "your bar to insert is not valid 3");
            int insertpos = BarListImpl.GetBarIndexPreceeding(org, insert.Bardate);
            var inserted  = BarListImpl.InsertBar(org, insert, insertpos);

            Assert.AreEqual(inserted.Count, orgcount + 1);
            var actualinsert = inserted[insertpos];

            Assert.IsTrue(actualinsert.isValid);
            Assert.AreEqual(insert.Close, actualinsert.Close);
            Assert.AreEqual(insert.Open, actualinsert.Open);
            Assert.AreEqual(insert.High, actualinsert.High);
            Assert.AreEqual(insert.Low, actualinsert.Low);
            Assert.AreEqual(insert.Symbol, actualinsert.Symbol);
        }
Exemple #2
0
        public void InsertBar_MultipleInsert()
        {
            string  sym = "FTI";
            int     d   = 20070926;
            BarList org = new BarListImpl(BarInterval.FiveMin, sym);

            Assert.IsTrue(org.isValid, "your original barlist is not valid 1");
            int orgcount = org.Count;

            Assert.AreEqual(0, orgcount);

            int h = 7;
            int m = 55;

            for (int i = 0; i < 10; i++)
            {
                int t      = h * 10000 + m * 100;
                Bar insert = new BarImpl(30, 30, 30, 30, 10000, d, t, sym, (int)BarInterval.FiveMin);
                Assert.IsTrue(insert.isValid, "your bar to insert is not valid 1");
                int insertpos = BarListImpl.GetBarIndexPreceeding(org, insert.Bardate, insert.Bartime);
                Assert.AreEqual(i - 1, insertpos, "insertion position");
                BarList inserted = BarListImpl.InsertBar(org, insert, insertpos);
                Assert.AreEqual(i + 1, inserted.Count, "element count after insertion");
                m += 5;
                if (m >= 60)
                {
                    h += m / 60;
                    m  = m % 60;
                }
                org = inserted;
            }
            Assert.AreEqual(orgcount + 10, org.Count, "total element count after insertion");
        }
Exemple #3
0
        public void InsertBar_MultipleInsert()
        {
            string  sym   = "FTI";
            int     d     = 20070926;
            var     bint  = BarInterval.FiveMin;
            var     bsize = (int)bint;
            BarList org   = new BarListImpl(bint, sym);

            Assert.True(org.IsValid, "your original barlist is not valid 1");
            int orgcount = org.Count;

            Assert.Equal(0, orgcount);

            int h = 7;
            int m = 55;

            for (int i = 0; i < 10; i++)
            {
                int t = h * 10000 + m * 100;
                t *= 1000;
                Bar insert = new BarImpl(30, 30, 30, 30, 10000, d, t, sym, bsize);
                Assert.True(insert.IsValid, "your bar to insert is not valid #" + i);
                int insertpos = BarListImpl.GetBarIndexPreceeding(org, insert.Bardate, insert.Bartime);
                Assert.Equal(i - 1, insertpos);
                BarList inserted = BarListImpl.InsertBar(org, insert, insertpos);
                //Assert.True(g.ta(i + 1 == inserted.Count, BarListImpl.Bars2String(org)+Environment.NewLine+ BarListImpl.Bars2String(inserted)), "element count after insertion #" + i + " pos: " + insertpos);
                m += 5;
                if (m >= 60)
                {
                    h += m / 60;
                    m  = m % 60;
                }
                org = inserted;
            }
            Assert.Equal(orgcount + 10, org.Count);
        }