19 using Newtonsoft.Json;
22 using System.Globalization;
23 using System.Runtime.CompilerServices;
32 [ProtoContract(SkipConstructor =
true)]
33 [ProtoInclude(1000, typeof(OpenInterest))]
37 private string _exchangeValue;
38 private uint? _parsedSaleCondition;
61 if (_exchange ==
null)
66 return _exchange.
Code;
70 _exchangeValue = value;
83 if (_exchange ==
null)
92 _exchangeValue = value;
117 if (!_parsedSaleCondition.HasValue)
119 _parsedSaleCondition = uint.Parse(
SaleCondition, NumberStyles.HexNumber, CultureInfo.InvariantCulture);
121 return _parsedSaleCondition.Value;
125 _parsedSaleCondition = value;
185 Time =
new DateTime();
204 Time =
new DateTime(original.
Time.Ticks);
209 _exchange = original._exchange;
210 _exchangeValue = original._exchangeValue;
228 public Tick(DateTime time,
Symbol symbol, decimal bid, decimal ask)
233 Value = (bid + ask) / 2;
245 public Tick(DateTime time,
Symbol symbol, decimal openInterest)
249 Value = openInterest;
262 public Tick(DateTime time,
Symbol symbol, decimal last, decimal bid, decimal ask)
282 public Tick(DateTime time,
Symbol symbol,
string saleCondition,
string exchange, decimal quantity, decimal price)
304 public Tick(DateTime time,
Symbol symbol,
string saleCondition,
Exchange exchange, decimal quantity, decimal price)
305 : this(time, symbol, saleCondition, string.Empty, quantity, price)
308 _exchange = exchange;
322 public Tick(DateTime time,
Symbol symbol,
string saleCondition,
string exchange, decimal bidSize, decimal bidPrice, decimal askSize, decimal askPrice)
348 public Tick(DateTime time,
Symbol symbol,
string saleCondition,
Exchange exchange, decimal bidSize, decimal bidPrice, decimal askSize, decimal askPrice)
349 : this(time, symbol, saleCondition, string.Empty, bidSize, bidPrice, askSize, askPrice)
352 _exchange = exchange;
362 var csv = line.Split(
',');
368 BidPrice = Convert.ToDecimal(csv[1], CultureInfo.InvariantCulture);
369 AskPrice = Convert.ToDecimal(csv[2], CultureInfo.InvariantCulture);
380 var csv = line.Split(
',');
383 Time = baseDate.Date.AddTicks(Convert.ToInt64(10000 * csv[0].ToDecimal()));
384 Value = csv[1].ToDecimal() / GetScaleFactor(symbol);
406 var scaleFactor = GetScaleFactor(config.
Symbol);
418 Value = reader.GetDecimal() / scaleFactor;
419 Quantity = reader.GetDecimal(out pastLineEnd);
429 BidPrice = reader.GetDecimal() / scaleFactor;
431 AskPrice = reader.GetDecimal() / scaleFactor;
432 AskSize = reader.GetDecimal(out pastLineEnd);
445 throw new InvalidOperationException($
"Tick(): Unexpected tick type {TickType}");
454 Time = date.Date.AddTicks(Convert.ToInt64(10000 * reader.GetDecimal()))
468 Time = date.Date.AddTicks(Convert.ToInt64(10000 * reader.GetDecimal()))
473 Value = reader.GetDecimal();
474 Quantity = reader.GetDecimal(out var endOfLine);
475 Suspicious = !endOfLine && reader.GetInt32() == 1;
482 AskSize = reader.GetDecimal(out var endOfLine);
483 Suspicious = !endOfLine && reader.GetInt32() == 1;
495 Time = date.Date.AddTicks(Convert.ToInt64(10000 * reader.GetDecimal()))
500 Value = reader.GetDecimal() / scaleFactor;
508 Value = reader.GetDecimal();
512 BidPrice = reader.GetDecimal() / scaleFactor;
514 AskPrice = reader.GetDecimal() / scaleFactor;
526 catch (Exception err)
546 var scaleFactor = GetScaleFactor(config.
Symbol);
559 Value = csv[index++].ToDecimal() / scaleFactor;
560 Quantity = csv[index++].ToDecimal();
561 if (csv.Count > index)
570 BidPrice = csv[index++].ToDecimal() / scaleFactor;
571 BidSize = csv[index++].ToDecimal();
572 AskPrice = csv[index++].ToDecimal() / scaleFactor;
573 AskSize = csv[index++].ToDecimal();
577 if (csv.Count > index)
586 throw new InvalidOperationException($
"Tick(): Unexpected tick type {TickType}");
594 var csv = line.ToCsv(3);
596 var ticks = (long)(csv[0].ToDecimal() * TimeSpan.TicksPerMillisecond);
597 Time = date.Date.AddTicks(ticks)
614 var csv = line.ToCsv(3);
615 Time = date.Date.AddTicks(Convert.ToInt64(10000 * csv[0].ToDecimal()))
617 Value = csv[1].ToDecimal();
624 var csv = line.ToCsv(6);
625 Time = date.Date.AddTicks(Convert.ToInt64(10000 * csv[0].ToDecimal()))
642 var csv = line.ToCsv(7);
644 Time = date.Date.AddTicks(Convert.ToInt64(10000 * csv[0].ToDecimal()))
649 Value = csv[1].ToDecimal()/scaleFactor;
657 Value = csv[1].ToDecimal();
661 if (csv[1].Length != 0)
663 BidPrice = csv[1].ToDecimal()/scaleFactor;
666 if (csv[3].Length != 0)
668 AskPrice = csv[3].ToDecimal()/scaleFactor;
681 catch (Exception err)
703 return new Tick(config, line, date);
722 return new Tick(config, stream, date);
758 [MethodImpl(MethodImplOptions.AggressiveInlining)]
759 public override void Update(decimal lastTrade, decimal bidPrice, decimal askPrice, decimal volume, decimal bidSize, decimal askSize)
766 Quantity = Convert.ToDecimal(volume);
772 [MethodImpl(MethodImplOptions.AggressiveInlining)]
788 return new Tick(
this);
800 return $
"{Symbol}: Price: {Price} Quantity: {Quantity}";
803 return $
"{Symbol}: Bid: {BidSize}@{BidPrice} Ask: {AskSize}@{AskPrice}";
806 return $
"{Symbol}: OpenInterest: {Value}";
809 throw new ArgumentOutOfRangeException();
831 private static decimal GetScaleFactor(
Symbol symbol)