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;
242 public Tick(DateTime time,
Symbol symbol, decimal last, decimal bid, decimal ask)
262 public Tick(DateTime time,
Symbol symbol,
string saleCondition,
string exchange, decimal quantity, decimal price)
284 public Tick(DateTime time,
Symbol symbol,
string saleCondition,
Exchange exchange, decimal quantity, decimal price)
285 : this(time, symbol, saleCondition, string.Empty, quantity, price)
288 _exchange = exchange;
302 public Tick(DateTime time,
Symbol symbol,
string saleCondition,
string exchange, decimal bidSize, decimal bidPrice, decimal askSize, decimal askPrice)
328 public Tick(DateTime time,
Symbol symbol,
string saleCondition,
Exchange exchange, decimal bidSize, decimal bidPrice, decimal askSize, decimal askPrice)
329 : this(time, symbol, saleCondition, string.Empty, bidSize, bidPrice, askSize, askPrice)
332 _exchange = exchange;
342 var csv = line.Split(
',');
348 BidPrice = Convert.ToDecimal(csv[1], CultureInfo.InvariantCulture);
349 AskPrice = Convert.ToDecimal(csv[2], CultureInfo.InvariantCulture);
360 var csv = line.Split(
',');
363 Time = baseDate.Date.AddTicks(Convert.ToInt64(10000 * csv[0].ToDecimal()));
364 Value = csv[1].ToDecimal() / GetScaleFactor(symbol);
386 var scaleFactor = GetScaleFactor(config.
Symbol);
398 Value = reader.GetDecimal() / scaleFactor;
399 Quantity = reader.GetDecimal(out pastLineEnd);
409 BidPrice = reader.GetDecimal() / scaleFactor;
411 AskPrice = reader.GetDecimal() / scaleFactor;
412 AskSize = reader.GetDecimal(out pastLineEnd);
425 throw new InvalidOperationException($
"Tick(): Unexpected tick type {TickType}");
434 Time = date.Date.AddTicks(Convert.ToInt64(10000 * reader.GetDecimal()))
448 Time = date.Date.AddTicks(Convert.ToInt64(10000 * reader.GetDecimal()))
453 Value = reader.GetDecimal();
454 Quantity = reader.GetDecimal(out var endOfLine);
455 Suspicious = !endOfLine && reader.GetInt32() == 1;
462 AskSize = reader.GetDecimal(out var endOfLine);
463 Suspicious = !endOfLine && reader.GetInt32() == 1;
475 Time = date.Date.AddTicks(Convert.ToInt64(10000 * reader.GetDecimal()))
480 Value = reader.GetDecimal() / scaleFactor;
488 Value = reader.GetDecimal();
492 BidPrice = reader.GetDecimal() / scaleFactor;
494 AskPrice = reader.GetDecimal() / scaleFactor;
506 catch (Exception err)
526 var scaleFactor = GetScaleFactor(config.
Symbol);
539 Value = csv[index++].ToDecimal() / scaleFactor;
540 Quantity = csv[index++].ToDecimal();
541 if (csv.Count > index)
550 BidPrice = csv[index++].ToDecimal() / scaleFactor;
551 BidSize = csv[index++].ToDecimal();
552 AskPrice = csv[index++].ToDecimal() / scaleFactor;
553 AskSize = csv[index++].ToDecimal();
557 if (csv.Count > index)
566 throw new InvalidOperationException($
"Tick(): Unexpected tick type {TickType}");
574 var csv = line.ToCsv(3);
576 var ticks = (long)(csv[0].ToDecimal() * TimeSpan.TicksPerMillisecond);
577 Time = date.Date.AddTicks(ticks)
594 var csv = line.ToCsv(3);
595 Time = date.Date.AddTicks(Convert.ToInt64(10000 * csv[0].ToDecimal()))
597 Value = csv[1].ToDecimal();
604 var csv = line.ToCsv(6);
605 Time = date.Date.AddTicks(Convert.ToInt64(10000 * csv[0].ToDecimal()))
622 var csv = line.ToCsv(7);
624 Time = date.Date.AddTicks(Convert.ToInt64(10000 * csv[0].ToDecimal()))
629 Value = csv[1].ToDecimal()/scaleFactor;
637 Value = csv[1].ToDecimal();
641 if (csv[1].Length != 0)
643 BidPrice = csv[1].ToDecimal()/scaleFactor;
646 if (csv[3].Length != 0)
648 AskPrice = csv[3].ToDecimal()/scaleFactor;
661 catch (Exception err)
683 return new Tick(config, line, date);
702 return new Tick(config, reader, date);
738 [MethodImpl(MethodImplOptions.AggressiveInlining)]
739 public override void Update(decimal lastTrade, decimal bidPrice, decimal askPrice, decimal volume, decimal bidSize, decimal askSize)
746 Quantity = Convert.ToDecimal(volume);
752 [MethodImpl(MethodImplOptions.AggressiveInlining)]
768 return new Tick(
this);
780 return $
"{Symbol}: Price: {Price} Quantity: {Quantity}";
783 return $
"{Symbol}: Bid: {BidSize}@{BidPrice} Ask: {AskSize}@{AskPrice}";
786 return $
"{Symbol}: OpenInterest: {Value}";
789 throw new ArgumentOutOfRangeException();
811 private static decimal GetScaleFactor(
Symbol symbol)