protected override Position Read(FastCsvReader reader) { var pfName = reader.ReadString(); var secId = reader.ReadString(); var position = new Position { Portfolio = Registry.Portfolios.ReadById(pfName), Security = Registry.Securities.ReadById(secId), DepoName = reader.ReadString(), LimitType = reader.ReadNullableEnum <TPlusLimits>(), BeginValue = reader.ReadNullableDecimal(), CurrentValue = reader.ReadNullableDecimal(), BlockedValue = reader.ReadNullableDecimal(), VariationMargin = reader.ReadNullableDecimal(), Commission = reader.ReadNullableDecimal(), Currency = reader.ReadNullableEnum <CurrencyTypes>(), LastChangeTime = _dateTimeParser.Parse(reader.ReadString()).ChangeKind(DateTimeKind.Utc), LocalTime = _dateTimeParser.Parse(reader.ReadString()).ChangeKind(DateTimeKind.Utc) }; if (position.Security == null) { throw new InvalidOperationException(LocalizedStrings.Str1218Params.Put(secId)); } if (position.Portfolio == null) { throw new InvalidOperationException(LocalizedStrings.Str891); } return(position); }
protected override Exchange Read(FastCsvReader reader) { var board = new Exchange { Name = reader.ReadString(), CountryCode = reader.ReadNullableEnum <CountryCodes>(), //EngName = reader.ReadString(), //RusName = reader.ReadString(), //ExtensionInfo = Deserialize<Dictionary<object, object>>(reader.ReadString()) }; var engName = reader.ReadString(); reader.Skip(); if ((reader.ColumnCurr + 1) < reader.ColumnCount) { board.FullNameLoc = reader.ReadString(); } else { board.FullNameLoc = LocalizedStrings.LocalizationManager.GetResourceId(engName) ?? engName; } return(board); }
/// <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.ReadString().To <TPlusLimits?>(), }; foreach (var type in _types) { 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; } default: { var value = reader.ReadNullableDecimal(); if (value != null) { posMsg.Changes.Add(type, value); } break; } } } return(posMsg); }
/// <inheritdoc /> protected override NewsMessage Read(FastCsvReader reader, IMarketDataMetaInfo metaInfo) { var news = new NewsMessage { ServerTime = reader.ReadTime(metaInfo.Date), Headline = reader.ReadString(), Source = reader.ReadString(), Url = reader.ReadString(), Id = reader.ReadString(), BoardCode = reader.ReadString(), }; var secCode = reader.ReadString(); if (!secCode.IsEmpty()) { news.SecurityId = new SecurityId { SecurityCode = secCode } } ; if ((reader.ColumnCurr + 1) < reader.ColumnCount) { news.Priority = reader.ReadNullableEnum <NewsPriorities>(); } if ((reader.ColumnCurr + 1) < reader.ColumnCount) { news.Language = reader.ReadString(); } if ((reader.ColumnCurr + 1) < reader.ColumnCount) { var boardCode = reader.ReadString(); if (news.SecurityId != null) { var secId = news.SecurityId.Value; secId.BoardCode = boardCode; news.SecurityId = secId; } } if ((reader.ColumnCurr + 1) < reader.ColumnCount) { news.ExpiryDate = reader.ReadString().TryToDateTimeOffset(_expiryFormat); } if ((reader.ColumnCurr + 1) < reader.ColumnCount) { news.SeqNum = reader.ReadNullableLong() ?? 0L; } return(news); } }
public void Init() { if (!File.Exists(_fileName)) { return; } CultureInfo.InvariantCulture.DoInCulture(() => { using (var stream = new FileStream(_fileName, FileMode.Open, FileAccess.Read)) { var reader = new FastCsvReader(stream, Encoding.UTF8); reader.NextLine(); reader.Skip(); var fields = new string[reader.ColumnCount - 1]; for (var i = 0; i < reader.ColumnCount - 1; i++) { fields[i] = reader.ReadString(); } reader.NextLine(); reader.Skip(); var types = new Type[reader.ColumnCount - 1]; for (var i = 0; i < reader.ColumnCount - 1; i++) { types[i] = reader.ReadString().To <Type>(); _fieldTypes.Add(fields[i], types[i]); } var idGenerator = new SecurityIdGenerator(); while (reader.NextLine()) { var secId = idGenerator.Split(reader.ReadString()); var values = new Dictionary <object, object>(); for (var i = 0; i < fields.Length; i++) { values[fields[i]] = reader.ReadString().To(types[i]); } _cache.Add(secId, values); } } }); }
protected override Exchange Read(FastCsvReader reader) { var board = new Exchange { Name = reader.ReadString(), CountryCode = reader.ReadNullableEnum <CountryCodes>(), EngName = reader.ReadString(), RusName = reader.ReadString(), //ExtensionInfo = Deserialize<Dictionary<object, object>>(reader.ReadString()) }; return(board); }
protected override ExchangeBoard Read(FastCsvReader reader) { var board = new ExchangeBoard { Code = reader.ReadString(), Exchange = GetExchange(reader.ReadString()), ExpiryTime = reader.ReadString().ToTime(), //IsSupportAtomicReRegister = reader.ReadBool(), //IsSupportMarketOrders = reader.ReadBool(), TimeZone = TimeZoneInfo.FindSystemTimeZoneById(reader.ReadString()), }; var time = board.WorkingTime; if (reader.ColumnCount == 7) { time.Periods = Deserialize <List <WorkingTimePeriod> >(reader.ReadString()); time.SpecialWorkingDays = Deserialize <IEnumerable <DateTime> >(reader.ReadString()).ToArray(); time.SpecialHolidays = Deserialize <IEnumerable <DateTime> >(reader.ReadString()).ToArray(); } else { time.Periods.AddRange(reader.ReadString().DecodeToPeriods()); time.SpecialDays.AddRange(reader.ReadString().DecodeToSpecialDays()); } //ExtensionInfo = Deserialize<Dictionary<object, object>>(reader.ReadString()) return(board); }
protected override ExchangeBoard Read(FastCsvReader reader) { var board = new ExchangeBoard { Code = reader.ReadString(), Exchange = GetExchange(reader.ReadString()), ExpiryTime = reader.ReadString().ToTime(), //IsSupportAtomicReRegister = reader.ReadBool(), //IsSupportMarketOrders = reader.ReadBool(), TimeZone = reader.ReadString().To <TimeZoneInfo>(), }; var time = board.WorkingTime; if (reader.ColumnCount == 7) { time.Periods = Deserialize <List <WorkingTimePeriod> >(reader.ReadString()); time.SpecialWorkingDays = Deserialize <IEnumerable <DateTime> >(reader.ReadString()).ToArray(); time.SpecialHolidays = Deserialize <IEnumerable <DateTime> >(reader.ReadString()).ToArray(); } else { time.Periods.AddRange(reader.ReadString().DecodeToPeriods()); time.SpecialDays.AddRange(reader.ReadString().DecodeToSpecialDays()); if ((reader.ColumnCurr + 1) < reader.ColumnCount) { reader.Skip(); time.IsEnabled = reader.ReadBool(); } } return(board); }
/// <inheritdoc /> protected override ExecutionMessage Read(FastCsvReader reader, IMarketDataMetaInfo metaInfo) { var execMsg = new ExecutionMessage { SecurityId = SecurityId, ExecutionType = ExecutionTypes.Tick, ServerTime = reader.ReadTime(metaInfo.Date), TradeId = reader.ReadNullableLong(), TradePrice = reader.ReadNullableDecimal(), TradeVolume = reader.ReadNullableDecimal(), OriginSide = reader.ReadNullableEnum <Sides>(), OpenInterest = reader.ReadNullableDecimal(), IsSystem = reader.ReadNullableBool(), }; if ((reader.ColumnCurr + 1) < reader.ColumnCount) { execMsg.IsUpTick = reader.ReadNullableBool(); execMsg.TradeStringId = reader.ReadString(); execMsg.Currency = reader.ReadNullableEnum <CurrencyTypes>(); } if ((reader.ColumnCurr + 1) < reader.ColumnCount) { execMsg.BuildFrom = reader.ReadBuildFrom(); } return(execMsg); }
/// <inheritdoc /> protected override Security Read(FastCsvReader reader) { var id = reader.ReadString(); var security = CreateSecurity(reader.ReadString()); var secId = id.ToSecurityId(); security.Id = id; security.Code = secId.SecurityCode; security.Board = Registry.GetBoard(secId.BoardCode); security.Decimals = reader.ReadNullableInt(); security.PriceStep = reader.ReadNullableDecimal(); security.VolumeStep = reader.ReadNullableDecimal(); return(security); }
/// <inheritdoc /> protected override ExecutionMessage Read(FastCsvReader reader, IMarketDataMetaInfo metaInfo) { var ol = new ExecutionMessage { SecurityId = SecurityId, ExecutionType = ExecutionTypes.OrderLog, ServerTime = reader.ReadTime(metaInfo.Date), TransactionId = reader.ReadLong(), OrderId = reader.ReadLong(), OrderPrice = reader.ReadDecimal(), OrderVolume = reader.ReadDecimal(), Side = reader.ReadEnum <Sides>(), OrderState = reader.ReadEnum <OrderStates>(), TimeInForce = reader.ReadNullableEnum <TimeInForce>(), TradeId = reader.ReadNullableLong(), TradePrice = reader.ReadNullableDecimal(), PortfolioName = reader.ReadString(), IsSystem = reader.ReadNullableBool(), }; if ((reader.ColumnCurr + 1) < reader.ColumnCount) { ol.Balance = reader.ReadNullableDecimal(); } return(ol); }
/// <inheritdoc /> protected override ExecutionMessage Read(FastCsvReader reader, IMarketDataMetaInfo metaInfo) { var ol = new ExecutionMessage { SecurityId = SecurityId, DataTypeEx = DataType.OrderLog, ServerTime = reader.ReadTime(metaInfo.Date), TransactionId = reader.ReadLong(), OrderId = reader.ReadNullableLong(), OrderPrice = reader.ReadDecimal(), OrderVolume = reader.ReadDecimal(), Side = reader.ReadEnum <Sides>(), OrderState = reader.ReadEnum <OrderStates>(), TimeInForce = reader.ReadNullableEnum <TimeInForce>(), TradeId = reader.ReadNullableLong(), TradePrice = reader.ReadNullableDecimal(), PortfolioName = reader.ReadString(), IsSystem = reader.ReadNullableBool(), }; if ((reader.ColumnCurr + 1) < reader.ColumnCount) { ol.Balance = reader.ReadNullableDecimal(); } if ((reader.ColumnCurr + 1) < reader.ColumnCount) { ol.SeqNum = reader.ReadNullableLong() ?? 0L; } if ((reader.ColumnCurr + 1) < reader.ColumnCount) { ol.OrderStringId = reader.ReadString(); ol.TradeStringId = reader.ReadString(); ol.OrderBuyId = reader.ReadNullableLong(); ol.OrderSellId = reader.ReadNullableLong(); ol.IsUpTick = reader.ReadNullableBool(); ol.Yield = reader.ReadNullableDecimal(); ol.TradeStatus = reader.ReadNullableInt(); ol.OpenInterest = reader.ReadNullableDecimal(); ol.OriginSide = reader.ReadNullableEnum <Sides>(); } return(ol); }
/// <inheritdoc /> protected override NewsMessage Read(FastCsvReader reader, IMarketDataMetaInfo metaInfo) { var news = new NewsMessage { ServerTime = reader.ReadTime(metaInfo.Date), Headline = reader.ReadString(), Source = reader.ReadString(), Url = reader.ReadString(), Id = reader.ReadString(), BoardCode = reader.ReadString(), }; var secCode = reader.ReadString(); if (!secCode.IsEmpty()) { news.SecurityId = new SecurityId { SecurityCode = secCode } } ; if ((reader.ColumnCurr + 1) < reader.ColumnCount) { news.Priority = reader.ReadNullableEnum <NewsPriorities>(); } if ((reader.ColumnCurr + 1) < reader.ColumnCount) { news.Language = reader.ReadString(); } return(news); } }
/// <summary> /// Read <see cref="DateTimeOffset"/>. /// </summary> /// <param name="reader">CSV reader.</param> /// <param name="date">Date.</param> /// <returns><see cref="DateTimeOffset"/>.</returns> internal static DateTimeOffset ReadTime(FastCsvReader reader, DateTime date) { if (reader == null) { throw new ArgumentNullException(nameof(reader)); } return((date + TimeParser.Parse(reader.ReadString())).ToDateTimeOffset(TimeSpan.Parse(reader.ReadString().Remove("+")))); }
/// <inheritdoc /> protected override BoardStateMessage Read(FastCsvReader reader, IMarketDataMetaInfo metaInfo) { var state = new BoardStateMessage { ServerTime = reader.ReadTime(metaInfo.Date), BoardCode = reader.ReadString(), State = reader.ReadEnum <SessionStates>() }; return(state); }
protected override Position Read(FastCsvReader reader) { var position = new Position { Portfolio = Registry.Portfolios.ReadById(reader.ReadString()), Security = Registry.Securities.ReadById(reader.ReadString()), DepoName = reader.ReadString(), LimitType = reader.ReadNullableEnum <TPlusLimits>(), BeginValue = reader.ReadNullableDecimal(), CurrentValue = reader.ReadNullableDecimal(), BlockedValue = reader.ReadNullableDecimal(), VariationMargin = reader.ReadNullableDecimal(), Commission = reader.ReadNullableDecimal(), Currency = reader.ReadNullableEnum <CurrencyTypes>(), LastChangeTime = reader.ReadDateTime(_dateTimeFormat), LocalTime = reader.ReadDateTime(_dateTimeFormat) }; return(position); }
private static DateTimeOffset?ReadNullableDateTime(FastCsvReader reader) { var str = reader.ReadString(); if (str == null) { return(null); } return(_dateTimeParser.Parse(str).ChangeKind(DateTimeKind.Utc)); }
protected override Portfolio Read(FastCsvReader reader) { var portfolio = new Portfolio { Name = reader.ReadString(), Board = Registry.ExchangeBoards.ReadById(reader.ReadString()), Leverage = reader.ReadNullableDecimal(), BeginValue = reader.ReadNullableDecimal(), CurrentValue = reader.ReadNullableDecimal(), BlockedValue = reader.ReadNullableDecimal(), VariationMargin = reader.ReadNullableDecimal(), Commission = reader.ReadNullableDecimal(), Currency = reader.ReadNullableEnum <CurrencyTypes>(), State = reader.ReadNullableEnum <PortfolioStates>(), Description = reader.ReadString(), LastChangeTime = reader.ReadDateTime(_dateTimeFormat), LocalTime = reader.ReadDateTime(_dateTimeFormat) }; return(portfolio); }
protected override Portfolio Read(FastCsvReader reader) { var portfolio = new Portfolio { Name = reader.ReadString(), Board = GetBoard(reader.ReadString()), Leverage = reader.ReadNullableDecimal(), BeginValue = reader.ReadNullableDecimal(), CurrentValue = reader.ReadNullableDecimal(), BlockedValue = reader.ReadNullableDecimal(), VariationMargin = reader.ReadNullableDecimal(), Commission = reader.ReadNullableDecimal(), Currency = reader.ReadNullableEnum <CurrencyTypes>(), State = reader.ReadNullableEnum <PortfolioStates>(), Description = reader.ReadString(), LastChangeTime = _dateTimeParser.Parse(reader.ReadString()).ChangeKind(DateTimeKind.Utc), LocalTime = _dateTimeParser.Parse(reader.ReadString()).ChangeKind(DateTimeKind.Utc) }; return(portfolio); }
/// <summary> /// Read data from the specified reader. /// </summary> /// <param name="reader">CSV reader.</param> /// <param name="date">Date.</param> /// <returns>Data.</returns> protected override NewsMessage Read(FastCsvReader reader, DateTime date) { var news = new NewsMessage { ServerTime = reader.ReadTime(date), Headline = reader.ReadString(), Source = reader.ReadString(), Url = reader.ReadString().To <Uri>(), Id = reader.ReadString(), BoardCode = reader.ReadString(), }; var secCode = reader.ReadString(); if (!secCode.IsEmpty()) { news.SecurityId = new SecurityId { SecurityCode = secCode } } ; return(news); } }
private void LoadFile(string fileName) { CultureInfo.InvariantCulture.DoInCulture(() => { if (!File.Exists(fileName)) { return; } var name = Path.GetFileNameWithoutExtension(fileName); var pairs = new List <Tuple <SecurityId, object> >(); using (var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read)) { var reader = new FastCsvReader(stream, Encoding.UTF8); reader.NextLine(); reader.Skip(2); var type1 = reader.ReadString().To <Type>(); var type2 = reader.ReadString().To <Type>(); var isTuple = type2 != null; while (reader.NextLine()) { var securityId = new SecurityId { SecurityCode = reader.ReadString(), BoardCode = reader.ReadString() }; var nativeId = reader.ReadString().To(type1); if (isTuple) { var nativeId2 = reader.ReadString().To(type2); nativeId = typeof(Tuple <,>).MakeGenericType(type1, type2).CreateInstance(new[] { nativeId, nativeId2 }); } pairs.Add(Tuple.Create(securityId, nativeId)); } } lock (_sync) { var nativeIds = _nativeIds.SafeAdd(name); foreach (var tuple in pairs) { nativeIds.Add(tuple.Item1, tuple.Item2); } } }); }
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())); }
protected override ExchangeBoard Read(FastCsvReader reader) { var board = new ExchangeBoard { Code = reader.ReadString(), Exchange = Registry.Exchanges.ReadById(reader.ReadString()), ExpiryTime = reader.ReadString().ToTime(), //IsSupportAtomicReRegister = reader.ReadBool(), //IsSupportMarketOrders = reader.ReadBool(), TimeZone = TimeZoneInfo.FindSystemTimeZoneById(reader.ReadString()), WorkingTime = { Periods = Deserialize <List <WorkingTimePeriod> >(reader.ReadString()), SpecialWorkingDays = Deserialize <List <DateTime> >(reader.ReadString()), SpecialHolidays = Deserialize <List <DateTime> >(reader.ReadString()) }, ExtensionInfo = Deserialize <Dictionary <object, object> >(reader.ReadString()) }; return(board); }
/// <summary> /// Load data from the specified reader. /// </summary> /// <param name="reader">CSV reader.</param> /// <param name="date">Date.</param> /// <returns>Data.</returns> protected override ExecutionMessage Read(FastCsvReader reader, DateTime date) { return(new ExecutionMessage { SecurityId = SecurityId, ExecutionType = ExecutionTypes.OrderLog, ServerTime = reader.ReadTime(date), TransactionId = reader.ReadLong(), OrderId = reader.ReadLong(), OrderPrice = reader.ReadDecimal(), OrderVolume = reader.ReadDecimal(), Side = reader.ReadEnum <Sides>(), OrderState = reader.ReadEnum <OrderStates>(), TimeInForce = reader.ReadNullableEnum <TimeInForce>(), TradeId = reader.ReadNullableLong(), TradePrice = reader.ReadNullableDecimal(), PortfolioName = reader.ReadString(), IsSystem = reader.ReadNullableBool(), }); }
/// <summary> /// Read data from the specified reader. /// </summary> /// <param name="reader">CSV reader.</param> /// <param name="metaInfo">Meta-information on data for one day.</param> /// <returns>Data.</returns> protected override Level1ChangeMessage Read(FastCsvReader reader, IMarketDataMetaInfo metaInfo) { var level1 = new Level1ChangeMessage { SecurityId = SecurityId, ServerTime = reader.ReadTime(metaInfo.Date), }; foreach (var field in _level1Fields) { // backward compatibility if (reader.ColumnCurr == reader.ColumnCount) { break; } switch (field) { case Level1Fields.BestAskTime: case Level1Fields.BestBidTime: case Level1Fields.LastTradeTime: case Level1Fields.BuyBackDate: 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); } break; case Level1Fields.LastTradeId: var id = reader.ReadNullableLong(); if (id != null) { level1.Changes.Add(field, id.Value); } break; case Level1Fields.AsksCount: case Level1Fields.BidsCount: case Level1Fields.TradesCount: case Level1Fields.Decimals: var count = reader.ReadNullableInt(); if (count != null) { level1.Changes.Add(field, count.Value); } break; case Level1Fields.LastTradeUpDown: case Level1Fields.IsSystem: var flag = reader.ReadNullableBool(); if (flag != null) { level1.Changes.Add(field, flag.Value); } break; case Level1Fields.State: var state = reader.ReadNullableEnum <SecurityStates>(); if (state != null) { level1.Changes.Add(field, state.Value); } break; case Level1Fields.LastTradeOrigin: var side = reader.ReadNullableEnum <Sides>(); if (side != null) { level1.Changes.Add(field, side.Value); } break; default: var value = reader.ReadNullableDecimal(); if (value != null) { level1.Changes.Add(field, value.Value); } break; } } return(level1); }
protected override Security Read(FastCsvReader reader) { var security = new Security { Id = reader.ReadString(), Name = reader.ReadString(), Code = reader.ReadString(), Class = reader.ReadString(), ShortName = reader.ReadString(), Board = Registry.ExchangeBoards.ReadById(reader.ReadString()), UnderlyingSecurityId = reader.ReadString(), PriceStep = reader.ReadNullableDecimal(), VolumeStep = reader.ReadNullableDecimal(), Multiplier = reader.ReadNullableDecimal(), Decimals = reader.ReadNullableInt(), Type = reader.ReadNullableEnum <SecurityTypes>(), ExpiryDate = ReadNullableDateTime(reader), SettlementDate = ReadNullableDateTime(reader), Strike = reader.ReadNullableDecimal(), OptionType = reader.ReadNullableEnum <OptionTypes>(), Currency = reader.ReadNullableEnum <CurrencyTypes>(), ExternalId = new SecurityExternalId { Sedol = reader.ReadString(), Cusip = reader.ReadString(), Isin = reader.ReadString(), Ric = reader.ReadString(), Bloomberg = reader.ReadString(), IQFeed = reader.ReadString(), InteractiveBrokers = reader.ReadNullableInt(), Plaza = reader.ReadString() }, ExtensionInfo = Deserialize <Dictionary <object, object> >(reader.ReadString()) }; return(security); }
/// <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.ReadBool(); 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(); } return(msg); }
/// <inheritdoc /> protected override Level1ChangeMessage Read(FastCsvReader reader, IMarketDataMetaInfo metaInfo) { var level1 = new Level1ChangeMessage { SecurityId = SecurityId, ServerTime = reader.ReadTime(metaInfo.Date), }; foreach (var pair in _level1Fields) { // 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); }
public void Init() { if (File.Exists(_fileName)) { CultureInfo.InvariantCulture.DoInCulture(() => { using (var stream = new FileStream(_fileName, FileMode.Open, FileAccess.Read)) { var reader = new FastCsvReader(stream, Encoding.UTF8); reader.NextLine(); reader.Skip(); var fields = new string[reader.ColumnCount - 1]; for (var i = 0; i < fields.Length; i++) { fields[i] = reader.ReadString(); } reader.NextLine(); reader.Skip(); var types = new Type[reader.ColumnCount - 1]; for (var i = 0; i < types.Length; i++) { types[i] = reader.ReadString().To <Type>(); //_fieldTypes.Add(fields[i], types[i]); } if (_fields == null) { if (fields.Length != types.Length) { throw new InvalidOperationException($"{fields.Length} != {types.Length}"); } _fields = fields.Select((f, i) => Tuple.Create(f, types[i])).ToArray(); } while (reader.NextLine()) { var secId = reader.ReadString().ToSecurityId(); var values = new Dictionary <string, object>(); for (var i = 0; i < fields.Length; i++) { values[fields[i]] = reader.ReadString().To(types[i]); } _cache.Add(secId, values); } } }); } else { if (_fields == null) { throw new InvalidOperationException(); } Write(Enumerable.Empty <Tuple <SecurityId, IDictionary <string, object> > >()); } }
/// <summary> /// Load data from the specified reader. /// </summary> /// <param name="reader">CSV reader.</param> /// <param name="date">Date.</param> /// <returns>Data.</returns> protected override ExecutionMessage Read(FastCsvReader reader, DateTime date) { var msg = new ExecutionMessage { SecurityId = SecurityId, ExecutionType = ExecutionTypes.Transaction, ServerTime = reader.ReadTime(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(), IsUpTick = reader.ReadNullableBool(), IsCancelled = reader.ReadBool(), OpenInterest = reader.ReadNullableDecimal(), PnL = reader.ReadNullableDecimal(), Position = reader.ReadNullableDecimal(), Slippage = reader.ReadNullableDecimal(), TradeStatus = reader.ReadNullableInt(), OrderStatus = reader.ReadNullableEnum <OrderStatus>(), Latency = reader.ReadNullableLong().To <TimeSpan?>(), }; var error = reader.ReadString(); if (!error.IsEmpty()) { msg.Error = new InvalidOperationException(error); } var dt = reader.ReadNullableDateTime(DateFormat); if (dt != null) { msg.ExpiryDate = (dt.Value + reader.ReadDateTime(TimeFormat).TimeOfDay).ToDateTimeOffset(TimeSpan.Parse(reader.ReadString().Replace("+", string.Empty))); } return(msg); }