Пример #1
0
        public void TikTypes()
        {
            // get symbol
            string sym = Research.RandomSymbol.GetSymbol((int)DateTime.Now.Ticks);

            // prepare data
            List <Tick> data = new List <Tick>();

            // bid
            data.Add(TickImpl.NewBid(sym, 10, 100));

            // ask
            data.Add(TickImpl.NewAsk(sym, 11, 200));

            // full quote
            data.Add(TickImpl.NewQuote(sym, Date, 93000, 10, 11, 300, 300, "NYSE", "ARCA"));

            // trade
            data.Add(TickImpl.NewTrade(sym, Date, 93100, 10, 400, "NYSE"));

            // full tick
            Tick full = TickImpl.Copy((TickImpl)data[2], (TickImpl)data[3]);

            data.Add(full);

            // write and read the data
            Writeandread(data.ToArray(), Date, false);

            //verify the count
            Assert.Equal(data.Count, _readdata.Count);

            // verify the data
            bool          equal = true;
            StringBuilder sb    = new StringBuilder(string.Empty);

            for (int i = 0; i < data.Count; i++)
            {
                bool start = equal;
                equal &= data[i].Bid == _readdata[i].Bid;
                equal &= data[i].BidSize == _readdata[i].BidSize;
                equal &= data[i].BidSource == _readdata[i].BidSource;
                equal &= data[i].Ask == _readdata[i].Ask;
                equal &= data[i].AskSize == _readdata[i].AskSize;
                equal &= data[i].AskSource == _readdata[i].AskSource;
                equal &= data[i].Trade == _readdata[i].Trade;
                equal &= data[i].Size == _readdata[i].Size;
                equal &= data[i].Source == _readdata[i].Source;
                equal &= data[i].Depth == _readdata[i].Depth;
                if (equal != start)
                {
                    sb.Append(i + " ");
                }
            }
            Assert.True(equal, "bad ticks: " + sb + data[0] + _readdata[0]);
        }
Пример #2
0
        public void TikTypes()
        {
            // get symbol
            string SYM = TradeLink.Research.RandomSymbol.GetSymbol((int)DateTime.Now.Ticks);

            // prepare data
            System.Collections.Generic.List <Tick> data = new List <Tick>();
            // bid
            data.Add(TickImpl.NewBid(SYM, 10, 100));
            // ask
            data.Add(TickImpl.NewAsk(SYM, 11, 200));
            // full quote
            data.Add(TickImpl.NewQuote(SYM, DATE, 93000, 10, 11, 300, 300, "NYSE", "ARCA"));
            // trade
            data.Add(TickImpl.NewTrade(SYM, DATE, 93100, 10, 400, "NYSE"));
            // full tick
            Tick full = TickImpl.Copy((TickImpl)data[2], (TickImpl)data[3]);

            data.Add(full);

            // write and read the data
            writeandread(data.ToArray(), DATE, false);

            //verify the count
            Assert.AreEqual(data.Count, readdata.Count);

            // verify the data
            bool equal = true;

            System.Text.StringBuilder sb = new StringBuilder(string.Empty);
            for (int i = 0; i < data.Count; i++)
            {
                bool start = equal;
                equal &= data[i].bid == readdata[i].bid;
                equal &= data[i].bs == readdata[i].bs;
                equal &= data[i].be == readdata[i].be;
                equal &= data[i].ask == readdata[i].ask;
                equal &= data[i].os == readdata[i].os;
                equal &= data[i].oe == readdata[i].oe;
                equal &= data[i].trade == readdata[i].trade;
                equal &= data[i].size == readdata[i].size;
                equal &= data[i].ex == readdata[i].ex;
                equal &= data[i].depth == readdata[i].depth;
                if (equal != start)
                {
                    sb.Append(i + " ");
                }
            }
            Assert.IsTrue(equal, "bad ticks: " + sb.ToString() + data[0].ToString() + readdata[0].ToString());
        }
Пример #3
0
        private bool HandleTick(int expectedCount, Action <TickIO, TickIO, ulong> assertTick, SymbolInfo symbol)
        {
            try {
                while (!tickQueue.TryDequeue(ref tickBinary))
                {
                    if (propagateException != null)
                    {
                        throw propagateException;
                    }
                    Thread.Sleep(1);
                }
                tick.Inject(tickBinary);
                if (debug && countLog < 5)
                {
                    log.Debug("Received a tick " + tick);
                    countLog++;
                }
                startTime = Environment.TickCount;
                count++;
                if (count > 0)
                {
                    assertTick(tick, lastTick, symbol.BinaryIdentifier);
                }
                lastTick.Copy(tick);
                if (propagateException != null)
                {
                    throw propagateException;
                }
                if (count >= expectedCount)
                {
                    return(true);
                }
            } catch (QueueException ex) {
                switch (ex.EntryType)
                {
                case EventType.EndHistorical:
                case EventType.StartRealTime:
                case EventType.EndRealTime:
                    break;

                case EventType.Terminate:
                    return(true);

                default:
                    throw new ApplicationException("Unexpected QueueException: " + (EventType)ex.EntryType);
                }
            }
            return(false);
        }
Пример #4
0
        public void WatcherTest()
        {
            // create a new tick watcher
            TickWatcher tw = new TickWatcher(0);

            tw.GotAlert += new SymDelegate(tw_GotAlert);
            const string sym  = "TST";
            const int    y    = 2008;
            const int    m    = 1;
            const int    d    = 1;
            int          date = Util.ToTLDate(new DateTime(y, m, d));
            TickImpl     t    = TickImpl.NewTrade(sym, date, 130000, 100m, 100, "");

            // watch this stock and supply a watch time
            // we have no previous updates to no whether to alert on,
            // so it returns false
            Assert.IsFalse(tw.newTick(t));
            tw.AlertThreshold = 300;
            Assert.That(tw.AlertThreshold == 300);
            TickImpl t2 = TickImpl.Copy(t);

            t2.time = 130458;
            // this should succeed bc it's within the window (but no alert sent)
            Assert.IsFalse(tw.newTick(t2));

            // this time check should send no alerts bc it's w/in window
            tw.SendAlerts(new DateTime(y, m, d, 13, 4, 0));

            TickImpl t3 = TickImpl.Copy(t2);

            t3.time = 131000;
            // this should return false and send an alert
            Assert.That(tw.newTick(t3));

            // this timecheck is outside the window, should alert
            DateTime iswaylate = new DateTime(y, m, d, 14, 0, 1);

            tw.SendAlerts(iswaylate);

            Assert.AreEqual(2, alertssent); // here's our alert check
        }
Пример #5
0
 void broker_GotTick(Tick tick)
 {
     receivedtickDP = TickImpl.Copy(tick);
     gottickDP++;
 }