void ISnapshotSerializer <PositionChangeMessage> .Serialize(Version version, PositionChangeMessage message, byte[] buffer) { if (version == null) { throw new ArgumentNullException(nameof(version)); } if (message == null) { throw new ArgumentNullException(nameof(message)); } var snapshot = new PositionSnapshot { SecurityId = message.SecurityId.ToStringId(), Portfolio = message.PortfolioName, ServerTime = message.ServerTime.To <long>(), LocalTime = message.LocalTime.To <long>(), }; foreach (var change in message.Changes) { } var ptr = snapshot.StructToPtr(); Marshal.Copy(ptr, buffer, 0, _snapshotSize); Marshal.FreeHGlobal(ptr); }
void ISnapshotSerializer <PositionChangeMessage> .Serialize(Version version, PositionChangeMessage message, byte[] buffer) { if (version == null) { throw new ArgumentNullException(nameof(version)); } if (message == null) { throw new ArgumentNullException(nameof(message)); } var snapshot = new PositionSnapshot { SecurityId = message.SecurityId.ToStringId(), Portfolio = message.PortfolioName, LastChangeServerTime = message.ServerTime.To <long>(), LastChangeLocalTime = message.LocalTime.To <long>(), Currency = -1, State = -1, }; foreach (var change in message.Changes) { switch (change.Key) { case PositionChangeTypes.BeginValue: snapshot.BeginValue = (decimal)change.Value; break; case PositionChangeTypes.CurrentValue: snapshot.CurrentValue = (decimal)change.Value; break; case PositionChangeTypes.BlockedValue: snapshot.BlockedValue = (decimal)change.Value; break; case PositionChangeTypes.CurrentPrice: snapshot.CurrentPrice = (decimal)change.Value; break; case PositionChangeTypes.AveragePrice: snapshot.AveragePrice = (decimal)change.Value; break; case PositionChangeTypes.UnrealizedPnL: snapshot.UnrealizedPnL = (decimal)change.Value; break; case PositionChangeTypes.RealizedPnL: snapshot.RealizedPnL = (decimal)change.Value; break; case PositionChangeTypes.VariationMargin: snapshot.VariationMargin = (decimal)change.Value; break; case PositionChangeTypes.Currency: snapshot.Currency = (short)(CurrencyTypes)change.Value; break; case PositionChangeTypes.Leverage: snapshot.Leverage = (decimal)change.Value; break; case PositionChangeTypes.Commission: snapshot.Commission = (decimal)change.Value; break; case PositionChangeTypes.CurrentValueInLots: snapshot.CurrentValueInLots = (decimal)change.Value; break; case PositionChangeTypes.State: snapshot.State = (sbyte)(PortfolioStates)change.Value; break; } } var ptr = snapshot.StructToPtr(); Marshal.Copy(ptr, buffer, 0, _snapshotSize); Marshal.FreeHGlobal(ptr); }
byte[] ISnapshotSerializer <Key, PositionChangeMessage> .Serialize(Version version, PositionChangeMessage message) { if (version == null) { throw new ArgumentNullException(nameof(version)); } if (message == null) { throw new ArgumentNullException(nameof(message)); } var snapshot = new PositionSnapshot { SecurityId = message.SecurityId.ToStringId().VerifySize(Sizes.S100), Portfolio = message.PortfolioName.VerifySize(Sizes.S100), LastChangeServerTime = message.ServerTime.To <long>(), LastChangeLocalTime = message.LocalTime.To <long>(), DepoName = message.DepoName, LimitType = (int?)message.LimitType, BoardCode = message.BoardCode, ClientCode = message.ClientCode, Description = message.Description, StrategyId = message.StrategyId, Side = (int?)message.Side, BuildFrom = message.BuildFrom == null ? default(SnapshotDataType?) : (SnapshotDataType)message.BuildFrom, }; foreach (var change in message.Changes) { switch (change.Key) { case PositionChangeTypes.BeginValue: snapshot.BeginValue = (BlittableDecimal)(decimal)change.Value; break; case PositionChangeTypes.CurrentValue: snapshot.CurrentValue = (BlittableDecimal)(decimal)change.Value; break; case PositionChangeTypes.BlockedValue: snapshot.BlockedValue = (BlittableDecimal)(decimal)change.Value; break; case PositionChangeTypes.CurrentPrice: snapshot.CurrentPrice = (BlittableDecimal)(decimal)change.Value; break; case PositionChangeTypes.AveragePrice: snapshot.AveragePrice = (BlittableDecimal)(decimal)change.Value; break; case PositionChangeTypes.UnrealizedPnL: snapshot.UnrealizedPnL = (BlittableDecimal)(decimal)change.Value; break; case PositionChangeTypes.RealizedPnL: snapshot.RealizedPnL = (BlittableDecimal)(decimal)change.Value; break; case PositionChangeTypes.VariationMargin: snapshot.VariationMargin = (BlittableDecimal)(decimal)change.Value; break; case PositionChangeTypes.Currency: snapshot.Currency = (short)(CurrencyTypes)change.Value; break; case PositionChangeTypes.Leverage: snapshot.Leverage = (BlittableDecimal)(decimal)change.Value; break; case PositionChangeTypes.Commission: snapshot.Commission = (BlittableDecimal)(decimal)change.Value; break; case PositionChangeTypes.CurrentValueInLots: snapshot.CurrentValueInLots = (BlittableDecimal)(decimal)change.Value; break; case PositionChangeTypes.State: snapshot.State = (byte)(PortfolioStates)change.Value; break; case PositionChangeTypes.ExpirationDate: snapshot.ExpirationDate = change.Value.To <long?>(); break; case PositionChangeTypes.CommissionTaker: snapshot.CommissionTaker = (BlittableDecimal)(decimal)change.Value; break; case PositionChangeTypes.CommissionMaker: snapshot.CommissionMaker = (BlittableDecimal)(decimal)change.Value; break; case PositionChangeTypes.SettlementPrice: snapshot.SettlementPrice = (BlittableDecimal)(decimal)change.Value; break; case PositionChangeTypes.BuyOrdersCount: snapshot.BuyOrdersCount = (int)change.Value; break; case PositionChangeTypes.SellOrdersCount: snapshot.SellOrdersCount = (int)change.Value; break; case PositionChangeTypes.BuyOrdersMargin: snapshot.BuyOrdersMargin = (BlittableDecimal)(decimal)change.Value; break; case PositionChangeTypes.SellOrdersMargin: snapshot.SellOrdersMargin = (BlittableDecimal)(decimal)change.Value; break; case PositionChangeTypes.OrdersMargin: snapshot.OrdersMargin = (BlittableDecimal)(decimal)change.Value; break; case PositionChangeTypes.OrdersCount: snapshot.OrdersCount = (int)change.Value; break; case PositionChangeTypes.TradesCount: snapshot.TradesCount = (int)change.Value; break; default: throw new InvalidOperationException(change.Key.To <string>()); } } var buffer = new byte[typeof(PositionSnapshot).SizeOf()]; var ptr = snapshot.StructToPtr(); ptr.CopyTo(buffer); ptr.FreeHGlobal(); return(buffer); }