Example #1
0
 public void SendTimeAndSales()
 {
     if (!isRunning)
     {
         return;
     }
     if (symbol.TimeAndSales != TimeAndSales.ActualTrades)
     {
         if (!errorWrongTimeAndSalesType)
         {
             log.Error("Received " + TimeAndSales.ActualTrades + " trade but " + symbol + " is configured for TimeAndSales = " + symbol.TimeAndSales + " in the symbol dictionary.");
             errorWrongTimeAndSalesType = true;
         }
         return;
     }
     if (!isTradeInitialized && !VerifyTrade())
     {
         return;
     }
     if (symbol.QuoteType == QuoteType.Level1)
     {
         if (!isQuoteInitialized && !VerifyQuote())
         {
             if (!errorNeverAnyLevel1Tick)
             {
                 log.Warn("Found a Trade tick w/o any " + QuoteType.Level1 + " quote yet but " + symbol + " is configured for QuoteType = " + symbol.QuoteType + " in the symbol dictionary.");
                 errorNeverAnyLevel1Tick = true;
             }
         }
         else if (errorNeverAnyLevel1Tick)
         {
             log.Notice("Okay. Found a Level 1 quote tick that resolves the earlier warning message.");
             errorNeverAnyLevel1Tick = false;
         }
     }
     if (Last == 0D)
     {
         log.Error("Found last trade price was set to " + Last + " so skipping this tick.");
         return;
     }
     if (symbol.TimeAndSales == TimeAndSales.ActualTrades)
     {
         tickIO.Initialize();
         tickIO.SetSymbol(symbol.BinaryIdentifier);
         tickIO.SetTime(Time);
         tickIO.SetTrade(Last, LastSize);
         if (symbol.QuoteType == QuoteType.Level1 && isQuoteInitialized && VerifyQuote())
         {
             tickIO.SetQuote(Bid, Ask, (short)BidSize, (short)AskSize);
         }
         var box = tickPool.Create();
         box.TickBinary = tickIO.Extract();
         if (tickIO.IsTrade && tickIO.Price == 0D)
         {
             log.Warn("Found trade tick with zero price: " + tickIO);
         }
         receiver.OnEvent(symbol, (int)EventType.Tick, box);
     }
 }
Example #2
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++;
        }
Example #3
0
        public void ProcessTimeAndSales(ref TSRECORD pTimeAndSales)
        {
            if (trace)
            {
                log.Trace("TimeAndSale: " +
                          pTimeAndSales.bstrExchange + ", " +
                          pTimeAndSales.bstrSymbol + ", " +
                          pTimeAndSales.cond + ", " +
                          pTimeAndSales.dPrice + ", " +
                          pTimeAndSales.lSize + ", " +
                          pTimeAndSales.lType + ", " +
                          pTimeAndSales.status + ", " +
                          pTimeAndSales.tick + ", " +
                          pTimeAndSales.type + ", " +
                          pTimeAndSales.UTCDateTime);
            }
            int InsideMarketHours = 30030;

            if (pTimeAndSales.status == enumTickStatus.tsNormal &&
                pTimeAndSales.type == enumTickType.ttTradeTick &&
                pTimeAndSales.cond == enumTickCondition.tcTrade_RegularSale &&
                pTimeAndSales.lType == InsideMarketHours)
            {
                CreateTick();
                lastAsk = lastBid = pTimeAndSales.dPrice;
                CheckSignalSync();
                tick.SetTrade(pTimeAndSales.dPrice, pTimeAndSales.lSize);
                if (Symbol.QuoteType == QuoteType.Level1)
                {
                    TryAddLevel1();
                }
                else if (Symbol.QuoteType == QuoteType.Level2)
                {
                    TryAddLevel2();
                }
                SendTick();
            }
        }
        public void SendTimeAndSales()
        {
            if (isInitialized)
            {
                if (symbol.TimeAndSales == TimeAndSales.ActualTrades)
                {
                    tickIO.Initialize();

                    tickIO.SetTrade(Last, LastSize);

                    if (symbol.QuoteType == QuoteType.Level1)
                    {
                        if (Bid == 0)
                        {
                            Bid     = Last;
                            BidSize = LastSize;
                        }
                        if (Ask == 0)
                        {
                            Ask     = Last;
                            AskSize = LastSize;
                        }
                        tickIO.SetQuote(Bid, Ask, (ushort)BidSize, (ushort)AskSize);
                    }

                    tickIO.SetSymbol(symbol.BinaryIdentifier);
                    tickIO.SetTime(TimeStamp.UtcNow);

                    TickBinary binary = tickIO.Extract();
                    receiver.OnSend(ref binary);
                }
            }
            else
            {
                VerifyInitialized();
            }
        }
Example #5
0
        public void SendOptionPrice()
        {
            if (!isRunning)
            {
                return;
            }
            if (Symbol.OptionChain != OptionChain.Complete)
            {
                if (!errorOptionChainType)
                {
                    log.Error("Received option price but " + Symbol + " is configured for TimeAndSales = " + Symbol.OptionChain + " in the symbol dictionary.");
                    errorOptionChainType = true;
                }
                return;
            }
            if (!isQuoteInitialized && !VerifyQuote())
            {
                return;
            }

            if (strikePrice == 0D || utcOptionExpiration == default(TimeStamp))
            {
                if (!errorStrikeAndExpiration)
                {
                    log.Error("Received option price but strike or expiration was blank: Strike " + strikePrice + ", " + utcOptionExpiration);
                    errorStrikeAndExpiration = true;
                }
                return;
            }
            tickIO.Initialize();
            tickIO.SetSymbol(Symbol.BinaryIdentifier);
            tickIO.SetTime(Time);
            tickIO.SetOption(optionType, strikePrice, utcOptionExpiration);
            if (Last != 0D)
            {
                tickIO.SetTrade(Last, LastSize);
            }
            if (Bid != 0 && Ask != 0 && BidSize != 0 && AskSize != 0)
            {
                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;
            if (tickIO.IsTrade && tickIO.Price == 0D)
            {
                log.Warn("Found trade tick with zero price: " + tickIO);
            }
            salesLatency.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 trade tick for " + Symbol + ": " + tickIO);
            }
        }