protected override void OnSave(BitArrayWriter writer, IEnumerable <NewsMessage> messages, NewsMetaInfo metaInfo) { var isMetaEmpty = metaInfo.IsEmpty(); writer.WriteInt(messages.Count()); var allowDiffOffsets = metaInfo.Version >= MarketDataVersions.Version46; var isTickPrecision = metaInfo.Version >= MarketDataVersions.Version47; foreach (var news in messages) { if (isMetaEmpty) { metaInfo.ServerOffset = news.ServerTime.Offset; isMetaEmpty = false; } writer.WriteStringEx(news.Id); writer.WriteString(news.Headline); writer.WriteStringEx(news.Story); writer.WriteStringEx(news.Source); writer.WriteStringEx(news.BoardCode); writer.WriteStringEx(news.SecurityId?.SecurityCode); writer.WriteStringEx(news.Url); var lastOffset = metaInfo.LastServerOffset; metaInfo.LastTime = writer.WriteTime(news.ServerTime, metaInfo.LastTime, LocalizedStrings.News, true, true, metaInfo.ServerOffset, allowDiffOffsets, isTickPrecision, ref lastOffset); metaInfo.LastServerOffset = lastOffset; if (metaInfo.Version < MarketDataVersions.Version48) { continue; } writer.Write(news.Priority != null); if (news.Priority != null) { writer.WriteInt((int)news.Priority.Value); } if (metaInfo.Version < MarketDataVersions.Version49) { continue; } writer.WriteStringEx(news.Language); if (metaInfo.Version < MarketDataVersions.Version50) { continue; } writer.Write(news.ExpiryDate != null); if (news.ExpiryDate != null) { writer.WriteLong(news.ExpiryDate.Value.To <long>()); } writer.WriteStringEx(news.SecurityId?.BoardCode); } }
protected override void OnSave(BitArrayWriter writer, IEnumerable <ExecutionMessage> messages, TransactionSerializerMetaInfo metaInfo) { if (metaInfo.IsEmpty()) { var msg = messages.First(); metaInfo.FirstOrderId = metaInfo.LastOrderId = msg.OrderId ?? 0; metaInfo.FirstTradeId = metaInfo.LastTradeId = msg.TradeId ?? 0; metaInfo.FirstTransactionId = metaInfo.LastTransactionId = msg.TransactionId; metaInfo.FirstOriginalTransactionId = metaInfo.LastOriginalTransactionId = msg.OriginalTransactionId; metaInfo.FirstCommission = metaInfo.LastCommission = msg.Commission ?? 0; metaInfo.ServerOffset = msg.ServerTime.Offset; } writer.WriteInt(messages.Count()); var allowNonOrdered = metaInfo.Version >= MarketDataVersions.Version48; var isUtc = metaInfo.Version >= MarketDataVersions.Version51; var allowDiffOffsets = metaInfo.Version >= MarketDataVersions.Version56; foreach (var msg in messages) { var isTrade = msg.ExecutionType == ExecutionTypes.Trade; if (msg.ExecutionType != ExecutionTypes.Order && msg.ExecutionType != ExecutionTypes.Trade) { throw new ArgumentOutOfRangeException(nameof(messages), msg.ExecutionType, LocalizedStrings.Str1695Params.Put(msg.OrderId ?? msg.TradeId)); } // нулевой номер заявки возможен при сохранении в момент регистрации if (msg.OrderId < 0) { throw new ArgumentOutOfRangeException(nameof(messages), msg.OrderId, LocalizedStrings.Str925); } // нулевая цена возможна, если идет "рыночная" продажа по инструменту без планок if (msg.OrderPrice < 0) { throw new ArgumentOutOfRangeException(nameof(messages), msg.OrderPrice, LocalizedStrings.Str926Params.Put(msg.OrderId == null ? msg.OrderStringId : msg.OrderId.To <string>())); } var volume = msg.Volume; if (volume < 0) { throw new ArgumentOutOfRangeException(nameof(messages), volume, LocalizedStrings.Str927Params.Put(msg.OrderId == null ? msg.OrderStringId : msg.OrderId.To <string>())); } if (isTrade) { if ((msg.TradeId == null && msg.TradeStringId.IsEmpty()) || msg.TradeId <= 0) { throw new ArgumentOutOfRangeException(nameof(messages), msg.TradeId, LocalizedStrings.Str928Params.Put(msg.TransactionId)); } if (msg.TradePrice == null || msg.TradePrice <= 0) { throw new ArgumentOutOfRangeException(nameof(messages), msg.TradePrice, LocalizedStrings.Str929Params.Put(msg.TradeId, msg.OrderId)); } } writer.WriteInt((int)msg.ExecutionType); metaInfo.LastTransactionId = writer.SerializeId(msg.TransactionId, metaInfo.LastTransactionId); metaInfo.LastOriginalTransactionId = writer.SerializeId(msg.OriginalTransactionId, metaInfo.LastOriginalTransactionId); if (!isTrade) { if (metaInfo.Version < MarketDataVersions.Version50) { metaInfo.LastOrderId = writer.SerializeId(msg.OrderId ?? 0, metaInfo.LastOrderId); } else { writer.Write(msg.OrderId != null); if (msg.OrderId != null) { metaInfo.LastOrderId = writer.SerializeId(msg.OrderId.Value, metaInfo.LastOrderId); } else { writer.Write(!msg.OrderStringId.IsEmpty()); if (!msg.OrderStringId.IsEmpty()) { writer.WriteString(msg.OrderStringId); } } writer.Write(!msg.OrderBoardId.IsEmpty()); if (!msg.OrderBoardId.IsEmpty()) { writer.WriteString(msg.OrderBoardId); } } } else { if (metaInfo.Version < MarketDataVersions.Version50) { metaInfo.LastTradeId = writer.SerializeId(msg.TradeId ?? 0, metaInfo.LastTradeId); } else { writer.Write(msg.TradeId != null); if (msg.TradeId != null) { metaInfo.LastTradeId = writer.SerializeId(msg.TradeId.Value, metaInfo.LastTradeId); } else { writer.Write(!msg.TradeStringId.IsEmpty()); if (!msg.TradeStringId.IsEmpty()) { writer.WriteString(msg.TradeStringId); } } } } writer.Write(msg.Side == Sides.Buy); writer.WritePriceEx(!isTrade ? msg.OrderPrice : msg.GetTradePrice(), metaInfo, SecurityId); if (metaInfo.Version < MarketDataVersions.Version57) { writer.WriteVolume(volume ?? 0, metaInfo, SecurityId); } else { writer.Write(volume != null); if (volume != null) { writer.WriteVolume(volume.Value, metaInfo, SecurityId); } } if (metaInfo.Version < MarketDataVersions.Version54) { writer.WriteVolume(msg.VisibleVolume ?? 0, metaInfo, SecurityId); writer.WriteVolume(msg.Balance ?? 0, metaInfo, SecurityId); } else { writer.Write(msg.VisibleVolume != null); if (msg.VisibleVolume != null) { writer.WriteVolume(msg.VisibleVolume.Value, metaInfo, SecurityId); } writer.Write(msg.Balance != null); if (msg.Balance != null) { writer.WriteVolume(msg.Balance.Value, metaInfo, SecurityId); } } var lastOffset = metaInfo.LastServerOffset; metaInfo.LastTime = writer.WriteTime(msg.ServerTime, metaInfo.LastTime, LocalizedStrings.Str930, allowNonOrdered, isUtc, metaInfo.ServerOffset, allowDiffOffsets, ref lastOffset); metaInfo.LastServerOffset = lastOffset; writer.WriteInt((int)msg.OrderType); writer.WriteNullableInt(msg.OrderState); writer.WriteNullableInt(msg.OrderStatus); if (metaInfo.Version < MarketDataVersions.Version52) { writer.WriteInt(msg.TradeStatus ?? 0); } else { writer.WriteNullableInt(msg.TradeStatus); } if (metaInfo.Version < MarketDataVersions.Version53) { writer.WriteInt((int)(msg.TimeInForce ?? TimeInForce.PutInQueue)); } else { writer.Write(msg.TimeInForce != null); if (msg.TimeInForce != null) { writer.WriteInt((int)msg.TimeInForce.Value); } } if (metaInfo.Version < MarketDataVersions.Version52) { writer.Write(msg.IsSystem ?? true); } else { writer.Write(msg.IsSystem != null); if (msg.IsSystem != null) { writer.Write(msg.IsSystem.Value); } } writer.WriteLong(msg.ExpiryDate != null ? msg.ExpiryDate.Value.Ticks : 0L); WriteCommission(writer, metaInfo, msg.Commission); WriteString(writer, metaInfo.Portfolios, msg.PortfolioName); WriteString(writer, metaInfo.StrategyIds, msg.UserOrderId); WriteString(writer, metaInfo.Comments, msg.Comment); WriteString(writer, metaInfo.Errors, msg.Error != null ? msg.Error.Message : null); if (metaInfo.Version < MarketDataVersions.Version55) { continue; } writer.Write(msg.Currency != null); if (msg.Currency != null) { writer.WriteInt((int)msg.Currency.Value); } } }
protected override void OnSave(BitArrayWriter writer, IEnumerable <NewsMessage> messages, NewsMetaInfo metaInfo) { var isMetaEmpty = metaInfo.IsEmpty(); writer.WriteInt(messages.Count()); var allowDiffOffsets = metaInfo.Version >= MarketDataVersions.Version46; var isTickPrecision = metaInfo.Version >= MarketDataVersions.Version47; foreach (var news in messages) { if (isMetaEmpty) { metaInfo.ServerOffset = news.ServerTime.Offset; isMetaEmpty = false; } if (news.Id.IsEmpty()) { writer.Write(false); } else { writer.Write(true); writer.WriteString(news.Id); } writer.WriteString(news.Headline); if (news.Story.IsEmpty()) { writer.Write(false); } else { writer.Write(true); writer.WriteString(news.Story); } if (news.Source.IsEmpty()) { writer.Write(false); } else { writer.Write(true); writer.WriteString(news.Source); } if (news.BoardCode.IsEmpty()) { writer.Write(false); } else { writer.Write(true); writer.WriteString(news.BoardCode); } if (news.SecurityId == null) { writer.Write(false); } else { writer.Write(true); writer.WriteString(news.SecurityId.Value.SecurityCode); } if (news.Url == null) { writer.Write(false); } else { writer.Write(true); writer.WriteString(news.Url.To <string>()); } var lastOffset = metaInfo.LastServerOffset; metaInfo.LastTime = writer.WriteTime(news.ServerTime, metaInfo.LastTime, LocalizedStrings.News, true, true, metaInfo.ServerOffset, allowDiffOffsets, isTickPrecision, ref lastOffset); metaInfo.LastServerOffset = lastOffset; } }
protected override void OnSave(BitArrayWriter writer, IEnumerable <ExecutionMessage> messages, TransactionSerializerMetaInfo metaInfo) { if (metaInfo.IsEmpty()) { var msg = messages.First(); metaInfo.FirstOrderId = metaInfo.LastOrderId = msg.OrderId ?? 0; metaInfo.FirstTradeId = metaInfo.LastTradeId = msg.TradeId ?? 0; metaInfo.FirstTransactionId = metaInfo.LastTransactionId = msg.TransactionId; metaInfo.FirstOriginalTransactionId = metaInfo.LastOriginalTransactionId = msg.OriginalTransactionId; metaInfo.FirstCommission = metaInfo.LastCommission = msg.Commission ?? 0; metaInfo.FirstPnL = metaInfo.LastPnL = msg.PnL ?? 0; metaInfo.FirstPosition = metaInfo.LastPosition = msg.Position ?? 0; metaInfo.FirstSlippage = metaInfo.LastSlippage = msg.Slippage ?? 0; metaInfo.FirstItemLocalTime = metaInfo.LastItemLocalTime = msg.LocalTime.UtcDateTime; metaInfo.FirstItemLocalOffset = metaInfo.LastItemLocalOffset = msg.LocalTime.Offset; metaInfo.ServerOffset = msg.ServerTime.Offset; } writer.WriteInt(messages.Count()); var allowNonOrdered = metaInfo.Version >= MarketDataVersions.Version48; var isUtc = metaInfo.Version >= MarketDataVersions.Version51; var allowDiffOffsets = metaInfo.Version >= MarketDataVersions.Version56; var isTickPrecision = metaInfo.Version >= MarketDataVersions.Version60; foreach (var msg in messages) { if (msg.ExecutionType != ExecutionTypes.Transaction) { throw new ArgumentOutOfRangeException(nameof(messages), msg.ExecutionType, LocalizedStrings.Str1695Params.Put(msg)); } // нулевой номер заявки возможен при сохранении в момент регистрации if (msg.OrderId < 0) { throw new ArgumentOutOfRangeException(nameof(messages), msg.OrderId, LocalizedStrings.Str925); } // нулевая цена возможна, если идет "рыночная" продажа по инструменту без планок if (msg.OrderPrice < 0) { throw new ArgumentOutOfRangeException(nameof(messages), msg.OrderPrice, LocalizedStrings.Str926Params.Put(msg.OrderId == null ? msg.OrderStringId : msg.OrderId.To <string>())); } //var volume = msg.Volume; //if (volume < 0) // throw new ArgumentOutOfRangeException(nameof(messages), volume, LocalizedStrings.Str927Params.Put(msg.OrderId == null ? msg.OrderStringId : msg.OrderId.To<string>())); if (msg.HasTradeInfo()) { //if ((msg.TradeId == null && msg.TradeStringId.IsEmpty()) || msg.TradeId <= 0) // throw new ArgumentOutOfRangeException(nameof(messages), msg.TradeId, LocalizedStrings.Str928Params.Put(msg.TransactionId)); if (msg.TradePrice == null || msg.TradePrice <= 0) { throw new ArgumentOutOfRangeException(nameof(messages), msg.TradePrice, LocalizedStrings.Str929Params.Put(msg.TradeId, msg.OrderId)); } } metaInfo.LastTransactionId = writer.SerializeId(msg.TransactionId, metaInfo.LastTransactionId); metaInfo.LastOriginalTransactionId = writer.SerializeId(msg.OriginalTransactionId, metaInfo.LastOriginalTransactionId); writer.Write(msg.HasOrderInfo); writer.Write(msg.HasTradeInfo); writer.Write(msg.OrderId != null); if (msg.OrderId != null) { metaInfo.LastOrderId = writer.SerializeId(msg.OrderId.Value, metaInfo.LastOrderId); } else { writer.Write(!msg.OrderStringId.IsEmpty()); if (!msg.OrderStringId.IsEmpty()) { writer.WriteString(msg.OrderStringId); } } writer.Write(!msg.OrderBoardId.IsEmpty()); if (!msg.OrderBoardId.IsEmpty()) { writer.WriteString(msg.OrderBoardId); } writer.Write(msg.TradeId != null); if (msg.TradeId != null) { metaInfo.LastTradeId = writer.SerializeId(msg.TradeId.Value, metaInfo.LastTradeId); } else { writer.Write(!msg.TradeStringId.IsEmpty()); if (!msg.TradeStringId.IsEmpty()) { writer.WriteString(msg.TradeStringId); } } if (msg.OrderPrice != 0) { writer.Write(true); writer.WritePriceEx(msg.OrderPrice, metaInfo, SecurityId); } else { writer.Write(false); } if (msg.TradePrice != null) { writer.Write(true); writer.WritePriceEx(msg.TradePrice.Value, metaInfo, SecurityId); } else { writer.Write(false); } writer.Write(msg.Side == Sides.Buy); writer.Write(msg.OrderVolume != null); if (msg.OrderVolume != null) { writer.WriteVolume(msg.OrderVolume.Value, metaInfo, SecurityId); } writer.Write(msg.TradeVolume != null); if (msg.TradeVolume != null) { writer.WriteVolume(msg.TradeVolume.Value, metaInfo, SecurityId); } writer.Write(msg.VisibleVolume != null); if (msg.VisibleVolume != null) { writer.WriteVolume(msg.VisibleVolume.Value, metaInfo, SecurityId); } writer.Write(msg.Balance != null); if (msg.Balance != null) { writer.WriteVolume(msg.Balance.Value, metaInfo, SecurityId); } var lastOffset = metaInfo.LastServerOffset; metaInfo.LastTime = writer.WriteTime(msg.ServerTime, metaInfo.LastTime, LocalizedStrings.Str930, allowNonOrdered, isUtc, metaInfo.ServerOffset, allowDiffOffsets, isTickPrecision, ref lastOffset); metaInfo.LastServerOffset = lastOffset; writer.WriteNullableInt((int?)msg.OrderType); writer.WriteNullableInt((int?)msg.OrderState); writer.WriteNullableLong(msg.OrderStatus); writer.WriteNullableInt(msg.TradeStatus); writer.WriteNullableInt((int?)msg.TimeInForce); writer.Write(msg.IsSystem != null); if (msg.IsSystem != null) { writer.Write(msg.IsSystem.Value); } writer.Write(msg.IsUpTick != null); if (msg.IsUpTick != null) { writer.Write(msg.IsUpTick.Value); } writer.WriteDto(msg.ExpiryDate); metaInfo.LastCommission = Write(writer, msg.Commission, metaInfo.LastCommission); metaInfo.LastPnL = Write(writer, msg.PnL, metaInfo.LastPnL); metaInfo.LastPosition = Write(writer, msg.Position, metaInfo.LastPosition); metaInfo.LastSlippage = Write(writer, msg.Slippage, metaInfo.LastSlippage); WriteString(writer, metaInfo.Portfolios, msg.PortfolioName); WriteString(writer, metaInfo.ClientCodes, msg.ClientCode); WriteString(writer, metaInfo.BrokerCodes, msg.BrokerCode); WriteString(writer, metaInfo.DepoNames, msg.DepoName); WriteString(writer, metaInfo.UserOrderIds, msg.UserOrderId); WriteString(writer, metaInfo.Comments, msg.Comment); WriteString(writer, metaInfo.SystemComments, msg.SystemComment); WriteString(writer, metaInfo.Errors, msg.Error?.Message); writer.WriteNullableInt((int?)msg.Currency); writer.Write(msg.Latency != null); if (msg.Latency != null) { writer.WriteLong(msg.Latency.Value.Ticks); } writer.Write(msg.OriginSide != null); if (msg.OriginSide != null) { writer.Write(msg.OriginSide.Value == Sides.Buy); } if (metaInfo.Version < MarketDataVersions.Version59) { continue; } WriteItemLocalTime(writer, metaInfo, msg, isTickPrecision); if (metaInfo.Version < MarketDataVersions.Version61) { continue; } writer.Write(msg.IsMarketMaker != null); if (msg.IsMarketMaker != null) { writer.Write(msg.IsMarketMaker.Value); } if (metaInfo.Version < MarketDataVersions.Version62) { continue; } writer.Write(msg.IsMargin != null); if (msg.IsMargin != null) { writer.Write(msg.IsMargin.Value); } } }
protected override void OnSave(BitArrayWriter writer, IEnumerable <NewsMessage> messages, NewsMetaInfo metaInfo) { var isMetaEmpty = metaInfo.IsEmpty(); writer.WriteInt(messages.Count()); foreach (var news in messages) { if (isMetaEmpty) { metaInfo.ServerOffset = news.ServerTime.Offset; isMetaEmpty = false; } if (news.Id.IsEmpty()) { writer.Write(false); } else { writer.Write(true); writer.WriteString(news.Id); } writer.WriteString(news.Headline); if (news.Story.IsEmpty()) { writer.Write(false); } else { writer.Write(true); writer.WriteString(news.Story); } if (news.Source.IsEmpty()) { writer.Write(false); } else { writer.Write(true); writer.WriteString(news.Source); } if (news.BoardCode.IsEmpty()) { writer.Write(false); } else { writer.Write(true); writer.WriteString(news.BoardCode); } if (news.SecurityId == null) { writer.Write(false); } else { writer.Write(true); writer.WriteString(news.SecurityId.Value.SecurityCode); } if (news.Url == null) { writer.Write(false); } else { writer.Write(true); writer.WriteString(news.Url.To <string>()); } metaInfo.LastTime = writer.WriteTime(news.ServerTime, metaInfo.LastTime, LocalizedStrings.News, true, true, metaInfo.ServerOffset); } }