コード例 #1
0
        byte[] ISnapshotSerializer <SecurityId, Level1ChangeMessage> .Serialize(Version version, Level1ChangeMessage message)
        {
            if (version == null)
            {
                throw new ArgumentNullException(nameof(version));
            }

            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            var snapshot = new Level1Snapshot
            {
                SecurityId           = message.SecurityId.ToStringId().VerifySize(Sizes.S100),
                LastChangeServerTime = message.ServerTime.To <long>(),
                LastChangeLocalTime  = message.LocalTime.To <long>(),
            };

            foreach (var change in message.Changes)
            {
                switch (change.Key)
                {
                case Level1Fields.OpenPrice:
                    snapshot.OpenPrice = (decimal)change.Value;
                    break;

                case Level1Fields.HighPrice:
                    snapshot.HighPrice = (decimal)change.Value;
                    break;

                case Level1Fields.LowPrice:
                    snapshot.LowPrice = (decimal)change.Value;
                    break;

                case Level1Fields.ClosePrice:
                    snapshot.ClosePrice = (decimal)change.Value;
                    break;

                case Level1Fields.StepPrice:
                    snapshot.StepPrice = (decimal)change.Value;
                    break;

                case Level1Fields.ImpliedVolatility:
                    snapshot.IV = (decimal)change.Value;
                    break;

                case Level1Fields.TheorPrice:
                    snapshot.TheorPrice = (decimal)change.Value;
                    break;

                case Level1Fields.OpenInterest:
                    snapshot.OI = (decimal)change.Value;
                    break;

                case Level1Fields.MinPrice:
                    snapshot.MinPrice = (decimal)change.Value;
                    break;

                case Level1Fields.MaxPrice:
                    snapshot.MaxPrice = (decimal)change.Value;
                    break;

                case Level1Fields.BidsVolume:
                    snapshot.BidsVolume = (decimal)change.Value;
                    break;

                case Level1Fields.BidsCount:
                    snapshot.BidsCount = (int)change.Value;
                    break;

                case Level1Fields.AsksVolume:
                    snapshot.AsksVolume = (decimal)change.Value;
                    break;

                case Level1Fields.AsksCount:
                    snapshot.AsksCount = (int)change.Value;
                    break;

                case Level1Fields.HistoricalVolatility:
                    snapshot.HV = (decimal)change.Value;
                    break;

                case Level1Fields.Delta:
                    snapshot.Delta = (decimal)change.Value;
                    break;

                case Level1Fields.Gamma:
                    snapshot.Gamma = (decimal)change.Value;
                    break;

                case Level1Fields.Vega:
                    snapshot.Vega = (decimal)change.Value;
                    break;

                case Level1Fields.Theta:
                    snapshot.Theta = (decimal)change.Value;
                    break;

                case Level1Fields.MarginBuy:
                    snapshot.MarginBuy = (decimal)change.Value;
                    break;

                case Level1Fields.MarginSell:
                    snapshot.MarginSell = (decimal)change.Value;
                    break;

                case Level1Fields.State:
                    snapshot.State = (byte)(SecurityStates)change.Value;
                    break;

                case Level1Fields.LastTradePrice:
                    snapshot.LastTradePrice = (decimal)change.Value;
                    break;

                case Level1Fields.LastTradeVolume:
                    snapshot.LastTradeVolume = (decimal)change.Value;
                    break;

                case Level1Fields.Volume:
                    snapshot.Volume = (decimal)change.Value;
                    break;

                case Level1Fields.AveragePrice:
                    snapshot.AveragePrice = (decimal)change.Value;
                    break;

                case Level1Fields.SettlementPrice:
                    snapshot.SettlementPrice = (decimal)change.Value;
                    break;

                case Level1Fields.Change:
                    snapshot.Change = (decimal)change.Value;
                    break;

                case Level1Fields.BestBidPrice:
                    snapshot.BestBidPrice = (decimal)change.Value;
                    break;

                case Level1Fields.BestBidVolume:
                    snapshot.BestBidVolume = (decimal)change.Value;
                    break;

                case Level1Fields.BestAskPrice:
                    snapshot.BestAskPrice = (decimal)change.Value;
                    break;

                case Level1Fields.BestAskVolume:
                    snapshot.BestAskVolume = (decimal)change.Value;
                    break;

                case Level1Fields.Rho:
                    snapshot.Rho = (decimal)change.Value;
                    break;

                case Level1Fields.AccruedCouponIncome:
                    snapshot.AccruedCouponIncome = (decimal)change.Value;
                    break;

                case Level1Fields.HighBidPrice:
                    snapshot.HighBidPrice = (decimal)change.Value;
                    break;

                case Level1Fields.LowAskPrice:
                    snapshot.LowAskPrice = (decimal)change.Value;
                    break;

                case Level1Fields.Yield:
                    snapshot.Yield = (decimal)change.Value;
                    break;

                case Level1Fields.LastTradeTime:
                    snapshot.LastTradeTime = change.Value.To <long>();
                    break;

                case Level1Fields.TradesCount:
                    snapshot.TradesCount = (int)change.Value;
                    break;

                case Level1Fields.VWAP:
                    snapshot.VWAP = (decimal)change.Value;
                    break;

                case Level1Fields.LastTradeId:
                    snapshot.LastTradeId = (long)change.Value;
                    break;

                case Level1Fields.LastTradeUpDown:
                    snapshot.LastTradeUpDown = (bool)change.Value ? (byte?)1 : 0;
                    break;

                case Level1Fields.LastTradeOrigin:
                    snapshot.LastTradeOrigin = (byte)(Sides)change.Value;
                    break;

                case Level1Fields.Beta:
                    snapshot.Beta = (decimal)change.Value;
                    break;

                case Level1Fields.AverageTrueRange:
                    snapshot.AverageTrueRange = (decimal)change.Value;
                    break;

                case Level1Fields.Duration:
                    snapshot.Duration = (decimal)change.Value;
                    break;

                case Level1Fields.Turnover:
                    snapshot.Turnover = (decimal)change.Value;
                    break;

                case Level1Fields.SpreadMiddle:
                    snapshot.SpreadMiddle = (decimal)change.Value;
                    break;

                case Level1Fields.PriceEarnings:
                    snapshot.PriceEarnings = (decimal)change.Value;
                    break;

                case Level1Fields.ForwardPriceEarnings:
                    snapshot.ForwardPriceEarnings = (decimal)change.Value;
                    break;

                case Level1Fields.PriceEarningsGrowth:
                    snapshot.PriceEarningsGrowth = (decimal)change.Value;
                    break;

                case Level1Fields.PriceSales:
                    snapshot.PriceSales = (decimal)change.Value;
                    break;

                case Level1Fields.PriceBook:
                    snapshot.PriceBook = (decimal)change.Value;
                    break;

                case Level1Fields.PriceCash:
                    snapshot.PriceCash = (decimal)change.Value;
                    break;

                case Level1Fields.PriceFreeCash:
                    snapshot.PriceFreeCash = (decimal)change.Value;
                    break;

                case Level1Fields.Payout:
                    snapshot.Payout = (decimal)change.Value;
                    break;

                case Level1Fields.SharesOutstanding:
                    snapshot.SharesOutstanding = (decimal)change.Value;
                    break;

                case Level1Fields.SharesFloat:
                    snapshot.SharesFloat = (decimal)change.Value;
                    break;

                case Level1Fields.FloatShort:
                    snapshot.FloatShort = (decimal)change.Value;
                    break;

                case Level1Fields.ShortRatio:
                    snapshot.ShortRatio = (decimal)change.Value;
                    break;

                case Level1Fields.ReturnOnAssets:
                    snapshot.ReturnOnAssets = (decimal)change.Value;
                    break;

                case Level1Fields.ReturnOnEquity:
                    snapshot.ReturnOnEquity = (decimal)change.Value;
                    break;

                case Level1Fields.ReturnOnInvestment:
                    snapshot.ReturnOnInvestment = (decimal)change.Value;
                    break;

                case Level1Fields.CurrentRatio:
                    snapshot.CurrentRatio = (decimal)change.Value;
                    break;

                case Level1Fields.QuickRatio:
                    snapshot.QuickRatio = (decimal)change.Value;
                    break;

                case Level1Fields.HistoricalVolatilityWeek:
                    snapshot.HistoricalVolatilityWeek = (decimal)change.Value;
                    break;

                case Level1Fields.HistoricalVolatilityMonth:
                    snapshot.HistoricalVolatilityMonth = (decimal)change.Value;
                    break;

                case Level1Fields.IssueSize:
                    snapshot.IssueSize = (decimal)change.Value;
                    break;

                case Level1Fields.BuyBackPrice:
                    snapshot.BuyBackPrice = (decimal)change.Value;
                    break;

                case Level1Fields.BuyBackDate:
                    snapshot.BuyBackDate = change.Value.To <long>();
                    break;

                case Level1Fields.Dividend:
                    snapshot.Dividend = (decimal)change.Value;
                    break;

                case Level1Fields.AfterSplit:
                    snapshot.AfterSplit = (decimal)change.Value;
                    break;

                case Level1Fields.BeforeSplit:
                    snapshot.BeforeSplit = (decimal)change.Value;
                    break;
                }
            }

            var buffer = new byte[typeof(Level1Snapshot).SizeOf()];

            var ptr = snapshot.StructToPtr();

            Marshal.Copy(ptr, buffer, 0, buffer.Length);
            Marshal.FreeHGlobal(ptr);

            return(buffer);
        }
コード例 #2
0
        byte[] ISnapshotSerializer <SecurityId, Level1ChangeMessage> .Serialize(Version version, Level1ChangeMessage message)
        {
            if (version == null)
            {
                throw new ArgumentNullException(nameof(version));
            }

            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            var snapshot = new Level1Snapshot
            {
                SecurityId           = message.SecurityId.ToStringId().VerifySize(Sizes.S100),
                LastChangeServerTime = message.ServerTime.To <long>(),
                LastChangeLocalTime  = message.LocalTime.To <long>(),
                BuildFrom            = message.BuildFrom == null ? default(SnapshotDataType?) : (SnapshotDataType)message.BuildFrom,
                SeqNum = message.SeqNum,
            };

            foreach (var change in message.Changes)
            {
                switch (change.Key)
                {
                case Level1Fields.OpenPrice:
                    snapshot.OpenPrice = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.HighPrice:
                    snapshot.HighPrice = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.LowPrice:
                    snapshot.LowPrice = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.ClosePrice:
                    snapshot.ClosePrice = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.StepPrice:
                    snapshot.StepPrice = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.ImpliedVolatility:
                    snapshot.IV = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.TheorPrice:
                    snapshot.TheorPrice = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.OpenInterest:
                    snapshot.OI = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.MinPrice:
                    snapshot.MinPrice = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.MaxPrice:
                    snapshot.MaxPrice = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.BidsVolume:
                    snapshot.BidsVolume = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.BidsCount:
                    snapshot.BidsCount = (int)change.Value;
                    break;

                case Level1Fields.AsksVolume:
                    snapshot.AsksVolume = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.AsksCount:
                    snapshot.AsksCount = (int)change.Value;
                    break;

                case Level1Fields.HistoricalVolatility:
                    snapshot.HV = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.Delta:
                    snapshot.Delta = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.Gamma:
                    snapshot.Gamma = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.Vega:
                    snapshot.Vega = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.Theta:
                    snapshot.Theta = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.MarginBuy:
                    snapshot.MarginBuy = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.MarginSell:
                    snapshot.MarginSell = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.State:
                    snapshot.State = (byte)(SecurityStates)change.Value;
                    break;

                case Level1Fields.LastTradePrice:
                    snapshot.LastTradePrice = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.LastTradeVolume:
                    snapshot.LastTradeVolume = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.Volume:
                    snapshot.Volume = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.AveragePrice:
                    snapshot.AveragePrice = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.SettlementPrice:
                    snapshot.SettlementPrice = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.Change:
                    snapshot.Change = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.BestBidPrice:
                    snapshot.BestBidPrice = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.BestBidVolume:
                    snapshot.BestBidVolume = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.BestAskPrice:
                    snapshot.BestAskPrice = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.BestAskVolume:
                    snapshot.BestAskVolume = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.Rho:
                    snapshot.Rho = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.AccruedCouponIncome:
                    snapshot.AccruedCouponIncome = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.HighBidPrice:
                    snapshot.HighBidPrice = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.LowAskPrice:
                    snapshot.LowAskPrice = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.Yield:
                    snapshot.Yield = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.LastTradeTime:
                    snapshot.LastTradeTime = change.Value.To <long>();
                    break;

                case Level1Fields.TradesCount:
                    snapshot.TradesCount = (int)change.Value;
                    break;

                case Level1Fields.VWAP:
                    snapshot.VWAP = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.LastTradeId:
                    snapshot.LastTradeId = (long)change.Value;
                    break;

                case Level1Fields.LastTradeUpDown:
                    snapshot.LastTradeUpDown = (bool)change.Value ? (byte?)1 : 0;
                    break;

                case Level1Fields.LastTradeOrigin:
                    snapshot.LastTradeOrigin = (byte)(Sides)change.Value;
                    break;

                case Level1Fields.Beta:
                    snapshot.Beta = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.AverageTrueRange:
                    snapshot.AverageTrueRange = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.Duration:
                    snapshot.Duration = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.Turnover:
                    snapshot.Turnover = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.SpreadMiddle:
                    snapshot.SpreadMiddle = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.PriceEarnings:
                    snapshot.PriceEarnings = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.ForwardPriceEarnings:
                    snapshot.ForwardPriceEarnings = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.PriceEarningsGrowth:
                    snapshot.PriceEarningsGrowth = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.PriceSales:
                    snapshot.PriceSales = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.PriceBook:
                    snapshot.PriceBook = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.PriceCash:
                    snapshot.PriceCash = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.PriceFreeCash:
                    snapshot.PriceFreeCash = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.Payout:
                    snapshot.Payout = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.SharesOutstanding:
                    snapshot.SharesOutstanding = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.SharesFloat:
                    snapshot.SharesFloat = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.FloatShort:
                    snapshot.FloatShort = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.ShortRatio:
                    snapshot.ShortRatio = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.ReturnOnAssets:
                    snapshot.ReturnOnAssets = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.ReturnOnEquity:
                    snapshot.ReturnOnEquity = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.ReturnOnInvestment:
                    snapshot.ReturnOnInvestment = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.CurrentRatio:
                    snapshot.CurrentRatio = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.QuickRatio:
                    snapshot.QuickRatio = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.HistoricalVolatilityWeek:
                    snapshot.HistoricalVolatilityWeek = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.HistoricalVolatilityMonth:
                    snapshot.HistoricalVolatilityMonth = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.IssueSize:
                    snapshot.IssueSize = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.BuyBackPrice:
                    snapshot.BuyBackPrice = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.BuyBackDate:
                    snapshot.BuyBackDate = change.Value.To <long>();
                    break;

                case Level1Fields.Dividend:
                    snapshot.Dividend = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.AfterSplit:
                    snapshot.AfterSplit = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.BeforeSplit:
                    snapshot.BeforeSplit = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.CommissionTaker:
                    snapshot.CommissionTaker = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.CommissionMaker:
                    snapshot.CommissionMaker = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.MinVolume:
                    snapshot.MinVolume = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.UnderlyingMinVolume:
                    snapshot.UnderlyingMinVolume = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.CouponValue:
                    snapshot.CouponValue = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.CouponDate:
                    snapshot.CouponDate = ((DateTimeOffset)change.Value).To <long>();
                    break;

                case Level1Fields.CouponPeriod:
                    snapshot.CouponPeriod = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.MarketPriceYesterday:
                    snapshot.MarketPriceYesterday = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.MarketPriceToday:
                    snapshot.MarketPriceToday = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.VWAPPrev:
                    snapshot.VWAPPrev = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.YieldVWAP:
                    snapshot.YieldVWAP = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.YieldVWAPPrev:
                    snapshot.YieldVWAPPrev = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.Index:
                    snapshot.Index = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.Imbalance:
                    snapshot.Imbalance = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.UnderlyingPrice:
                    snapshot.UnderlyingPrice = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.MaxVolume:
                    snapshot.MaxVolume = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.LowBidPrice:
                    snapshot.LowBidPrice = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.HighAskPrice:
                    snapshot.HighAskPrice = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.LastTradeVolumeLow:
                    snapshot.LastTradeVolumeLow = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.LastTradeVolumeHigh:
                    snapshot.LastTradeVolumeHigh = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.OptionMargin:
                    snapshot.OptionMargin = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.OptionSyntheticMargin:
                    snapshot.OptionSyntheticMargin = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.PriceStep:
                    snapshot.PriceStep = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.VolumeStep:
                    snapshot.VolumeStep = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.BestBidTime:
                    snapshot.BestBidTime = ((DateTimeOffset)change.Value).To <long>();
                    break;

                case Level1Fields.BestAskTime:
                    snapshot.BestAskTime = ((DateTimeOffset)change.Value).To <long>();
                    break;

                case Level1Fields.Multiplier:
                    snapshot.Multiplier = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.LongTermDebtEquity:
                    snapshot.LongTermDebtEquity = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.TotalDebtEquity:
                    snapshot.TotalDebtEquity = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.GrossMargin:
                    snapshot.GrossMargin = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.OperatingMargin:
                    snapshot.OperatingMargin = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.ProfitMargin:
                    snapshot.ProfitMargin = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.IsSystem:
                    snapshot.IsSystem = ((bool)change.Value).ToByte();
                    break;

                case Level1Fields.Decimals:
                    snapshot.Decimals = (int)change.Value;
                    break;

                case Level1Fields.LowBidVolume:
                    snapshot.LowBidVolume = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.HighAskVolume:
                    snapshot.HighAskVolume = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.UnderlyingBestBidPrice:
                    snapshot.UnderlyingBestBidPrice = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.UnderlyingBestAskPrice:
                    snapshot.UnderlyingBestAskPrice = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.MedianPrice:
                    snapshot.MedianPrice = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.HighPrice52Week:
                    snapshot.HighPrice52Week = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.LowPrice52Week:
                    snapshot.LowPrice52Week = (BlittableDecimal)(decimal)change.Value;
                    break;

                case Level1Fields.LastTradeStringId:
                    snapshot.LastTradeStringId = (string)change.Value;
                    break;
                }
            }

            var buffer = new byte[typeof(Level1Snapshot).SizeOf()];

            var ptr = snapshot.StructToPtr();

            ptr.CopyTo(buffer);
            ptr.FreeHGlobal();

            return(buffer);
        }
コード例 #3
0
        void ISnapshotSerializer <Level1ChangeMessage> .Serialize(Version version, Level1ChangeMessage message, byte[] buffer)
        {
            if (version == null)
            {
                throw new ArgumentNullException(nameof(version));
            }

            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            var snapshot = new Level1Snapshot
            {
                SecurityId           = message.SecurityId.ToStringId(),
                LastChangeServerTime = message.ServerTime.To <long>(),
                LastChangeLocalTime  = message.LocalTime.To <long>(),

                LastTradeUpDown = -1,
                LastTradeOrigin = -1,
                State           = -1,
            };

            foreach (var change in message.Changes)
            {
                switch (change.Key)
                {
                case Level1Fields.OpenPrice:
                    snapshot.OpenPrice = (decimal)change.Value;
                    break;

                case Level1Fields.HighPrice:
                    snapshot.HighPrice = (decimal)change.Value;
                    break;

                case Level1Fields.LowPrice:
                    snapshot.LowPrice = (decimal)change.Value;
                    break;

                case Level1Fields.ClosePrice:
                    snapshot.ClosePrice = (decimal)change.Value;
                    break;

                case Level1Fields.StepPrice:
                    snapshot.StepPrice = (decimal)change.Value;
                    break;

                case Level1Fields.ImpliedVolatility:
                    snapshot.IV = (decimal)change.Value;
                    break;

                case Level1Fields.TheorPrice:
                    snapshot.TheorPrice = (decimal)change.Value;
                    break;

                case Level1Fields.OpenInterest:
                    snapshot.OI = (decimal)change.Value;
                    break;

                case Level1Fields.MinPrice:
                    snapshot.MinPrice = (decimal)change.Value;
                    break;

                case Level1Fields.MaxPrice:
                    snapshot.MaxPrice = (decimal)change.Value;
                    break;

                case Level1Fields.BidsVolume:
                    snapshot.BidsVolume = (decimal)change.Value;
                    break;

                case Level1Fields.BidsCount:
                    snapshot.BidsCount = (int)change.Value;
                    break;

                case Level1Fields.AsksVolume:
                    snapshot.AsksVolume = (decimal)change.Value;
                    break;

                case Level1Fields.AsksCount:
                    snapshot.AsksCount = (int)change.Value;
                    break;

                case Level1Fields.HistoricalVolatility:
                    snapshot.HV = (decimal)change.Value;
                    break;

                case Level1Fields.Delta:
                    snapshot.Delta = (decimal)change.Value;
                    break;

                case Level1Fields.Gamma:
                    snapshot.Gamma = (decimal)change.Value;
                    break;

                case Level1Fields.Vega:
                    snapshot.Vega = (decimal)change.Value;
                    break;

                case Level1Fields.Theta:
                    snapshot.Theta = (decimal)change.Value;
                    break;

                case Level1Fields.MarginBuy:
                    snapshot.MarginBuy = (decimal)change.Value;
                    break;

                case Level1Fields.MarginSell:
                    snapshot.MarginSell = (decimal)change.Value;
                    break;

                case Level1Fields.State:
                    snapshot.State = (sbyte)(SecurityStates)change.Value;
                    break;

                case Level1Fields.LastTradePrice:
                    snapshot.LastTradePrice = (decimal)change.Value;
                    break;

                case Level1Fields.LastTradeVolume:
                    snapshot.LastTradeVolume = (decimal)change.Value;
                    break;

                case Level1Fields.Volume:
                    snapshot.Volume = (decimal)change.Value;
                    break;

                case Level1Fields.AveragePrice:
                    snapshot.AveragePrice = (decimal)change.Value;
                    break;

                case Level1Fields.SettlementPrice:
                    snapshot.SettlementPrice = (decimal)change.Value;
                    break;

                case Level1Fields.Change:
                    snapshot.Change = (decimal)change.Value;
                    break;

                case Level1Fields.BestBidPrice:
                    snapshot.BestBidPrice = (decimal)change.Value;
                    break;

                case Level1Fields.BestBidVolume:
                    snapshot.BestBidVolume = (decimal)change.Value;
                    break;

                case Level1Fields.BestAskPrice:
                    snapshot.BestAskPrice = (decimal)change.Value;
                    break;

                case Level1Fields.BestAskVolume:
                    snapshot.BestAskVolume = (decimal)change.Value;
                    break;

                case Level1Fields.Rho:
                    snapshot.Rho = (decimal)change.Value;
                    break;

                case Level1Fields.AccruedCouponIncome:
                    snapshot.AccruedCouponIncome = (decimal)change.Value;
                    break;

                case Level1Fields.HighBidPrice:
                    snapshot.HighBidPrice = (decimal)change.Value;
                    break;

                case Level1Fields.LowAskPrice:
                    snapshot.LowAskPrice = (decimal)change.Value;
                    break;

                case Level1Fields.Yield:
                    snapshot.Yield = (decimal)change.Value;
                    break;

                case Level1Fields.LastTradeTime:
                    snapshot.LastTradeTime = change.Value.To <long>();
                    break;

                case Level1Fields.TradesCount:
                    snapshot.TradesCount = (int)change.Value;
                    break;

                case Level1Fields.VWAP:
                    snapshot.VWAP = (decimal)change.Value;
                    break;

                case Level1Fields.LastTradeId:
                    snapshot.LastTradeId = (long)change.Value;
                    break;

                case Level1Fields.LastTradeUpDown:
                    snapshot.LastTradeUpDown = (sbyte)((bool)change.Value == false ? 0 : 1);
                    break;

                case Level1Fields.LastTradeOrigin:
                    snapshot.LastTradeOrigin = (sbyte)(Sides)change.Value;
                    break;

                case Level1Fields.Beta:
                    snapshot.Beta = (decimal)change.Value;
                    break;

                case Level1Fields.AverageTrueRange:
                    snapshot.AverageTrueRange = (decimal)change.Value;
                    break;

                case Level1Fields.HistoricalVolatilityMonth:
                    snapshot.Beta = (decimal)change.Value;
                    break;

                case Level1Fields.Duration:
                    snapshot.Duration = (decimal)change.Value;
                    break;

                case Level1Fields.Turnover:
                    snapshot.Turnover = (decimal)change.Value;
                    break;

                case Level1Fields.SpreadMiddle:
                    snapshot.SpreadMiddle = (decimal)change.Value;
                    break;
                }
            }

            var ptr = snapshot.StructToPtr();

            Marshal.Copy(ptr, buffer, 0, _snapshotSize);
            Marshal.FreeHGlobal(ptr);
        }