Esempio n. 1
0
        public void SpoolIntraBars()
        {
            BarListImpl bl = (BarListImpl)_intraBarTracker["SPY", (int)BarInterval.FiveMin];

            for (int x = 0; x < _spyIntra.Length; x++)
            {
                Bar b = BarImpl.Deserialize(_spyIntra[x]);

                bl.NewPoint(b.Symbol, b.Open, b.Bartime, b.Bardate, 0);
                bl.NewPoint(b.Symbol, b.High, b.Bartime, b.Bardate, 0);
                bl.NewPoint(b.Symbol, b.Low, b.Bartime, b.Bardate, 0);
                bl.NewPoint(b.Symbol, b.Close, b.Bartime, b.Bardate, (int)b.Volume);
            }

            Console.WriteLine("Count: " + bl.Count);

            Assert.Equal(_spyIntra.Length, bl.Count);
            for (int x = 0; x < _spyIntra.Length; x++)
            {
                Bar t = BarImpl.Deserialize(_spyIntra[x]);
                Assert.Equal(bl[x].Bardate, t.Bardate);
                Assert.Equal(bl[x].Close, t.Close);
            }

            DisplayTrackerContent(_intraBarTracker["SPY"]);
        }
Esempio n. 2
0
        public void IntraMixedTickAndBars()
        {
            BarList bl = intraBarTracker["SPY", (int)BarInterval.FiveMin];

            for (int x = 0; x < SPY_Intra.Length; x++)
            {
                Bar b = BarImpl.Deserialize(SPY_Intra[x]);

                bl.newPoint(b.Symbol, b.Open, b.Bartime, b.Bardate, 0);
                bl.newPoint(b.Symbol, b.High, b.Bartime, b.Bardate, 0);
                bl.newPoint(b.Symbol, b.Low, b.Bartime, b.Bardate, 0);
                bl.newPoint(b.Symbol, b.Close, b.Bartime, b.Bardate, (int)b.Volume);

                // interleave ticks with the bars to simulate datafeed asynchronous-ness
                int  baseTime = 144500;
                Tick k        = new TickImpl("SPY");
                k.ask   = 101;
                k.bid   = 100;
                k.date  = 20110208;
                k.trade = 100.5m;
                k.size  = 5000;
                k.time  = baseTime + x;
                intraBarTracker.newTick(k);
            }

            Console.WriteLine("Count: " + bl.Count);
            DisplayTrackerContent(intraBarTracker["SPY"]);
            Assert.AreEqual(SPY_Intra.Length, bl.Count);
            for (int x = 0; x < SPY_Intra.Length - 1; x++)
            {
                Bar t = BarImpl.Deserialize(SPY_Intra[x]);
                Assert.AreEqual(bl[x].Bardate, t.Bardate);
                Assert.AreEqual(bl[x].Close, t.Close);
            }
        }
Esempio n. 3
0
        public void DailyMixedTickAndBars()
        {
            BarListImpl bl = (BarListImpl)_dailyBarTracker["SPY", (int)BarInterval.Day];

            for (int x = 0; x < _spyDaily.Length; x++)
            {
                BarImpl b = (BarImpl)BarImpl.Deserialize(_spyDaily[x]);
                bl.NewPoint(b.Symbol, b.Open, b.Bartime, b.Bardate, 0);
                bl.NewPoint(b.Symbol, b.High, b.Bartime, b.Bardate, 0);
                bl.NewPoint(b.Symbol, b.Low, b.Bartime, b.Bardate, 0);
                bl.NewPoint(b.Symbol, b.Close, b.Bartime, b.Bardate, (int)b.Volume);

                // interleave ticks with the bars to simulate datafeed asynchronous-ness
                int      baseTime = 144500;
                TickImpl k        = new TickImpl("SPY");
                k.Ask   = 101;
                k.Bid   = 100;
                k.Date  = 20110208;
                k.Trade = 100.5m;
                k.Size  = 5000;
                k.Time  = baseTime + x;
                _dailyBarTracker.NewTick(k);
            }

            Console.WriteLine("Count: " + bl.Count);
            DisplayTrackerContent(_dailyBarTracker["SPY"]);
            Assert.Equal(_spyDaily.Length, bl.Count);
            for (int x = 0; x < _spyDaily.Length - 1; x++)
            {
                Bar t = BarImpl.Deserialize(_spyDaily[x]);
                Assert.Equal(bl[x].Bardate, t.Bardate);
                Assert.Equal(bl[x].Close, t.Close);
            }
        }
Esempio n. 4
0
        public void SpoolDailyBars()
        {
            BarList bl = dailyBarTracker["SPY", (int)BarInterval.Day];

            for (int x = 0; x < SPY_Daily.Length; x++)
            {
                Bar b = BarImpl.Deserialize(SPY_Daily[x]);

                bl.newPoint(b.Symbol, b.Open, b.Bartime, b.Bardate, 0);
                bl.newPoint(b.Symbol, b.High, b.Bartime, b.Bardate, 0);
                bl.newPoint(b.Symbol, b.Low, b.Bartime, b.Bardate, 0);
                bl.newPoint(b.Symbol, b.Close, b.Bartime, b.Bardate, (int)b.Volume);
            }

            Console.WriteLine("Count: " + bl.Count);
            Assert.AreEqual(SPY_Daily.Length, bl.Count);
            for (int x = 0; x < SPY_Daily.Length; x++)
            {
                Bar t = BarImpl.Deserialize(SPY_Daily[x]);
                Assert.AreEqual(bl[x].Bardate, t.Bardate);
                Assert.AreEqual(bl[x].Close, t.Close);
            }

            DisplayTrackerContent(dailyBarTracker["SPY"]);
        }
Esempio n. 5
0
        void c_gotUnknownMessage(MessageTypes type, long source, long dest, long msgid, string request, ref string response)
        {
            if (type == MessageTypes.BARRESPONSE)
            {
                bar = BarImpl.Deserialize(response);
                if (bar.isValid)
                {
#if DEBUG
                    g.d("got bar: " + response);
#endif
                    barcount++;
                }
            }
        }
Esempio n. 6
0
        public void SerializeDeseralize()
        {
            Bar    b   = new BarImpl(1, 1, 1, 1, 1, 20100302, 93533, "IBM", (int)BarInterval.FiveMin);
            string msg = BarImpl.Serialize(b);
            Bar    cb  = BarImpl.Deserialize(msg);

            Assert.AreEqual(b.Symbol, cb.Symbol);
            Assert.AreEqual(b.time, cb.time);
            Assert.AreEqual(b.Interval, cb.Interval);
            Assert.AreEqual(b.High, cb.High);
            Assert.AreEqual(b.Low, cb.Low);
            Assert.AreEqual(b.Open, cb.Open);
            Assert.AreEqual(b.Close, cb.Close);
            Assert.AreEqual(b.Volume, cb.Volume);
            Assert.AreEqual(b.Bardate, cb.Bardate);
        }
Esempio n. 7
0
        void client_gotUnknownMessage(MessageTypes type, long source, long dest, long msgid, string request, ref string response)
        {
            if (type == MessageTypes.BARRESPONSE)
            {
                lastbarraw = response;
                var b         = BarImpl.Deserialize(response);
                var label     = b.Symbol + b.Interval.ToString() + b.CustomInterval.ToString();
                var symintidx = symintcount.getindex(label);
                if (symintidx < 0)
                {
                    symintidx = symintcount.addindex(label, new List <Bar>());
                    g.d("got new symbol/interval: " + b.Symbol + " " + b.Interval + b.CustomInterval + " bar:" + b.ToString());
                }

                symintcount[symintidx].Add(b);
                if (!recvsyms.Contains(b.Symbol))
                {
                    recvsyms.Add(b.Symbol);
                }
                recvbarcount++;
            }
            else if (type == MessageTypes.BARRESPONSE_FINAL)
            {
                var br = BarRequest.Deserialize(response);
                reccomplete++;
                g.d("completed: " + br.symbol + " " + br.Interval + " " + br.ID);
            }
            else
            {
                g.d("got unknown message: " + type + request + response);
            }
            var ok = mt.GotMessage(type, source, dest, msgid, request, ref response);

            if (!ok)
            {
                g.d("error processing: " + type + " request: " + request + " response: " + response);
            }
            msgok &= ok;
        }
Esempio n. 8
0
        public void SerializeDeseralize_Custom()
        {
            Bar b = new BarImpl(1, 1, 1, 1, 1, 20100302, 93533, "IBM", (int)BarInterval.CustomVol, 10000, OrderImpl.Unique);

            g.d(b.Interval + b.CustomInterval.ToString());
            Assert.IsTrue(b.isCustom, "org not custom");
            string msg = BarImpl.Serialize(b);
            Bar    cb  = BarImpl.Deserialize(msg);

            Assert.AreEqual(b.Symbol, cb.Symbol);
            Assert.AreEqual(b.time, cb.time);
            Assert.AreEqual(b.Interval, cb.Interval);
            Assert.AreEqual(b.High, cb.High);
            Assert.AreEqual(b.Low, cb.Low);
            Assert.AreEqual(b.Open, cb.Open);
            Assert.AreEqual(b.Close, cb.Close);
            Assert.AreEqual(b.Volume, cb.Volume);
            Assert.AreEqual(b.Bardate, cb.Bardate);

            Assert.IsTrue(cb.isCustom, "copy not custom");
            Assert.AreEqual(b.CustomInterval, cb.CustomInterval, "cust int mismatch");
            Assert.AreNotEqual(b.id, 0, "id was zero");
            Assert.AreEqual(b.id, cb.id);
        }