// ********************************************************************** public void Write(DateTime dateTime, OwnTradeReply reply) { dw.WriteRecHeader(sid, dateTime); dw.WriteGrowing(DateTimeHelper.ToMs(reply.DateTime), ref lastMilliseconds); dw.WriteLeb128(reply.TradeId - lastTradeId); lastTradeId = reply.TradeId; dw.WriteLeb128(reply.OrderId - lastOrderId); lastOrderId = reply.OrderId; dw.WriteLeb128(reply.Price - lastPrice); lastPrice = reply.Price; dw.WriteLeb128(reply.Quantity); }
// ********************************************************************** public void Write(DateTime dateTime, OwnOrder order) { dw.WriteRecHeader(sid, dateTime); if (order.Id == 0 && order.Price == 0) { dw.Write((byte)OrderFlags.DropAll); } else { OrderFlags flags; switch (order.Type) { case OwnOrderType.Regular: flags = OrderFlags.Active; break; case OwnOrderType.Stop: flags = OrderFlags.Active | OrderFlags.Stop; break; default: flags = OrderFlags.None; break; } if (order.Id > 0) { flags |= OrderFlags.External; } dw.Write((byte)flags); dw.WriteLeb128(order.Id); dw.WriteLeb128(order.Price); dw.WriteLeb128(order.Quantity); } }
// ********************************************************************** public void Write(DateTime dateTime, Deal deal) { dw.WriteRecHeader(sid, dateTime); // ------------------------------------------------------------ long milliseconds = DateTimeHelper.ToMs(deal.DateTime); DealFlags flags = (DealFlags)deal.Type & DealFlags.Type; if (lastMilliseconds != milliseconds) { flags |= DealFlags.DateTime; } if (deal.Id != 0) { flags |= DealFlags.Id; } //if(deal.OrderId != 0) // flags |= DealFlags.OrderId; if (lastRawPrice != deal.Price) { lastRawPrice = deal.Price; flags |= DealFlags.Price; } if (lastVolume != deal.Volume) { flags |= DealFlags.Volume; } if (lastOI != deal.OI) { flags |= DealFlags.OI; } // ------------------------------------------------------------ dw.Write((byte)flags); // ------------------------------------------------------------ if ((flags & DealFlags.DateTime) != 0) { dw.WriteGrowing(milliseconds, ref lastMilliseconds); } if ((flags & DealFlags.Id) != 0) { dw.WriteGrowing(deal.Id, ref lastId); } if ((flags & DealFlags.Price) != 0) { int p = s.GetTicks(deal.Price); dw.WriteLeb128(p - lastPrice); lastPrice = p; } if ((flags & DealFlags.Volume) != 0) { dw.WriteLeb128(deal.Volume); lastVolume = deal.Volume; } if ((flags & DealFlags.OI) != 0) { dw.WriteLeb128(deal.OI - lastOI); lastOI = deal.OI; } // ------------------------------------------------------------ }
// ********************************************************************** public void Write(DateTime dateTime, OrdLogEntry entry) { dw.WriteRecHeader(sid, dateTime); // ------------------------------------------------------------ long milliseconds = DateTimeHelper.ToMs(entry.DateTime); OrdLogEntryFlags flags = OrdLogEntryFlags.None; // ------------------------------------------------------------ if (lastMilliseconds != milliseconds) { flags |= OrdLogEntryFlags.DateTime; } if (lastOrderId != entry.OrderId) { flags |= OrdLogEntryFlags.OrderId; } if (lastPrice != entry.Price) { flags |= OrdLogEntryFlags.Price; } if (lastAmount != entry.Amount) { flags |= OrdLogEntryFlags.Amount; } if ((entry.Flags & OrdLogFlags.Fill) != 0) { if (lastAmountRest != entry.AmountRest) { flags |= OrdLogEntryFlags.AmountRest; } if (lastDealId != entry.DealId) { flags |= OrdLogEntryFlags.DealId; } if (lastDealPrice != entry.DealPrice) { flags |= OrdLogEntryFlags.DealPrice; } if (lastOI != entry.OI) { flags |= OrdLogEntryFlags.OI; } } // ------------------------------------------------------------ dw.Write((byte)flags); // ------------------------------------------------------------ dw.Write((ushort)entry.Flags); if ((flags & OrdLogEntryFlags.DateTime) != 0) { dw.WriteGrowing(milliseconds, ref lastMilliseconds); } if ((flags & OrdLogEntryFlags.OrderId) != 0) { if ((entry.Flags & OrdLogFlags.Add) != 0) { dw.WriteGrowing(entry.OrderId, ref lastOrderId); } else { dw.WriteLeb128(entry.OrderId - lastOrderId); } } if ((flags & OrdLogEntryFlags.Price) != 0) { dw.WriteLeb128(entry.Price - lastPrice); lastPrice = entry.Price; } if ((flags & OrdLogEntryFlags.Amount) != 0) { dw.WriteLeb128(entry.Amount); lastAmount = entry.Amount; } if ((flags & OrdLogEntryFlags.AmountRest) != 0) { dw.WriteLeb128(entry.AmountRest); lastAmountRest = entry.AmountRest; } if ((flags & OrdLogEntryFlags.DealId) != 0) { dw.WriteGrowing(entry.DealId, ref lastDealId); } if ((flags & OrdLogEntryFlags.DealPrice) != 0) { dw.WriteLeb128(entry.DealPrice - lastDealPrice); lastDealPrice = entry.DealPrice; } if ((flags & OrdLogEntryFlags.OI) != 0) { dw.WriteLeb128(entry.OI - lastOI); lastOI = entry.OI; } // ------------------------------------------------------------ }
// ********************************************************************** public void Write(DateTime dateTime, Quote[] quotes) { // ------------------------------------------------------------ diffQuotes.Clear(); int i = 0; foreach (Quote lq in lastQuotes) { while (i < quotes.Length && lq.Price < quotes[i].Price) { diffQuotes.Add(quotes[i++]); } if (i < quotes.Length && quotes[i].Price == lq.Price) { if (!QuoteTypeEquals(lq.Type, quotes[i].Type) || lq.Volume != quotes[i].Volume) { diffQuotes.Add(quotes[i]); } i++; } else { diffQuotes.Add(new Quote(lq.Price, 0, QuoteType.Unknown)); } } while (i < quotes.Length) { diffQuotes.Add(quotes[i++]); } lastQuotes = quotes; // ------------------------------------------------------------ if (diffQuotes.Count > 0) { dw.WriteRecHeader(sid, dateTime); dw.WriteLeb128(diffQuotes.Count); foreach (Quote q in diffQuotes) { dw.WriteLeb128(q.Price - lastPrice); lastPrice = q.Price; switch (q.Type) { case QuoteType.Ask: case QuoteType.BestAsk: dw.WriteLeb128(q.Volume); break; case QuoteType.Bid: case QuoteType.BestBid: dw.WriteLeb128(-q.Volume); break; default: dw.WriteLeb128(0); break; } } } // ------------------------------------------------------------ }
// ********************************************************************** public void Write(DateTime dateTime, AuxInfo auxInfo) { dw.WriteRecHeader(sid, dateTime); // -------------------------------------------------- long milliseconds = DateTimeHelper.ToMs(auxInfo.DateTime); AuxInfoFlags flags = AuxInfoFlags.None; // -------------------------------------------------- if (lastMilliseconds != milliseconds) { flags |= AuxInfoFlags.DateTime; } if (lastAskTotal != auxInfo.AskTotal) { flags |= AuxInfoFlags.AskTotal; } if (lastBidTotal != auxInfo.BidTotal) { flags |= AuxInfoFlags.BidTotal; } if (lastOI != auxInfo.OI) { flags |= AuxInfoFlags.OI; } if (lastPrice != auxInfo.Price) { flags |= AuxInfoFlags.Price; } if (lastHiLimit != auxInfo.HiLimit || lastLoLimit != auxInfo.LoLimit || lastDeposit != auxInfo.Deposit) { flags |= AuxInfoFlags.SessionInfo; } if (lastRate != auxInfo.Rate) { flags |= AuxInfoFlags.Rate; } if (auxInfo.Message != null) { flags |= AuxInfoFlags.Message; } // -------------------------------------------------- dw.Write((byte)flags); // -------------------------------------------------- if ((flags & AuxInfoFlags.DateTime) != 0) { dw.WriteGrowing(milliseconds, ref lastMilliseconds); } if ((flags & AuxInfoFlags.AskTotal) != 0) { dw.WriteLeb128(auxInfo.AskTotal - lastAskTotal); lastAskTotal = auxInfo.AskTotal; } if ((flags & AuxInfoFlags.BidTotal) != 0) { dw.WriteLeb128(auxInfo.BidTotal - lastBidTotal); lastBidTotal = auxInfo.BidTotal; } if ((flags & AuxInfoFlags.OI) != 0) { dw.WriteLeb128(auxInfo.OI - lastOI); lastOI = auxInfo.OI; } if ((flags & AuxInfoFlags.Price) != 0) { dw.WriteLeb128(auxInfo.Price - lastPrice); lastPrice = auxInfo.Price; } if ((flags & AuxInfoFlags.SessionInfo) != 0) { dw.WriteLeb128(auxInfo.HiLimit); dw.WriteLeb128(auxInfo.LoLimit); dw.Write(auxInfo.Deposit); lastHiLimit = auxInfo.HiLimit; lastLoLimit = auxInfo.LoLimit; lastDeposit = auxInfo.Deposit; } if ((flags & AuxInfoFlags.Rate) != 0) { dw.Write(auxInfo.Rate); lastRate = auxInfo.Rate; } if ((flags & AuxInfoFlags.Message) != 0) { dw.Write(auxInfo.Message); } // -------------------------------------------------- }