Esempio n. 1
0
        public void StartSymbol(Receiver receiver, SymbolInfo symbol, object eventDetail)
        {
            TickIO tickIO = Factory.TickUtil.TickIO();

            tickIO.Initialize();
            tickIO.SetSymbol(symbol.BinaryIdentifier);
            tickIO.SetTime(new TimeStamp(2000, 1, 1));
            tickIO.SetQuote(100D, 100D);
            while (!receiver.OnEvent(symbol, (int)EventType.StartHistorical, symbol))
            {
                Factory.Parallel.Yield();
            }
            var binaryBox = tickPool.Create();

            binaryBox.TickBinary = tickIO.Extract();
            while (!receiver.OnEvent(symbol, (int)EventType.Tick, binaryBox))
            {
                Factory.Parallel.Yield();
            }
            tickIO.Initialize();
            tickIO.SetSymbol(symbol.BinaryIdentifier);
            tickIO.SetTime(new TimeStamp(2000, 1, 2));
            tickIO.SetQuote(101D, 101D);
            binaryBox            = tickPool.Create();
            binaryBox.TickBinary = tickIO.Extract();
            while (!receiver.OnEvent(symbol, (int)EventType.Tick, binaryBox))
            {
                Factory.Parallel.Yield();
            }
            while (!receiver.OnEvent(symbol, (int)EventType.EndHistorical, symbol))
            {
                Factory.Parallel.Yield();
            }
        }
Esempio n. 2
0
 public void SendQuote()
 {
     if (isQuoteInitialized || VerifyQuote())
     {
         if (isRunning)
         {
             if (Symbol.QuoteType != QuoteType.Level1)
             {
                 if (!errorWrongLevel1Type)
                 {
                     log.Error("Received " + QuoteType.Level1 + " quote but " + Symbol + " is configured for QuoteType = " + Symbol.QuoteType + " in the symbol dictionary.");
                     errorWrongLevel1Type = true;
                 }
             }
             else if (Bid == 0D)
             {
                 log.Error("Found quote bid was set to " + Bid + " so skipping this tick.");
                 return;
             }
             else if (Ask == 0D)
             {
                 log.Error("Found quote ask was set to " + Ask + " so skipping this tick.");
                 return;
             }
             else
             {
                 tickIO.Initialize();
                 tickIO.SetSymbol(Symbol.BinaryIdentifier);
                 tickIO.SetTime(Time);
                 tickIO.SetQuote(Bid, Ask, (short)BidSize, (short)AskSize);
                 var box    = tickPool.Create(tickPoolCallerId);
                 var tickId = box.TickBinary.Id;
                 box.TickBinary    = tickIO.Extract();
                 box.TickBinary.Id = tickId;
                 quotesLatency.TryUpdate(box.TickBinary.Symbol, box.TickBinary.UtcTime);
                 var eventItem = new EventItem(symbol, EventType.Tick, box);
                 agent.SendEvent(eventItem);
                 Interlocked.Increment(ref tickCount);
                 if (Diagnose.TraceTicks)
                 {
                     Diagnose.AddTick(diagnoseMetric, ref box.TickBinary);
                 }
                 if (trace)
                 {
                     log.Trace("Sent quote for " + Symbol + ": " + tickIO);
                 }
             }
         }
     }
 }
Esempio n. 3
0
 public bool TryReadTick(TickIO tickIO)
 {
     try
     {
         if (memory.Position >= tickBlockHeader.blockHeader.length)
         {
             return(false);
         }
         tickIO.SetSymbol(tickIO.lSymbol);
         var size = memory.GetBuffer()[memory.Position];
         dataVersion = tickIO.FromReader(memory);
         var utcTime = new TimeStamp(tickIO.lUtcTime);
         tickIO.SetTime(utcTime);
         return(true);
     }
     catch (EndOfStreamException ex)
     {
         return(false);
     }
     catch (IndexOutOfRangeException)
     {
         int x = 0;
         return(false);
     }
 }
Esempio n. 4
0
 public bool TryReadTick(TickIO tickIO)
 {
     if (!isInitialized)
     {
         return(false);
     }
     if (dataIn == null || tickCount > MaxCount || endOfData)
     {
         return(false);
     }
     try
     {
         do
         {
             tickIO.SetSymbol(lSymbol);
             byte size = dataIn.ReadByte();
             // Check for old style prior to version 8 where
             // single byte version # was first.
             if (dataVersion < 8 && size < 8)
             {
                 dataVersion = tickIO.FromReader((byte)size, dataIn);
             }
             else
             {
                 // Subtract the size byte.
                 //if (dataIn.BaseStream.Position + size - 1 > length) {
                 //    return false;
                 //}
                 int count = 1;
                 memory.SetLength(size);
                 memory.GetBuffer()[0] = size;
                 while (count < size)
                 {
                     var bytesRead = dataIn.Read(buffer, count, size - count);
                     if (bytesRead == 0)
                     {
                         return(false);
                     }
                     count += bytesRead;
                 }
                 memory.Position = 0;
                 dataVersion     = tickIO.FromReader(memory);
             }
             var utcTime = new TimeStamp(tickIO.lUtcTime);
             if (utcTime > EndTime)
             {
                 ReportEndOfData();
                 return(false);
             }
             tickIO.SetTime(utcTime);
             tickCount++;
         } while (tickIO.UtcTime < StartTime);
         return(true);
     }
     catch (EndOfStreamException ex)
     {
         ReportEndOfData();
         return(false);
     }
 }
Esempio n. 5
0
        private void CreateTick()
        {
            TimeStamp timeStamp = TimeStamp.UtcNow;

            tick.Initialize();
            tick.SetSymbol(symbol.BinaryIdentifier);
            tick.SetTime(timeStamp);
        }
Esempio n. 6
0
 public void SendQuote()
 {
     if (isInitialized)
     {
         if (symbol.QuoteType == QuoteType.Level1)
         {
             tickIO.Initialize();
             tickIO.SetSymbol(symbol.BinaryIdentifier);
             tickIO.SetTime(TimeStamp.UtcNow);
             tickIO.SetQuote(Bid, Ask, (ushort)BidSize, (ushort)AskSize);
             TickBinary binary = tickIO.Extract();
             receiver.OnSend(ref binary);
         }
     }
     else
     {
         VerifyInitialized();
     }
 }
Esempio n. 7
0
 public void SendQuote()
 {
     if (isQuoteInitialized || VerifyQuote())
     {
         if (isRunning)
         {
             if (symbol.QuoteType != QuoteType.Level1)
             {
                 if (!errorWrongLevel1Type)
                 {
                     log.Error("Received " + QuoteType.Level1 + " quote but " + symbol + " is configured for QuoteType = " + symbol.QuoteType + " in the symbol dictionary.");
                     errorWrongLevel1Type = true;
                 }
             }
             else if (Bid == 0D)
             {
                 log.Error("Found quote bid was set to " + Bid + " so skipping this tick.");
                 return;
             }
             else if (Ask == 0D)
             {
                 log.Error("Found quote ask was set to " + Ask + " so skipping this tick.");
                 return;
             }
             else
             {
                 tickIO.Initialize();
                 tickIO.SetSymbol(symbol.BinaryIdentifier);
                 tickIO.SetTime(Time);
                 tickIO.SetQuote(Bid, Ask, (short)BidSize, (short)AskSize);
                 var box = tickPool.Create();
                 box.TickBinary = tickIO.Extract();
                 receiver.OnEvent(symbol, (int)EventType.Tick, box);
                 if (trace)
                 {
                     log.Trace("Sent tick for " + symbol + ": " + tickIO);
                 }
             }
         }
     }
 }
        private Yield DequeueTick()
        {
            LatencyManager.IncrementSymbolHandler();
            var result = Yield.NoWork.Repeat;

            if (isFirstTick)
            {
                if (!reader.TryReadTick(currentTick))
                {
                    return(result);
                }
            }
            else
            {
                currentTick.Inject(nextTick.Extract());
                if (!reader.TryReadTick(nextTick))
                {
                    return(result);
                }
            }
            tickCounter++;
            if (isFirstTick)
            {
                playbackOffset = fixSimulatorSupport.GetRealTimeOffset(currentTick.UtcTime.Internal);
                prevTickTime   = TimeStamp.UtcNow.Internal + 5000000;
            }
            currentTick.SetTime(new TimeStamp(GetNextUtcTime(currentTick.lUtcTime)));
            prevTickTime = currentTick.UtcTime.Internal;
            if (tickCounter > 10)
            {
                intervalTime = 1000;
            }
            isFirstTick = false;
            FillSimulator.StartTick(currentTick);
            if (trace)
            {
                log.Trace("Dequeue tick " + nextTick.UtcTime + "." + nextTick.UtcTime.Microsecond);
            }
            return(Yield.DidWork.Invoke(ProcessTick));
        }
Esempio n. 9
0
        private void writeATick(double insertPrice, int volume)
        {
            if (tsBits[1].Length <= 3)
            {
                tickTime = new TimeStamp(tsBits[0] + " " + tsBits[1] + ":00");
            }
            else
            {
                tickTime = new TimeStamp(tsBits[0] + " " + tsBits[1]);
            }
            utcTime = tickTime;
            utcTime.AddSeconds(-GetUtcOffset(tickTime));
            double price = insertPrice;

            tickIO.SetTime(utcTime);
            if (volume >= 1)
            {
                tickIO.SetTrade(price, volume);
            }
            else
            {
//				tickIO.SetQuote(price, price);
                tickIO.SetTrade(price, volume);
            }

            if (tickWriter == null)
            {
                tickWriter = Factory.TickUtil.TickWriter(true);
                tickWriter.KeepFileOpen = true;
                string folder = "DataCache";
                tickWriter.Initialize(folder, symbol.Symbol);
            }

            // Console.WriteLine(tickIO);

            tickWriter.Add(tickIO);

            countTicksOut++;
        }