19 using Newtonsoft.Json;
22 using System.Globalization;
23 using System.Runtime.CompilerServices;
31 [ProtoContract(SkipConstructor =
true)]
32 [ProtoInclude(1000, typeof(OpenInterest))]
36 private string _exchangeValue;
37 private uint? _parsedSaleCondition;
58 if (_exchange ==
null)
63 return _exchange.
Code;
67 _exchangeValue = value;
80 if (_exchange ==
null)
89 _exchangeValue = value;
112 if (!_parsedSaleCondition.HasValue)
114 _parsedSaleCondition = uint.Parse(
SaleCondition, NumberStyles.HexNumber, CultureInfo.InvariantCulture);
116 return _parsedSaleCondition.Value;
120 _parsedSaleCondition = value;
180 Time =
new DateTime();
199 Time =
new DateTime(original.
Time.Ticks);
204 _exchange = original._exchange;
205 _exchangeValue = original._exchangeValue;
223 public Tick(DateTime time,
Symbol symbol, decimal bid, decimal ask)
228 Value = (bid + ask) / 2;
240 public Tick(DateTime time,
Symbol symbol, decimal openInterest)
244 Value = openInterest;
257 public Tick(DateTime time,
Symbol symbol, decimal last, decimal bid, decimal ask)
277 public Tick(DateTime time,
Symbol symbol,
string saleCondition,
string exchange, decimal quantity, decimal price)
299 public Tick(DateTime time,
Symbol symbol,
string saleCondition,
Exchange exchange, decimal quantity, decimal price)
300 : this(time, symbol, saleCondition, string.Empty, quantity, price)
303 _exchange = exchange;
317 public Tick(DateTime time,
Symbol symbol,
string saleCondition,
string exchange, decimal bidSize, decimal bidPrice, decimal askSize, decimal askPrice)
343 public Tick(DateTime time,
Symbol symbol,
string saleCondition,
Exchange exchange, decimal bidSize, decimal bidPrice, decimal askSize, decimal askPrice)
344 : this(time, symbol, saleCondition, string.Empty, bidSize, bidPrice, askSize, askPrice)
347 _exchange = exchange;
357 var csv = line.Split(
',');
363 BidPrice = Convert.ToDecimal(csv[1], CultureInfo.InvariantCulture);
364 AskPrice = Convert.ToDecimal(csv[2], CultureInfo.InvariantCulture);
375 var csv = line.Split(
',');
378 Time = baseDate.Date.AddTicks(Convert.ToInt64(10000 * csv[0].ToDecimal()));
379 Value = csv[1].ToDecimal() / GetScaleFactor(symbol);
401 var scaleFactor = GetScaleFactor(config.
Symbol);
413 Value = reader.GetDecimal() / scaleFactor;
414 Quantity = reader.GetDecimal(out pastLineEnd);
424 BidPrice = reader.GetDecimal() / scaleFactor;
426 AskPrice = reader.GetDecimal() / scaleFactor;
427 AskSize = reader.GetDecimal(out pastLineEnd);
440 throw new InvalidOperationException($
"Tick(): Unexpected tick type {TickType}");
449 Time = date.Date.AddTicks(Convert.ToInt64(10000 * reader.GetDecimal()))
463 Time = date.Date.AddTicks(Convert.ToInt64(10000 * reader.GetDecimal()))
468 Value = reader.GetDecimal();
469 Quantity = reader.GetDecimal(out var endOfLine);
470 Suspicious = !endOfLine && reader.GetInt32() == 1;
477 AskSize = reader.GetDecimal(out var endOfLine);
478 Suspicious = !endOfLine && reader.GetInt32() == 1;
490 Time = date.Date.AddTicks(Convert.ToInt64(10000 * reader.GetDecimal()))
495 Value = reader.GetDecimal() / scaleFactor;
503 Value = reader.GetDecimal();
507 BidPrice = reader.GetDecimal() / scaleFactor;
509 AskPrice = reader.GetDecimal() / scaleFactor;
521 catch (Exception err)
541 var scaleFactor = GetScaleFactor(config.
Symbol);
554 Value = csv[index++].ToDecimal() / scaleFactor;
555 Quantity = csv[index++].ToDecimal();
556 if (csv.Count > index)
565 BidPrice = csv[index++].ToDecimal() / scaleFactor;
566 BidSize = csv[index++].ToDecimal();
567 AskPrice = csv[index++].ToDecimal() / scaleFactor;
568 AskSize = csv[index++].ToDecimal();
572 if (csv.Count > index)
581 throw new InvalidOperationException($
"Tick(): Unexpected tick type {TickType}");
589 var csv = line.ToCsv(3);
591 var ticks = (long)(csv[0].ToDecimal() * TimeSpan.TicksPerMillisecond);
592 Time = date.Date.AddTicks(ticks)
609 var csv = line.ToCsv(3);
610 Time = date.Date.AddTicks(Convert.ToInt64(10000 * csv[0].ToDecimal()))
612 Value = csv[1].ToDecimal();
619 var csv = line.ToCsv(6);
620 Time = date.Date.AddTicks(Convert.ToInt64(10000 * csv[0].ToDecimal()))
637 var csv = line.ToCsv(7);
639 Time = date.Date.AddTicks(Convert.ToInt64(10000 * csv[0].ToDecimal()))
644 Value = csv[1].ToDecimal()/scaleFactor;
652 Value = csv[1].ToDecimal();
656 if (csv[1].Length != 0)
658 BidPrice = csv[1].ToDecimal()/scaleFactor;
661 if (csv[3].Length != 0)
663 AskPrice = csv[3].ToDecimal()/scaleFactor;
676 catch (Exception err)
698 return new Tick(config, line, date);
717 return new Tick(config, stream, date);
753 [MethodImpl(MethodImplOptions.AggressiveInlining)]
754 public override void Update(decimal lastTrade, decimal bidPrice, decimal askPrice, decimal volume, decimal bidSize, decimal askSize)
761 Quantity = Convert.ToDecimal(volume);
767 [MethodImpl(MethodImplOptions.AggressiveInlining)]
783 return new Tick(
this);
795 return $
"{Symbol}: Price: {Price} Quantity: {Quantity}";
798 return $
"{Symbol}: Bid: {BidSize}@{BidPrice} Ask: {AskSize}@{AskPrice}";
801 return $
"{Symbol}: OpenInterest: {Value}";
804 throw new ArgumentOutOfRangeException();
826 private static decimal GetScaleFactor(
Symbol symbol)