17 using System.Collections;
18 using System.Collections.Generic;
19 using System.Globalization;
35 private readonly Stream _stream;
36 private readonly StreamReader _streamReader;
37 private readonly HashSet<string> _symbolFilter;
38 private readonly Dictionary<string, decimal> _symbolMultipliers;
41 private readonly
int _columnTimestamp = -1;
42 private readonly
int _columnSecID = -1;
43 private readonly
int _columnTicker = -1;
44 private readonly
int _columnType = -1;
45 private readonly
int _columnSide = -1;
46 private readonly
int _columnQuantity = -1;
47 private readonly
int _columnPrice = -1;
48 private readonly
int _columnsCount = -1;
56 public AlgoSeekFuturesReader(
string file, Dictionary<string, decimal> symbolMultipliers, HashSet<string> symbolFilter =
null)
59 _stream = streamProvider.
Open(file).First();
60 _streamReader =
new StreamReader(_stream);
61 _symbolFilter = symbolFilter;
62 _symbolMultipliers = symbolMultipliers.ToDictionary();
66 var headerLine = _streamReader.ReadLine();
67 if (!
string.IsNullOrEmpty(headerLine))
69 var header = headerLine.ToCsv();
70 _columnTimestamp = header.FindIndex(x => x ==
"Timestamp");
71 _columnTicker = header.FindIndex(x => x ==
"Ticker");
72 _columnType = header.FindIndex(x => x ==
"Type");
73 _columnSide = header.FindIndex(x => x ==
"Side");
74 _columnSecID = header.FindIndex(x => x ==
"SecurityID");
75 _columnQuantity = header.FindIndex(x => x ==
"Quantity");
76 _columnPrice = header.FindIndex(x => x ==
"Price");
78 _columnsCount =
new[] { _columnTimestamp, _columnTicker, _columnType, _columnSide, _columnSecID, _columnQuantity, _columnPrice }.Max();
93 while (tick ==
null && (line = _streamReader.ReadLine()) !=
null)
114 object IEnumerator.Current =>
Current;
121 throw new NotImplementedException(
"Reset not implemented for AlgoSeekFuturesReader.");
131 _streamReader.Close();
132 _streamReader.Dispose();
144 const int TradeMask = 2;
145 const int QuoteMask = 1;
146 const int OpenInterestMask = 11;
147 const int MessageTypeMask = 15;
150 var csv = line.ToCsv();
151 if (csv.Count - 1 < _columnsCount)
156 var ticker = csv[_columnTicker];
159 if (ticker.IndexOfAny(
new [] {
' ',
'-' }) != -1)
164 ticker = ticker.Trim(
'"');
166 if (
string.IsNullOrEmpty(ticker))
172 var timeString = csv[_columnTimestamp];
173 var time = DateTime.ParseExact(timeString,
"yyyyMMddHHmmssFFF", CultureInfo.InvariantCulture);
175 var symbol = SymbolRepresentation.ParseFutureSymbol(ticker, time.Year);
177 if (symbol ==
null || !_symbolMultipliers.ContainsKey(symbol.ID.Symbol) ||
178 _symbolFilter !=
null && !_symbolFilter.Contains(symbol.ID.Symbol, StringComparer.InvariantCultureIgnoreCase))
187 var type = csv[_columnType].ConvertInvariant<
int>();
188 if ((type & MessageTypeMask) == TradeMask)
192 else if ((type & MessageTypeMask) == OpenInterestMask)
196 else if ((type & MessageTypeMask) == QuoteMask)
200 switch (csv[_columnSide])
220 var scaleFactor = symbol.ID.Symbol ==
"VX" ? decimal.One : 10000000000m;
222 var price = csv[_columnPrice].ToDecimal() / scaleFactor;
223 var quantity = csv[_columnQuantity].ToInt32();
225 price *= _symbolMultipliers[symbol.ID.Symbol];
241 tick.AskPrice = price;
242 tick.AskSize = quantity;
246 tick.BidPrice = price;
247 tick.BidSize = quantity;
271 Exchange = symbol.ID.Market,
279 catch (Exception err)