Exemplo n.º 1
0
 public void Copy(TickIO tick, byte contentMask)
 {
     Initialize();
     SetSymbol(tick.lSymbol);
     SetTime(tick.UtcTime);
     binary.contentMask = contentMask;
     if (binary.IsQuote)
     {
         SetQuote(tick.lBid, tick.lAsk);
     }
     if (binary.IsTrade)
     {
         SetTrade(tick.Side, tick.lPrice, tick.Size);
     }
     if (binary.IsOption)
     {
         var type = binary.OptionType;
         SetOption(type, tick.Strike, tick.UtcOptionExpiration);
     }
     if (binary.HasDepthOfMarket)
     {
         fixed(ushort *b = binary.DepthBidLevels)
         fixed(ushort *a = binary.DepthAskLevels)
         for (int i = 0; i < TickBinary.DomLevels; i++)
         {
             *(b + i) = (ushort)tick.BidLevel(i);
             *(a + i) = (ushort)tick.AskLevel(i);
         }
     }
     dataVersion = tick.DataVersion;
 }
Exemplo n.º 2
0
        public void Copy(TickIO tick, byte contentMask)
        {
            bool dom           = (contentMask & ContentBit.DepthOfMarket) != 0;
            bool simulateTicks = (contentMask & ContentBit.SimulateTicks) != 0;
            bool quote         = (contentMask & ContentBit.Quote) != 0;
            bool trade         = (contentMask & ContentBit.TimeAndSales) != 0;

            Initialize();
            SetSymbol(tick.lSymbol);
            SetTime(tick.UtcTime);
            IsSimulateTicks = simulateTicks;
            if (quote)
            {
                SetQuote(tick.lBid, tick.lAsk);
            }
            if (trade)
            {
                SetTrade(tick.Side, tick.lPrice, tick.Size);
            }
            if (dom)
            {
                fixed(ushort *b = binary.DepthBidLevels)
                fixed(ushort *a = binary.DepthAskLevels)
                for (int i = 0; i < TickBinary.DomLevels; i++)
                {
                    *(b + i) = (ushort)tick.BidLevel(i);
                    *(a + i) = (ushort)tick.AskLevel(i);
                }
            }
            binary.ContentMask = contentMask;
            dataVersion        = tick.DataVersion;
        }
Exemplo n.º 3
0
 public override void AssertTick(TickIO tick, TickIO lastTick, ulong symbol)
 {
     Assert.IsTrue(tick.IsQuote);
     if (tick.IsQuote)
     {
         Assert.Greater(tick.Bid, 0);
         Assert.Greater(tick.BidLevel(0), 0);
         Assert.Greater(tick.Ask, 0);
         Assert.Greater(tick.AskLevel(0), 0);
     }
     if (tick.IsTrade)
     {
         Assert.Greater(tick.Price, 0);
         Assert.Greater(tick.Size, 0);
     }
     Assert.IsTrue(tick.Time >= lastTick.Time, "tick.Time > lastTick.Time");
     Assert.AreEqual(symbol, tick.lSymbol);
 }
Exemplo n.º 4
0
 public void AssertTimeAndSales(TickIO tick, TickIO lastTick, long symbol)
 {
     Assert.IsFalse(tick.IsQuote);
     if (tick.IsQuote)
     {
         Assert.Greater(tick.Bid, 0);
         Assert.Greater(tick.BidLevel(0), 0);
         Assert.Greater(tick.Ask, 0);
         Assert.Greater(tick.AskLevel(0), 0);
     }
     Assert.IsTrue(tick.IsTrade);
     if (tick.IsTrade)
     {
         Assert.Greater(tick.Price, 0);
         Assert.Greater(tick.Size, 0);
     }
     Assert.AreEqual(symbol, tick.lSymbol);
 }
Exemplo n.º 5
0
        protected override void TrySendTick(SymbolInfo symbol, TickIO tick)
        {
            if (trace)
            {
                log.Trace("TrySendTick( " + symbol + " " + tick + ")");
            }
            var quoteMessage = QuoteSocket.MessageFactory.Create();
            var lastTick     = lastTicks[symbol.BinaryIdentifier];
            var buffer       = quoteMessage.Data.GetBuffer();
            var position     = quoteMessage.Data.Position;

            quoteMessage.Data.SetLength(1024);
            if (tick.IsTrade)
            {
                var index   = 0;
                var snippet = tradeSnippetBytes[index];
                Array.Copy(snippet, 0, buffer, position, snippet.Length);
                position += snippet.Length;

                // Symbol
                var value = symbol.Symbol.ToCharArray();
                for (var i = 0; i < value.Length; i++)
                {
                    buffer[position] = (byte)value[i];
                    ++position;
                }

                ++index; snippet = tradeSnippetBytes[index];
                Array.Copy(snippet, 0, buffer, position, snippet.Length);
                position += snippet.Length;

                // Price
                var len = ConvertPriceToBytes(tick.lPrice);
                var pos = len;
                for (var i = 0; i < len; i++)
                {
                    buffer[position] = (byte)bytebuffer[--pos];
                    ++position;
                }

                ++index; snippet = tradeSnippetBytes[index];
                Array.Copy(snippet, 0, buffer, position, snippet.Length);
                position += snippet.Length;

                // Size
                value = tick.Size.ToString().ToCharArray();
                for (var i = 0; i < value.Length; i++)
                {
                    buffer[position] = (byte)value[i];
                    ++position;
                }

                ++index; snippet = tradeSnippetBytes[index];
                Array.Copy(snippet, 0, buffer, position, snippet.Length);
                position += snippet.Length;

                // Bid
                if (tick.lBid != lastTick.lBid)
                {
                    value = ("2003=" + tick.Bid + ";").ToCharArray();
                    for (var i = 0; i < value.Length; i++)
                    {
                        buffer[position] = (byte)value[i];
                        ++position;
                    }
                }

                ++index; snippet = tradeSnippetBytes[index];
                Array.Copy(snippet, 0, buffer, position, snippet.Length);
                position += snippet.Length;

                // Ask
                if (tick.lAsk != lastTick.lAsk)
                {
                    value = ("2004=" + tick.Ask + ";").ToCharArray();
                    for (var i = 0; i < value.Length; i++)
                    {
                        buffer[position] = (byte)value[i];
                        ++position;
                    }
                }

                ++index; snippet = tradeSnippetBytes[index];
                Array.Copy(snippet, 0, buffer, position, snippet.Length);
                position += snippet.Length;

                // Ask size
                var askSize = Math.Max((int)tick.AskLevel(0), 1);
                if (askSize != lastTick.AskLevel(0))
                {
                    value = ("2005=" + askSize + ";").ToCharArray();
                    for (var i = 0; i < value.Length; i++)
                    {
                        buffer[position] = (byte)value[i];
                        ++position;
                    }
                }

                ++index; snippet = tradeSnippetBytes[index];
                Array.Copy(snippet, 0, buffer, position, snippet.Length);
                position += snippet.Length;

                // Bid size
                var bidSize = Math.Max((int)tick.BidLevel(0), 1);
                if (bidSize != lastTick.BidLevel(0))
                {
                    value = ("2006=" + bidSize + ";").ToCharArray();
                    for (var i = 0; i < value.Length; i++)
                    {
                        buffer[position] = (byte)value[i];
                        ++position;
                    }
                }

                ++index; snippet = tradeSnippetBytes[index];
                Array.Copy(snippet, 0, buffer, position, snippet.Length);
                position += snippet.Length;
            }
            else
            {
                var index   = 0;
                var snippet = quoteSnippetBytes[index];
                Array.Copy(snippet, 0, buffer, position, snippet.Length);
                position += snippet.Length;

                var value = symbol.Symbol.ToCharArray();
                for (var i = 0; i < value.Length; i++)
                {
                    buffer[position] = (byte)value[i];
                    ++position;
                }

                ++index; snippet = quoteSnippetBytes[index];
                Array.Copy(snippet, 0, buffer, position, snippet.Length);
                position += snippet.Length;

                if (tick.lBid != lastTick.lBid)
                {
                    value = ("2003=" + tick.Bid + ";").ToCharArray();
                    for (var i = 0; i < value.Length; i++)
                    {
                        buffer[position] = (byte)value[i];
                        ++position;
                    }
                }

                ++index; snippet = quoteSnippetBytes[index];
                Array.Copy(snippet, 0, buffer, position, snippet.Length);
                position += snippet.Length;

                if (tick.lAsk != lastTick.lAsk)
                {
                    value = ("2004=" + tick.Ask + ";").ToCharArray();
                    for (var i = 0; i < value.Length; i++)
                    {
                        buffer[position] = (byte)value[i];
                        ++position;
                    }
                }

                ++index; snippet = quoteSnippetBytes[index];
                Array.Copy(snippet, 0, buffer, position, snippet.Length);
                position += snippet.Length;

                var askSize = Math.Max((int)tick.AskLevel(0), 1);
                if (askSize != lastTick.AskLevel(0))
                {
                    value = ("2005=" + askSize + ";").ToCharArray();
                    for (var i = 0; i < value.Length; i++)
                    {
                        buffer[position] = (byte)value[i];
                        ++position;
                    }
                }

                ++index; snippet = quoteSnippetBytes[index];
                Array.Copy(snippet, 0, buffer, position, snippet.Length);
                position += snippet.Length;

                var bidSize = Math.Max((int)tick.BidLevel(0), 1);
                if (bidSize != lastTick.BidLevel(0))
                {
                    value = ("2006=" + bidSize + ";").ToCharArray();
                    for (var i = 0; i < value.Length; i++)
                    {
                        buffer[position] = (byte)value[i];
                        ++position;
                    }
                }

                ++index; snippet = quoteSnippetBytes[index];
                Array.Copy(snippet, 0, buffer, position, snippet.Length);
                position += snippet.Length;
            }

            var strValue = (tick.UtcTime.TimeOfDay + "." + tick.UtcTime.Microsecond.ToString("000") + ";2015=" + tick.UtcTime.Month.ToString("00") +
                            "/" + tick.UtcTime.Day.ToString("00") + "/" + tick.UtcTime.Year + "\n").ToCharArray();

            for (var i = 0; i < strValue.Length; i++)
            {
                buffer[position] = (byte)strValue[i];
                ++position;
            }

            if (trace)
            {
                var message = Encoding.ASCII.GetString(buffer, 0, (int)position);
                log.Trace("Tick message: " + message);
            }
            quoteMessage.Data.Position = position;
            quoteMessage.Data.SetLength(position);
            lastTick.Inject(tick.Extract());

            if (trace)
            {
                log.Trace("Added tick to packet: " + tick.UtcTime);
            }
            quoteMessage.SendUtcTime = tick.UtcTime.Internal;

            if (quoteMessage.Data.GetBuffer().Length == 0)
            {
                return;
            }
            QuotePacketQueue.Enqueue(quoteMessage, quoteMessage.SendUtcTime);
            if (trace)
            {
                log.Trace("Enqueued tick packet: " + new TimeStamp(quoteMessage.SendUtcTime));
            }
        }