public bool TryAdd(TickIO tickIO)
        {
            if (!isInitialized)
            {
                throw new ApplicationException("Please initialized TickWriter first.");
            }
            TickBinary tick = tickIO.Extract();

            return(writeQueue.TryEnqueue(ref tick));
        }
Exemple #2
0
        public bool TryAdd(TickIO tickIO)
        {
            if (!isInitialized)
            {
                throw new ApplicationException("Please initialized TickWriter first.");
            }
            TickBinary tick   = tickIO.Extract();
            var        result = writeQueue.TryEnqueue(ref tick);

            if (result)
            {
                Interlocked.Increment(ref appendCounter);
            }
            return(result);
        }
Exemple #3
0
        public bool OnEvent(SymbolInfo symbol, int eventType, object eventDetail)
        {
            bool result = false;

            if (isDisposed)
            {
                return(false);
            }
            try {
                switch ((EventType)eventType)
                {
                case EventType.Tick:
                    TickBinary binary = (TickBinary)eventDetail;
                    result = tickQueue.TryEnqueue(ref binary);
                    break;

                case EventType.EndHistorical:
                    result = tickQueue.TryEnqueue(EventType.EndHistorical, symbol);
                    break;

                case EventType.StartRealTime:
                    result = tickQueue.TryEnqueue(EventType.StartRealTime, symbol);
                    break;

                case EventType.EndRealTime:
                    result = tickQueue.TryEnqueue(EventType.EndRealTime, symbol);
                    break;

                case EventType.StartBroker:
                    result = tickQueue.TryEnqueue(EventType.StartBroker, symbol);
                    break;

                case EventType.EndBroker:
                    result = tickQueue.TryEnqueue(EventType.EndBroker, symbol);
                    break;

                case EventType.Error:
                    result = tickQueue.TryEnqueue(EventType.Error, symbol);
                    break;

                case EventType.Terminate:
                    result = tickQueue.TryEnqueue(EventType.Terminate, symbol);
                    break;

                case EventType.LogicalFill:
                case EventType.StartHistorical:
                case EventType.Initialize:
                case EventType.Open:
                case EventType.Close:
                case EventType.PositionChange:
                default:
                    break;
                }
            } catch (QueueException) {
                log.Warn("Already terminated.");
            }
            return(result);
        }
 public bool OnHistorical(SymbolInfo symbol)
 {
     try {
         return(tickQueue.TryEnqueue(EventType.StartHistorical, symbol));
     } catch (QueueException) {
         // Queue was already ended.
     }
     return(true);
 }
        public bool OnEvent(SymbolInfo symbol, int eventType, object eventDetail)
        {
            bool result = false;

            try {
                switch ((EventType)eventType)
                {
                case EventType.Tick:
                    TickBinaryBox binary = (TickBinaryBox)eventDetail;
                    result = readQueue.TryEnqueue(ref binary.TickBinary);
                    if (result)
                    {
                        tickPool.Free(binary);
                    }
                    break;

                case EventType.EndHistorical:
                    result = readQueue.TryEnqueue(EventType.EndHistorical, symbol);
                    break;

                case EventType.StartRealTime:
                    result = readQueue.TryEnqueue(EventType.StartRealTime, symbol);
                    break;

                case EventType.EndRealTime:
                    result = readQueue.TryEnqueue(EventType.EndRealTime, symbol);
                    break;

                case EventType.Error:
                    result = readQueue.TryEnqueue(EventType.Error, symbol);
                    break;

                case EventType.Terminate:
                    result = readQueue.TryEnqueue(EventType.Terminate, symbol);
                    break;

                case EventType.LogicalFill:
                case EventType.StartHistorical:
                case EventType.Initialize:
                case EventType.Open:
                case EventType.Close:
                case EventType.PositionChange:
                default:
                    // Skip these event types.
                    result = true;
                    break;
                }
            } catch (QueueException) {
                log.Warn("Already terminated.");
            }
            return(result);
        }
Exemple #6
0
        public void EnQueueItemTest()
        {
            TickBinary tick   = new TickBinary();
            TickIO     tickIO = Factory.TickUtil.TickIO();
            long       start  = Factory.TickCount;

            for (int i = 0; i < 10; i++)
            {
                Assert.IsTrue(queue.TryEnqueue(ref tick));
            }
            long stop = Factory.TickCount;

            log.Notice("Enqueue elapsed time is " + (stop - start) + "ms");

            start = Factory.TickCount;
            for (int i = 0; i < 10; i++)
            {
                Assert.IsTrue(queue.TryDequeue(ref tick));
            }
            stop = Factory.TickCount;
            log.Notice("Dequeue elapsed time is " + (stop - start) + "ms");
        }