private unsafe void TimeAndSalesUpdate(PacketMBTQuotes packet) { SymbolHandler handler = null; MemoryStream data = packet.Data; data.Position += 2; string time = null; string date = null; SymbolInfo symbolInfo = null; fixed(byte *bptr = data.GetBuffer()) { byte *ptr = bptr + data.Position; while (ptr - bptr < data.Length) { int key = packet.GetKey(ref ptr); switch (key) { case 1003: // Symbol string symbol = packet.GetString(ref ptr); symbolInfo = Factory.Symbol.LookupSymbol(symbol); handler = symbolHandlers[symbolInfo.BinaryIdentifier]; break; case 2014: // Time time = packet.GetString(ref ptr); break; case 2015: // Date date = packet.GetString(ref ptr); break; case 2002: // Last Trade Price handler.Last = packet.GetDouble(ref ptr); if (trace) { log.Trace("Got last trade price: " + handler.Last); // + "\n" + packet); } break; case 2007: // Last Trade Size handler.LastSize = packet.GetInt(ref ptr); break; case 2082: // Condition int condition = packet.GetInt(ref ptr); if (condition != 0 && condition != 53 && condition != 45) { log.Info("Trade quote received with non-zero condition: " + condition); } break; case 2083: // Status int status = packet.GetInt(ref ptr); if (status != 0) { log.Info("Trade quote received with non-zero status: " + status); } break; case 2084: // Type int type = packet.GetInt(ref ptr); if (type != 0) { log.Info("Trade quote received with non-zero type: " + type); } break; default: packet.SkipValue(ref ptr); break; } if (*(ptr - 1) == 10) { if (UseLocalTickTime) { var currentTime = TimeStamp.UtcNow; if (currentTime <= prevTime) { currentTime.Internal = prevTime.Internal + 1; } prevTime = currentTime; handler.Time = currentTime; } else { var strings = date.Split(new char[] { '/' }); date = strings[2] + "/" + strings[0] + "/" + strings[1]; handler.Time = new TimeStamp(date + " " + time); } if (handler.Last == 0D) { log.Warn("About to call SendTimeAndSales with Last price = zero."); } handler.SendTimeAndSales(); data.Position++; return; } } } throw new ApplicationException("Expected Trade Quote to end with new line character."); }
private unsafe void Level1Update(PacketMBTQuotes packet) { SymbolHandler handler = null; MemoryStream data = packet.Data; data.Position += 2; string time = null; string date = null; fixed(byte *bptr = data.GetBuffer()) { byte *ptr = bptr + data.Position; while (ptr - bptr < data.Length) { int key = packet.GetKey(ref ptr); switch (key) { case 1003: // Symbol string symbol = packet.GetString(ref ptr); SymbolInfo symbolInfo = Factory.Symbol.LookupSymbol(symbol); handler = symbolHandlers[symbolInfo.BinaryIdentifier]; break; case 2014: // Time time = packet.GetString(ref ptr); break; case 2015: // Date date = packet.GetString(ref ptr); break; case 2003: // Bid handler.Bid = packet.GetDouble(ref ptr); break; case 2004: // Ask handler.Ask = packet.GetDouble(ref ptr); break; case 2005: // Bid Size handler.AskSize = packet.GetInt(ref ptr); break; case 2006: // Ask Size handler.BidSize = packet.GetInt(ref ptr); break; default: packet.SkipValue(ref ptr); break; } if (*(ptr - 1) == 10) { if (UseLocalTickTime) { var currentTime = TimeStamp.UtcNow; if (currentTime == prevTime) { currentTime.Internal = prevTime.Internal + 1; } prevTime = currentTime; handler.Time = currentTime; } else { var strings = date.Split(new char[] { '/' }); date = strings[2] + "/" + strings[0] + "/" + strings[1]; handler.Time = new TimeStamp(date + " " + time); } handler.SendQuote(); data.Position++; return; } } } throw new ApplicationException("Expected Level 1 Quote to end with new line character. Packet:\n" + packet); }