PositionChangeMessage ISnapshotSerializer <Key, PositionChangeMessage> .Deserialize(Version version, byte[] buffer)
        {
            if (version == null)
            {
                throw new ArgumentNullException(nameof(version));
            }

            using (var handle = new GCHandle <byte[]>(buffer))
            {
                var snapshot = handle.CreatePointer().ToStruct <PositionSnapshot>(true);

                var posMsg = new PositionChangeMessage
                {
                    SecurityId    = snapshot.SecurityId.ToSecurityId(),
                    PortfolioName = snapshot.Portfolio,
                    ServerTime    = snapshot.LastChangeServerTime.To <DateTimeOffset>(),
                    LocalTime     = snapshot.LastChangeLocalTime.To <DateTimeOffset>(),
                    ClientCode    = snapshot.ClientCode,
                    DepoName      = snapshot.DepoName,
                    BoardCode     = snapshot.BoardCode,
                    LimitType     = (TPlusLimits?)snapshot.LimitType,
                    Description   = snapshot.Description,
                    StrategyId    = snapshot.StrategyId,
                    Side          = (Sides?)snapshot.Side,
                    BuildFrom     = snapshot.BuildFrom,
                }
                .TryAdd(PositionChangeTypes.BeginValue, snapshot.BeginValue, true)
                .TryAdd(PositionChangeTypes.CurrentValue, snapshot.CurrentValue, true)
                .TryAdd(PositionChangeTypes.BlockedValue, snapshot.BlockedValue, true)
                .TryAdd(PositionChangeTypes.CurrentPrice, snapshot.CurrentPrice, true)
                .TryAdd(PositionChangeTypes.AveragePrice, snapshot.AveragePrice, true)
                .TryAdd(PositionChangeTypes.UnrealizedPnL, snapshot.UnrealizedPnL, true)
                .TryAdd(PositionChangeTypes.RealizedPnL, snapshot.RealizedPnL, true)
                .TryAdd(PositionChangeTypes.VariationMargin, snapshot.VariationMargin, true)
                .TryAdd(PositionChangeTypes.Leverage, snapshot.Leverage, true)
                .TryAdd(PositionChangeTypes.Commission, snapshot.Commission, true)
                .TryAdd(PositionChangeTypes.CurrentValueInLots, snapshot.CurrentValueInLots, true)
                .TryAdd(PositionChangeTypes.CommissionTaker, snapshot.CommissionTaker, true)
                .TryAdd(PositionChangeTypes.CommissionMaker, snapshot.CommissionMaker, true)
                .TryAdd(PositionChangeTypes.SettlementPrice, snapshot.SettlementPrice, true)
                .TryAdd(PositionChangeTypes.ExpirationDate, snapshot.ExpirationDate.To <DateTimeOffset?>())
                .TryAdd(PositionChangeTypes.BuyOrdersCount, snapshot.BuyOrdersCount, true)
                .TryAdd(PositionChangeTypes.SellOrdersCount, snapshot.SellOrdersCount, true)
                .TryAdd(PositionChangeTypes.BuyOrdersMargin, snapshot.BuyOrdersMargin, true)
                .TryAdd(PositionChangeTypes.SellOrdersMargin, snapshot.SellOrdersMargin, true)
                .TryAdd(PositionChangeTypes.OrdersMargin, snapshot.OrdersMargin, true)
                .TryAdd(PositionChangeTypes.OrdersCount, snapshot.OrdersCount, true)
                .TryAdd(PositionChangeTypes.TradesCount, snapshot.TradesCount, true)
                .TryAdd(PositionChangeTypes.State, snapshot.State?.ToEnum <PortfolioStates>())
                ;

                if (snapshot.Currency != null)
                {
                    posMsg.Add(PositionChangeTypes.Currency, (CurrencyTypes)snapshot.Currency.Value);
                }

                return(posMsg);
            }
        }
        ExecutionMessage ISnapshotSerializer <string, ExecutionMessage> .Deserialize(Version version, byte[] buffer)
        {
            if (version == null)
            {
                throw new ArgumentNullException(nameof(version));
            }

            using (var handle = new GCHandle <byte[]>(buffer))
            {
                var ptr = handle.CreatePointer();

                var snapshot = ptr.ToStruct <TransactionSnapshot>(true);

                var execMsg = new ExecutionMessage
                {
                    SecurityId    = snapshot.SecurityId.ToSecurityId(),
                    PortfolioName = snapshot.PortfolioName,
                    ServerTime    = snapshot.LastChangeServerTime.To <DateTimeOffset>(),
                    LocalTime     = snapshot.LastChangeLocalTime.To <DateTimeOffset>(),

                    ExecutionType = ExecutionTypes.Transaction,

                    //OriginalTransactionId = snapshot.OriginalTransactionId,
                    TransactionId = snapshot.TransactionId,

                    HasOrderInfo = snapshot.HasOrderInfo,
                    HasTradeInfo = snapshot.HasTradeInfo,

                    BrokerCode = snapshot.BrokerCode,
                    ClientCode = snapshot.ClientCode,

                    Comment       = snapshot.Comment,
                    SystemComment = snapshot.SystemComment,

                    Currency = snapshot.Currency == null ? (CurrencyTypes?)null : (CurrencyTypes)snapshot.Currency.Value,
                    DepoName = snapshot.DepoName,
                    Error    = snapshot.Error.IsEmpty() ? null : new InvalidOperationException(snapshot.Error),

                    ExpiryDate    = snapshot.ExpiryDate?.To <DateTimeOffset>(),
                    IsMarketMaker = snapshot.IsMarketMaker == null ? (bool?)null : (snapshot.IsMarketMaker.Value == 1),
                    IsMargin      = snapshot.IsMargin == null ? (bool?)null : (snapshot.IsMargin.Value == 1),
                    IsManual      = snapshot.IsManual == null ? (bool?)null : (snapshot.IsManual.Value == 1),
                    Side          = (Sides)snapshot.Side,
                    OrderId       = snapshot.OrderId,
                    OrderStringId = snapshot.OrderStringId,
                    OrderBoardId  = snapshot.OrderBoardId,
                    OrderPrice    = snapshot.OrderPrice,
                    OrderVolume   = snapshot.OrderVolume,
                    VisibleVolume = snapshot.VisibleVolume,
                    OrderType     = snapshot.OrderType == null ? (OrderTypes?)null : (OrderTypes)snapshot.OrderType.Value,
                    OrderState    = snapshot.OrderState == null ? (OrderStates?)null : (OrderStates)snapshot.OrderState.Value,
                    OrderStatus   = snapshot.OrderStatus,
                    Balance       = snapshot.Balance,
                    UserOrderId   = snapshot.UserOrderId,
                    OriginSide    = snapshot.OriginSide == null ? (Sides?)null : (Sides)snapshot.OriginSide.Value,
                    Latency       = snapshot.Latency == null ? (TimeSpan?)null : TimeSpan.FromTicks(snapshot.Latency.Value),
                    PnL           = snapshot.PnL,
                    Position      = snapshot.Position,
                    Slippage      = snapshot.Slippage,
                    Commission    = snapshot.Commission,
                    TradePrice    = snapshot.TradePrice,
                    TradeVolume   = snapshot.TradeVolume,
                    TradeStatus   = snapshot.TradeStatus,
                    TradeId       = snapshot.TradeId,
                    TradeStringId = snapshot.TradeStringId,
                    OpenInterest  = snapshot.OpenInterest,
                    IsSystem      = snapshot.IsSystem == null ? (bool?)null : (snapshot.IsSystem.Value == 1),
                    TimeInForce   = snapshot.OrderTif == null ? (TimeInForce?)null : (TimeInForce)snapshot.OrderTif.Value,
                };

                //var paramSize = (version > SnapshotVersions.V20 ? typeof(TransactionConditionParamV21) : typeof(TransactionConditionParamV20)).SizeOf();

                if (!snapshot.ConditionType.IsEmpty())
                {
                    execMsg.Condition = snapshot.ConditionType.To <Type>().CreateInstance <OrderCondition>();
                    execMsg.Condition.Parameters.Clear();                     // removing pre-defined values
                }

                for (var i = 0; i < snapshot.ConditionParamsCount; i++)
                {
                    var param = ptr.ToStruct <TransactionConditionParamV21>(true);

                    var typeBuffer = new byte[param.ValueTypeLen];
                    ptr.CopyTo(typeBuffer, true);

                    var paramTypeName = typeBuffer.UTF8();

                    try
                    {
                        var paramType = paramTypeName.To <Type>();

                        object value;

                        if (param.NumValue != null)
                        {
                            value = (long)param.NumValue;
                        }
                        else if (param.DecimalValue != null)
                        {
                            value = (decimal)param.DecimalValue;
                        }
                        else if (param.BoolValue != null)
                        {
                            value = (bool)param.BoolValue;
                        }
                        //else if (paramType == typeof(Unit))
                        //	value = param.StringValue.ToUnit();
                        else if (param.StringValueLen > 0)
                        {
                            var strBuffer = new byte[param.StringValueLen];
                            ptr.CopyTo(strBuffer, true);

                            if (typeof(IPersistable).IsAssignableFrom(paramType))
                            {
                                var persistable = paramType.CreateInstance <IPersistable>();
                                persistable.Load(new XmlSerializer <SettingsStorage>().Deserialize(strBuffer));
                                value = persistable;
                            }
                            else if (typeof(IRange).IsAssignableFrom(paramType))
                            {
                                var range = paramType.CreateInstance <IRange>();

                                var storage = new XmlSerializer <SettingsStorage>().Deserialize(strBuffer);

                                if (storage.ContainsKey(nameof(range.Min)))
                                {
                                    range.Min = storage.GetValue <object>(nameof(range.Min));
                                }

                                if (storage.ContainsKey(nameof(range.Max)))
                                {
                                    range.Max = storage.GetValue <object>(nameof(range.Max));
                                }

                                value = range;
                            }
                            else
                            {
                                value = typeof(XmlSerializer <>).Make(paramType).CreateInstance <ISerializer>().Deserialize(strBuffer);
                            }
                        }
                        else
                        {
                            value = null;
                        }

                        value = value.To(paramType);
                        execMsg.Condition.Parameters.Add(param.Name, value);
                    }
                    catch (Exception ex)
                    {
                        ex.LogError();
                    }
                }

                return(execMsg);
            }
        }
        Level1ChangeMessage ISnapshotSerializer <SecurityId, Level1ChangeMessage> .Deserialize(Version version, byte[] buffer)
        {
            if (version == null)
            {
                throw new ArgumentNullException(nameof(version));
            }

            using (var handle = new GCHandle <byte[]>(buffer))
            {
                var snapshot = handle.CreatePointer().ToStruct <Level1Snapshot>(true);

                var level1Msg = new Level1ChangeMessage
                {
                    SecurityId = snapshot.SecurityId.ToSecurityId(),
                    ServerTime = snapshot.LastChangeServerTime.To <DateTimeOffset>(),
                    LocalTime  = snapshot.LastChangeLocalTime.To <DateTimeOffset>(),
                    BuildFrom  = snapshot.BuildFrom,
                    SeqNum     = snapshot.SeqNum,
                };

                level1Msg
                .TryAdd(Level1Fields.LastTradePrice, snapshot.LastTradePrice)
                .TryAdd(Level1Fields.LastTradeVolume, snapshot.LastTradeVolume)
                .TryAdd(Level1Fields.LastTradeId, snapshot.LastTradeId)

                .TryAdd(Level1Fields.BestBidPrice, snapshot.BestBidPrice)
                .TryAdd(Level1Fields.BestAskPrice, snapshot.BestAskPrice)

                .TryAdd(Level1Fields.BestBidVolume, snapshot.BestBidVolume)
                .TryAdd(Level1Fields.BestAskVolume, snapshot.BestAskVolume)

                .TryAdd(Level1Fields.BidsVolume, snapshot.BidsVolume)
                .TryAdd(Level1Fields.AsksVolume, snapshot.AsksVolume)

                .TryAdd(Level1Fields.BidsCount, snapshot.BidsCount)
                .TryAdd(Level1Fields.AsksCount, snapshot.AsksCount)

                .TryAdd(Level1Fields.HighBidPrice, snapshot.HighBidPrice)
                .TryAdd(Level1Fields.LowAskPrice, snapshot.LowAskPrice)

                .TryAdd(Level1Fields.OpenPrice, snapshot.OpenPrice)
                .TryAdd(Level1Fields.HighPrice, snapshot.HighPrice)
                .TryAdd(Level1Fields.LowPrice, snapshot.LowPrice)
                .TryAdd(Level1Fields.ClosePrice, snapshot.ClosePrice)
                .TryAdd(Level1Fields.Volume, snapshot.Volume)

                .TryAdd(Level1Fields.StepPrice, snapshot.StepPrice)
                .TryAdd(Level1Fields.OpenInterest, snapshot.OI)

                .TryAdd(Level1Fields.MinPrice, snapshot.MinPrice)
                .TryAdd(Level1Fields.MaxPrice, snapshot.MaxPrice)

                .TryAdd(Level1Fields.MarginBuy, snapshot.MarginBuy)
                .TryAdd(Level1Fields.MarginSell, snapshot.MarginSell)

                .TryAdd(Level1Fields.ImpliedVolatility, snapshot.IV)
                .TryAdd(Level1Fields.HistoricalVolatility, snapshot.HV)
                .TryAdd(Level1Fields.TheorPrice, snapshot.TheorPrice)
                .TryAdd(Level1Fields.Delta, snapshot.Delta)
                .TryAdd(Level1Fields.Gamma, snapshot.Gamma)
                .TryAdd(Level1Fields.Vega, snapshot.Vega)
                .TryAdd(Level1Fields.Theta, snapshot.Theta)
                .TryAdd(Level1Fields.Rho, snapshot.Rho)

                .TryAdd(Level1Fields.AveragePrice, snapshot.AveragePrice)
                .TryAdd(Level1Fields.SettlementPrice, snapshot.SettlementPrice)
                .TryAdd(Level1Fields.Change, snapshot.Change)
                .TryAdd(Level1Fields.AccruedCouponIncome, snapshot.AccruedCouponIncome)
                .TryAdd(Level1Fields.Yield, snapshot.Yield)
                .TryAdd(Level1Fields.VWAP, snapshot.VWAP)

                .TryAdd(Level1Fields.TradesCount, snapshot.TradesCount)

                .TryAdd(Level1Fields.Beta, snapshot.Beta)
                .TryAdd(Level1Fields.AverageTrueRange, snapshot.AverageTrueRange)
                .TryAdd(Level1Fields.Duration, snapshot.Duration)
                .TryAdd(Level1Fields.Turnover, snapshot.Turnover)
                .TryAdd(Level1Fields.SpreadMiddle, snapshot.SpreadMiddle)

                .TryAdd(Level1Fields.PriceEarnings, snapshot.PriceEarnings)
                .TryAdd(Level1Fields.ForwardPriceEarnings, snapshot.ForwardPriceEarnings)
                .TryAdd(Level1Fields.PriceEarningsGrowth, snapshot.PriceEarningsGrowth)
                .TryAdd(Level1Fields.PriceSales, snapshot.PriceSales)
                .TryAdd(Level1Fields.PriceBook, snapshot.PriceBook)
                .TryAdd(Level1Fields.PriceCash, snapshot.PriceCash)
                .TryAdd(Level1Fields.PriceFreeCash, snapshot.PriceFreeCash)
                .TryAdd(Level1Fields.Payout, snapshot.Payout)
                .TryAdd(Level1Fields.SharesOutstanding, snapshot.SharesOutstanding)
                .TryAdd(Level1Fields.SharesFloat, snapshot.SharesFloat)
                .TryAdd(Level1Fields.FloatShort, snapshot.FloatShort)
                .TryAdd(Level1Fields.ShortRatio, snapshot.ShortRatio)
                .TryAdd(Level1Fields.ReturnOnAssets, snapshot.ReturnOnAssets)
                .TryAdd(Level1Fields.ReturnOnEquity, snapshot.ReturnOnEquity)
                .TryAdd(Level1Fields.ReturnOnInvestment, snapshot.ReturnOnInvestment)
                .TryAdd(Level1Fields.CurrentRatio, snapshot.CurrentRatio)
                .TryAdd(Level1Fields.QuickRatio, snapshot.QuickRatio)
                .TryAdd(Level1Fields.HistoricalVolatilityWeek, snapshot.HistoricalVolatilityWeek)
                .TryAdd(Level1Fields.HistoricalVolatilityMonth, snapshot.HistoricalVolatilityMonth)
                .TryAdd(Level1Fields.IssueSize, snapshot.IssueSize)
                .TryAdd(Level1Fields.BuyBackPrice, snapshot.BuyBackPrice)
                .TryAdd(Level1Fields.Dividend, snapshot.Dividend)
                .TryAdd(Level1Fields.AfterSplit, snapshot.AfterSplit)
                .TryAdd(Level1Fields.BeforeSplit, snapshot.BeforeSplit)
                .TryAdd(Level1Fields.CommissionTaker, snapshot.CommissionTaker)
                .TryAdd(Level1Fields.CommissionMaker, snapshot.CommissionMaker)
                .TryAdd(Level1Fields.MinVolume, snapshot.MinVolume)
                .TryAdd(Level1Fields.UnderlyingMinVolume, snapshot.UnderlyingMinVolume)
                .TryAdd(Level1Fields.CouponValue, snapshot.CouponValue)
                .TryAdd(Level1Fields.CouponDate, snapshot.CouponDate?.To <DateTimeOffset>())
                .TryAdd(Level1Fields.CouponPeriod, snapshot.CouponPeriod)
                .TryAdd(Level1Fields.MarketPriceYesterday, snapshot.MarketPriceYesterday)
                .TryAdd(Level1Fields.MarketPriceToday, snapshot.MarketPriceToday)
                .TryAdd(Level1Fields.VWAPPrev, snapshot.VWAPPrev)
                .TryAdd(Level1Fields.YieldVWAP, snapshot.YieldVWAP)
                .TryAdd(Level1Fields.YieldVWAPPrev, snapshot.YieldVWAPPrev)
                .TryAdd(Level1Fields.Index, snapshot.Index)
                .TryAdd(Level1Fields.Imbalance, snapshot.Imbalance)
                .TryAdd(Level1Fields.UnderlyingPrice, snapshot.UnderlyingPrice)
                .TryAdd(Level1Fields.MaxVolume, snapshot.MaxVolume)
                .TryAdd(Level1Fields.LowBidPrice, snapshot.LowBidPrice)
                .TryAdd(Level1Fields.HighAskPrice, snapshot.HighAskPrice)
                .TryAdd(Level1Fields.LastTradeVolumeLow, snapshot.LastTradeVolumeLow)
                .TryAdd(Level1Fields.LastTradeVolumeHigh, snapshot.LastTradeVolumeHigh)
                .TryAdd(Level1Fields.OptionMargin, snapshot.OptionMargin)
                .TryAdd(Level1Fields.OptionSyntheticMargin, snapshot.OptionSyntheticMargin)
                .TryAdd(Level1Fields.PriceStep, snapshot.PriceStep)
                .TryAdd(Level1Fields.VolumeStep, snapshot.VolumeStep)
                .TryAdd(Level1Fields.BestBidTime, snapshot.BestBidTime?.To <DateTimeOffset>())
                .TryAdd(Level1Fields.BestAskTime, snapshot.BestAskTime?.To <DateTimeOffset>())
                .TryAdd(Level1Fields.Multiplier, snapshot.Multiplier)
                .TryAdd(Level1Fields.LongTermDebtEquity, snapshot.LongTermDebtEquity)
                .TryAdd(Level1Fields.TotalDebtEquity, snapshot.TotalDebtEquity)
                .TryAdd(Level1Fields.GrossMargin, snapshot.GrossMargin)
                .TryAdd(Level1Fields.OperatingMargin, snapshot.OperatingMargin)
                .TryAdd(Level1Fields.ProfitMargin, snapshot.ProfitMargin)
                .TryAdd(Level1Fields.IsSystem, snapshot.IsSystem?.ToBool())
                .TryAdd(Level1Fields.Decimals, snapshot.Decimals, true)
                .TryAdd(Level1Fields.LowBidVolume, snapshot.LowBidVolume)
                .TryAdd(Level1Fields.HighAskVolume, snapshot.HighAskVolume)
                .TryAdd(Level1Fields.UnderlyingBestBidPrice, snapshot.UnderlyingBestBidPrice)
                .TryAdd(Level1Fields.UnderlyingBestAskPrice, snapshot.UnderlyingBestAskPrice)
                .TryAdd(Level1Fields.MedianPrice, snapshot.MedianPrice)
                .TryAdd(Level1Fields.HighPrice52Week, snapshot.HighPrice52Week)
                .TryAdd(Level1Fields.LowPrice52Week, snapshot.LowPrice52Week)
                .TryAdd(Level1Fields.LastTradeStringId, snapshot.LastTradeStringId)
                ;

                if (snapshot.LastTradeTime != null)
                {
                    level1Msg.Add(Level1Fields.LastTradeTime, snapshot.LastTradeTime.Value.To <DateTimeOffset>());
                }

                if (snapshot.LastTradeUpDown != null)
                {
                    level1Msg.Add(Level1Fields.LastTradeUpDown, snapshot.LastTradeUpDown.Value == 1);
                }

                if (snapshot.LastTradeOrigin != null)
                {
                    level1Msg.Add(Level1Fields.LastTradeOrigin, (Sides)snapshot.LastTradeOrigin.Value);
                }

                if (snapshot.State != null)
                {
                    level1Msg.Add(Level1Fields.State, (SecurityStates)snapshot.State.Value);
                }

                if (snapshot.BuyBackDate != null)
                {
                    level1Msg.Add(Level1Fields.BuyBackDate, snapshot.BuyBackDate.Value.To <DateTimeOffset>());
                }

                return(level1Msg);
            }
        }
예제 #4
0
        Level1ChangeMessage ISnapshotSerializer <SecurityId, Level1ChangeMessage> .Deserialize(Version version, byte[] buffer)
        {
            if (version == null)
            {
                throw new ArgumentNullException(nameof(version));
            }

            using (var handle = new GCHandle <byte[]>(buffer))
            {
                var snapshot = handle.CreatePointer().ToStruct <Level1Snapshot>(true);

                var level1Msg = new Level1ChangeMessage
                {
                    SecurityId = snapshot.SecurityId.ToSecurityId(),
                    ServerTime = snapshot.LastChangeServerTime.To <DateTimeOffset>(),
                    LocalTime  = snapshot.LastChangeLocalTime.To <DateTimeOffset>(),
                };

                level1Msg
                .TryAdd(Level1Fields.LastTradePrice, snapshot.LastTradePrice)
                .TryAdd(Level1Fields.LastTradeVolume, snapshot.LastTradeVolume)
                .TryAdd(Level1Fields.LastTradeId, snapshot.LastTradeId)

                .TryAdd(Level1Fields.BestBidPrice, snapshot.BestBidPrice)
                .TryAdd(Level1Fields.BestAskPrice, snapshot.BestAskPrice)

                .TryAdd(Level1Fields.BestBidVolume, snapshot.BestBidVolume)
                .TryAdd(Level1Fields.BestAskVolume, snapshot.BestAskVolume)

                .TryAdd(Level1Fields.BidsVolume, snapshot.BidsVolume)
                .TryAdd(Level1Fields.AsksVolume, snapshot.AsksVolume)

                .TryAdd(Level1Fields.BidsCount, snapshot.BidsCount)
                .TryAdd(Level1Fields.AsksCount, snapshot.AsksCount)

                .TryAdd(Level1Fields.HighBidPrice, snapshot.HighBidPrice)
                .TryAdd(Level1Fields.LowAskPrice, snapshot.LowAskPrice)

                .TryAdd(Level1Fields.OpenPrice, snapshot.OpenPrice)
                .TryAdd(Level1Fields.HighPrice, snapshot.HighPrice)
                .TryAdd(Level1Fields.LowPrice, snapshot.LowPrice)
                .TryAdd(Level1Fields.ClosePrice, snapshot.ClosePrice)
                .TryAdd(Level1Fields.Volume, snapshot.Volume)

                .TryAdd(Level1Fields.StepPrice, snapshot.StepPrice)
                .TryAdd(Level1Fields.OpenInterest, snapshot.OI)

                .TryAdd(Level1Fields.MinPrice, snapshot.MinPrice)
                .TryAdd(Level1Fields.MaxPrice, snapshot.MaxPrice)

                .TryAdd(Level1Fields.MarginBuy, snapshot.MarginBuy)
                .TryAdd(Level1Fields.MarginSell, snapshot.MarginSell)

                .TryAdd(Level1Fields.ImpliedVolatility, snapshot.IV)
                .TryAdd(Level1Fields.HistoricalVolatility, snapshot.HV)
                .TryAdd(Level1Fields.TheorPrice, snapshot.TheorPrice)
                .TryAdd(Level1Fields.Delta, snapshot.Delta)
                .TryAdd(Level1Fields.Gamma, snapshot.Gamma)
                .TryAdd(Level1Fields.Vega, snapshot.Vega)
                .TryAdd(Level1Fields.Theta, snapshot.Theta)
                .TryAdd(Level1Fields.Rho, snapshot.Rho)

                .TryAdd(Level1Fields.AveragePrice, snapshot.AveragePrice)
                .TryAdd(Level1Fields.SettlementPrice, snapshot.SettlementPrice)
                .TryAdd(Level1Fields.Change, snapshot.Change)
                .TryAdd(Level1Fields.AccruedCouponIncome, snapshot.AccruedCouponIncome)
                .TryAdd(Level1Fields.Yield, snapshot.Yield)
                .TryAdd(Level1Fields.VWAP, snapshot.VWAP)

                .TryAdd(Level1Fields.TradesCount, snapshot.TradesCount)

                .TryAdd(Level1Fields.Beta, snapshot.Beta)
                .TryAdd(Level1Fields.AverageTrueRange, snapshot.AverageTrueRange)
                .TryAdd(Level1Fields.Duration, snapshot.Duration)
                .TryAdd(Level1Fields.Turnover, snapshot.Turnover)
                .TryAdd(Level1Fields.SpreadMiddle, snapshot.SpreadMiddle)

                .TryAdd(Level1Fields.PriceEarnings, snapshot.PriceEarnings)
                .TryAdd(Level1Fields.ForwardPriceEarnings, snapshot.ForwardPriceEarnings)
                .TryAdd(Level1Fields.PriceEarningsGrowth, snapshot.PriceEarningsGrowth)
                .TryAdd(Level1Fields.PriceSales, snapshot.PriceSales)
                .TryAdd(Level1Fields.PriceBook, snapshot.PriceBook)
                .TryAdd(Level1Fields.PriceCash, snapshot.PriceCash)
                .TryAdd(Level1Fields.PriceFreeCash, snapshot.PriceFreeCash)
                .TryAdd(Level1Fields.Payout, snapshot.Payout)
                .TryAdd(Level1Fields.SharesOutstanding, snapshot.SharesOutstanding)
                .TryAdd(Level1Fields.SharesFloat, snapshot.SharesFloat)
                .TryAdd(Level1Fields.FloatShort, snapshot.FloatShort)
                .TryAdd(Level1Fields.ShortRatio, snapshot.ShortRatio)
                .TryAdd(Level1Fields.ReturnOnAssets, snapshot.ReturnOnAssets)
                .TryAdd(Level1Fields.ReturnOnEquity, snapshot.ReturnOnEquity)
                .TryAdd(Level1Fields.ReturnOnInvestment, snapshot.ReturnOnInvestment)
                .TryAdd(Level1Fields.CurrentRatio, snapshot.CurrentRatio)
                .TryAdd(Level1Fields.QuickRatio, snapshot.QuickRatio)
                .TryAdd(Level1Fields.HistoricalVolatilityWeek, snapshot.HistoricalVolatilityWeek)
                .TryAdd(Level1Fields.HistoricalVolatilityMonth, snapshot.HistoricalVolatilityMonth)
                .TryAdd(Level1Fields.IssueSize, snapshot.IssueSize)
                .TryAdd(Level1Fields.BuyBackPrice, snapshot.BuyBackPrice)
                .TryAdd(Level1Fields.Dividend, snapshot.Dividend)
                .TryAdd(Level1Fields.AfterSplit, snapshot.AfterSplit)
                .TryAdd(Level1Fields.BeforeSplit, snapshot.BeforeSplit)
                ;

                if (snapshot.LastTradeTime != null)
                {
                    level1Msg.Add(Level1Fields.LastTradeTime, snapshot.LastTradeTime.Value.To <DateTimeOffset>());
                }

                if (snapshot.LastTradeUpDown != null)
                {
                    level1Msg.Add(Level1Fields.LastTradeUpDown, snapshot.LastTradeUpDown.Value == 1);
                }

                if (snapshot.LastTradeOrigin != null)
                {
                    level1Msg.Add(Level1Fields.LastTradeOrigin, (Sides)snapshot.LastTradeOrigin.Value);
                }

                if (snapshot.State != null)
                {
                    level1Msg.Add(Level1Fields.State, (SecurityStates)snapshot.State.Value);
                }

                if (snapshot.BuyBackDate != null)
                {
                    level1Msg.Add(Level1Fields.BuyBackDate, snapshot.BuyBackDate.Value.To <DateTimeOffset>());
                }

                return(level1Msg);
            }
        }