/// <inheritdoc />
        protected override Level1ChangeMessage Read(FastCsvReader reader, IMarketDataMetaInfo metaInfo)
        {
            var level1 = new Level1ChangeMessage
            {
                SecurityId = SecurityId,
                ServerTime = reader.ReadTime(metaInfo.Date),
                BuildFrom  = reader.ReadBuildFrom(),
                SeqNum     = reader.ReadNullableLong() ?? 0L,
            };

            reader.Skip(_reserved.Length);

            var count = reader.ReadInt();

            foreach (var pair in _level1Fields.Take(count))
            {
                // backward compatibility
                if (reader.ColumnCurr == reader.ColumnCount)
                {
                    break;
                }

                var field = pair.Key;

                if (pair.Value == typeof(DateTimeOffset))
                {
                    var dtStr = reader.ReadString();

                    if (dtStr != null)
                    {
                        level1.Changes.Add(field, (dtStr.ToDateTime() + reader.ReadString().ToTimeMls()).ToDateTimeOffset(TimeSpan.Parse(reader.ReadString().Remove("+"))));
                    }
                    else
                    {
                        reader.Skip(2);
                    }
                }
                else if (pair.Value == typeof(int))
                {
                    var value = reader.ReadNullableInt();

                    if (value != null)
                    {
                        level1.Changes.Add(field, value.Value);
                    }
                }
                else if (pair.Value == typeof(long))
                {
                    var value = reader.ReadNullableLong();

                    if (value != null)
                    {
                        level1.Changes.Add(field, value.Value);
                    }
                }
                else if (pair.Value == typeof(bool))
                {
                    var value = reader.ReadNullableBool();

                    if (value != null)
                    {
                        level1.Changes.Add(field, value.Value);
                    }
                }
                else if (pair.Value == typeof(SecurityStates))
                {
                    var value = reader.ReadNullableEnum <SecurityStates>();

                    if (value != null)
                    {
                        level1.Changes.Add(field, value.Value);
                    }
                }
                else if (pair.Value == typeof(Sides))
                {
                    var value = reader.ReadNullableEnum <Sides>();

                    if (value != null)
                    {
                        level1.Changes.Add(field, value.Value);
                    }
                }
                else
                {
                    var value = reader.ReadNullableDecimal();

                    if (value != null)
                    {
                        level1.Changes.Add(field, value.Value);
                    }
                }
            }

            return(level1);
        }
Beispiel #2
0
        /// <inheritdoc />
        protected override ExecutionMessage Read(FastCsvReader reader, IMarketDataMetaInfo metaInfo)
        {
            var msg = new ExecutionMessage
            {
                SecurityId            = SecurityId,
                ExecutionType         = ExecutionTypes.Transaction,
                ServerTime            = reader.ReadTime(metaInfo.Date),
                TransactionId         = reader.ReadLong(),
                OriginalTransactionId = reader.ReadLong(),
                OrderId       = reader.ReadNullableLong(),
                OrderStringId = reader.ReadString(),
                OrderBoardId  = reader.ReadString(),
                UserOrderId   = reader.ReadString(),
                OrderPrice    = reader.ReadDecimal(),
                OrderVolume   = reader.ReadNullableDecimal(),
                Balance       = reader.ReadNullableDecimal(),
                VisibleVolume = reader.ReadNullableDecimal(),
                Side          = reader.ReadEnum <Sides>(),
                OriginSide    = reader.ReadNullableEnum <Sides>(),
                OrderState    = reader.ReadNullableEnum <OrderStates>(),
                OrderType     = reader.ReadNullableEnum <OrderTypes>(),
                TimeInForce   = reader.ReadNullableEnum <TimeInForce>(),
                TradeId       = reader.ReadNullableLong(),
                TradeStringId = reader.ReadString(),
                TradePrice    = reader.ReadNullableDecimal(),
                TradeVolume   = reader.ReadNullableDecimal(),
                PortfolioName = reader.ReadString(),
                ClientCode    = reader.ReadString(),
                BrokerCode    = reader.ReadString(),
                DepoName      = reader.ReadString(),
                IsSystem      = reader.ReadNullableBool(),
                HasOrderInfo  = reader.ReadBool(),
                HasTradeInfo  = reader.ReadBool(),
                Commission    = reader.ReadNullableDecimal(),
                Currency      = reader.ReadNullableEnum <CurrencyTypes>(),
                Comment       = reader.ReadString(),
                SystemComment = reader.ReadString(),
                //DerivedOrderId = reader.ReadNullableLong(),
                //DerivedOrderStringId = reader.ReadString(),
            };

            reader.ReadNullableLong();
            reader.ReadString();

            msg.IsUpTick = reader.ReadNullableBool();
            /*msg.IsCancellation = */ reader.Skip();
            msg.OpenInterest = reader.ReadNullableDecimal();
            msg.PnL          = reader.ReadNullableDecimal();
            msg.Position     = reader.ReadNullableDecimal();
            msg.Slippage     = reader.ReadNullableDecimal();
            msg.TradeStatus  = reader.ReadNullableInt();
            msg.OrderStatus  = reader.ReadNullableLong();
            msg.Latency      = reader.ReadNullableLong().To <TimeSpan?>();

            var error = reader.ReadString();

            if (!error.IsEmpty())
            {
                msg.Error = new InvalidOperationException(error);
            }

            var dtStr = reader.ReadString();

            if (dtStr != null)
            {
                msg.ExpiryDate = (dtStr.ToDateTime() + reader.ReadString().ToTimeMls()).ToDateTimeOffset(TimeSpan.Parse(reader.ReadString().Remove("+")));
            }
            else
            {
                reader.Skip(2);
            }

            msg.LocalTime     = reader.ReadTime(metaInfo.Date);
            msg.IsMarketMaker = reader.ReadNullableBool();

            if ((reader.ColumnCurr + 1) < reader.ColumnCount)
            {
                msg.CommissionCurrency = reader.ReadString();
            }

            if ((reader.ColumnCurr + 1) < reader.ColumnCount)
            {
                msg.IsMargin = reader.ReadNullableBool();
                msg.IsManual = reader.ReadNullableBool();
            }

            if ((reader.ColumnCurr + 1) < reader.ColumnCount)
            {
                msg.MinVolume      = reader.ReadNullableDecimal();
                msg.PositionEffect = reader.ReadNullableEnum <OrderPositionEffects>();
                msg.PostOnly       = reader.ReadNullableBool();
                msg.Initiator      = reader.ReadNullableBool();
            }

            if ((reader.ColumnCurr + 1) < reader.ColumnCount)
            {
                msg.SeqNum     = reader.ReadLong();
                msg.StrategyId = reader.ReadString();
            }

            if ((reader.ColumnCurr + 1) < reader.ColumnCount)
            {
                msg.BuildFrom = reader.ReadBuildFrom();
            }

            if ((reader.ColumnCurr + 1) < reader.ColumnCount)
            {
                msg.Leverage = reader.ReadInt();
            }

            return(msg);
        }
        /// <inheritdoc />
        protected override PositionChangeMessage Read(FastCsvReader reader, IMarketDataMetaInfo metaInfo)
        {
            var posMsg = new PositionChangeMessage
            {
                SecurityId    = SecurityId,
                ServerTime    = reader.ReadTime(metaInfo.Date),
                PortfolioName = reader.ReadString(),
                ClientCode    = reader.ReadString(),
                DepoName      = reader.ReadString(),
                LimitType     = reader.ReadNullableEnum <TPlusLimits>(),
                Description   = reader.ReadString(),
                StrategyId    = reader.ReadString(),
                Side          = reader.ReadNullableEnum <Sides>(),
                BuildFrom     = reader.ReadBuildFrom(),
            };

            reader.Skip(_reserved.Length);

            var count = reader.ReadInt();

            foreach (var type in _types.Take(count))
            {
                switch (type)
                {
                case PositionChangeTypes.Currency:
                {
                    var currency = reader.ReadNullableEnum <CurrencyTypes>();

                    if (currency != null)
                    {
                        posMsg.Changes.Add(type, currency);
                    }

                    break;
                }

                case PositionChangeTypes.State:
                {
                    var state = reader.ReadNullableEnum <PortfolioStates>();

                    if (state != null)
                    {
                        posMsg.Changes.Add(type, state);
                    }

                    break;
                }

                case PositionChangeTypes.ExpirationDate:
                {
                    var dtStr = reader.ReadString();

                    if (dtStr != null)
                    {
                        posMsg.Changes.Add(type, (dtStr.ToDateTime() + reader.ReadString().ToTimeMls()).ToDateTimeOffset(TimeSpan.Parse(reader.ReadString().Remove("+"))));
                    }
                    else
                    {
                        reader.Skip(2);
                    }

                    break;
                }

                default:
                {
                    var value = reader.ReadNullableDecimal();

                    if (value != null)
                    {
                        posMsg.Changes.Add(type, value);
                    }

                    break;
                }
                }
            }

            return(posMsg);
        }
Beispiel #4
0
        public static DataType ReadBuildFrom(this FastCsvReader reader)
        {
            if (reader is null)
            {
                throw new ArgumentNullException(nameof(reader));
            }

            var str = reader.ReadString();

            if (str.IsEmpty())
            {
                reader.Skip(3);
                return(null);
            }

            return(str.To <int>().ToDataType(reader.ReadLong(), reader.ReadDecimal(), reader.ReadInt()));
        }