17 using System.Globalization;
19 using System.Runtime.CompilerServices;
32 [ProtoContract(SkipConstructor =
true)]
36 private const decimal _scaleFactor = 1 / 10000m;
42 [PandasColumn(
"bidsize")]
49 [PandasColumn(
"asksize")]
71 if (
Bid !=
null &&
Ask !=
null)
103 if (
Bid !=
null &&
Ask !=
null)
135 if (
Bid !=
null &&
Ask !=
null)
167 if (
Bid !=
null &&
Ask !=
null)
196 public override DateTime
EndTime
215 Time =
new DateTime();
233 public QuoteBar(DateTime time,
Symbol symbol,
IBar bid, decimal lastBidSize,
IBar ask, decimal lastAskSize, TimeSpan? period =
null)
255 [MethodImpl(MethodImplOptions.AggressiveInlining)]
256 public override void Update(decimal lastTrade, decimal bidPrice, decimal askPrice, decimal volume, decimal bidSize, decimal askSize)
259 if (
Bid ==
null && bidPrice != 0)
Bid =
new Bar(bidPrice, bidPrice, bidPrice, bidPrice);
262 if (
Ask ==
null && askPrice != 0)
Ask =
new Bar(askPrice, askPrice, askPrice, askPrice);
276 if (lastTrade != 0)
Value = lastTrade;
277 else if (askPrice != 0)
Value = askPrice;
278 else if (bidPrice != 0)
Value = bidPrice;
304 return ParseCfd(config, stream, date);
316 catch (Exception err)
318 Log.
Error(Invariant($
"QuoteBar.Reader(): Error parsing stream, Symbol: {config.Symbol.Value}, SecurityType: {config.SecurityType}, ") +
319 Invariant($
"Resolution: {config.Resolution}, Date: {date.ToStringInvariant("yyyy-MM-dd
")}, Message: {err}")
353 return ParseCfd(config, line, date);
365 catch (Exception err)
367 Log.
Error(Invariant($
"QuoteBar.Reader(): Error parsing line: '{line}', Symbol: {config.Symbol.Value}, SecurityType: {config.SecurityType}, ") +
368 Invariant($
"Resolution: {config.Resolution}, Date: {date.ToStringInvariant("yyyy-MM-dd
")}, Message: {err}")
385 return ParseQuote(config, date, line,
false);
397 return ParseQuote(config, date, streamReader,
false);
434 return ParseQuote(config, date, line,
false);
446 return ParseQuote(config, date, streamReader,
false);
458 return ParseQuote(config, date, line,
false);
470 return ParseQuote(config, date, streamReader,
false);
482 return ParseQuote(config, date, line,
true);
494 return ParseQuote(config, date, streamReader,
true);
508 var scaleFactor = useScaleFactor
529 var open = streamReader.GetDecimal();
530 var high = streamReader.GetDecimal();
531 var low = streamReader.GetDecimal();
532 var close = streamReader.GetDecimal();
533 var lastSize = streamReader.GetDecimal();
535 if (open != 0 || high != 0 || low != 0 || close != 0)
538 quoteBar.Bid.Open = open * scaleFactor;
539 quoteBar.Bid.High = high * scaleFactor;
540 quoteBar.Bid.Low = low * scaleFactor;
541 quoteBar.Bid.Close = close * scaleFactor;
542 quoteBar.LastBidSize = lastSize;
549 open = streamReader.GetDecimal();
550 high = streamReader.GetDecimal();
551 low = streamReader.GetDecimal();
552 close = streamReader.GetDecimal();
553 lastSize = streamReader.GetDecimal();
555 if (open != 0 || high != 0 || low != 0 || close != 0)
558 quoteBar.Ask.Open = open * scaleFactor;
559 quoteBar.Ask.High = high * scaleFactor;
560 quoteBar.Ask.Low = low * scaleFactor;
561 quoteBar.Ask.Close = close * scaleFactor;
562 quoteBar.LastAskSize = lastSize;
569 quoteBar.
Value = quoteBar.Close;
582 private QuoteBar ParseQuote(SubscriptionDataConfig config, DateTime date,
string line,
bool useScaleFactor)
584 var scaleFactor = useScaleFactor
590 Period = config.Increment,
594 var csv = line.ToCsv(11);
598 quoteBar.Time = DateTime.ParseExact(csv[0], DateFormat.TwelveCharacter, CultureInfo.InvariantCulture).ConvertTo(config.DataTimeZone, config.ExchangeTimeZone);
603 quoteBar.Time = date.Date.AddMilliseconds((
double)csv[0].ToDecimal()).ConvertTo(config.DataTimeZone, config.ExchangeTimeZone);
607 if (csv[1].Length != 0 || csv[2].Length != 0 || csv[3].Length != 0 || csv[4].Length != 0)
610 quoteBar.Bid.Open = csv[1].ToDecimal() * scaleFactor;
611 quoteBar.Bid.High = csv[2].ToDecimal() * scaleFactor;
612 quoteBar.Bid.Low = csv[3].ToDecimal() * scaleFactor;
613 quoteBar.Bid.Close = csv[4].ToDecimal() * scaleFactor;
614 quoteBar.LastBidSize = csv[5].ToDecimal();
622 if (csv[6].Length != 0 || csv[7].Length != 0 || csv[8].Length != 0 || csv[9].Length != 0)
625 quoteBar.Ask.Open = csv[6].ToDecimal() * scaleFactor;
626 quoteBar.Ask.High = csv[7].ToDecimal() * scaleFactor;
627 quoteBar.Ask.Low = csv[8].ToDecimal() * scaleFactor;
628 quoteBar.Ask.Close = csv[9].ToDecimal() * scaleFactor;
629 quoteBar.LastAskSize = csv[10].ToDecimal();
636 quoteBar.Value = quoteBar.Close;
701 return $
"{Symbol}: " +
702 $
"Bid: O: {Bid?.Open.SmartRounding()} " +
703 $
"Bid: H: {Bid?.High.SmartRounding()} " +
704 $
"Bid: L: {Bid?.Low.SmartRounding()} " +
705 $
"Bid: C: {Bid?.Close.SmartRounding()} " +
706 $
"Ask: O: {Ask?.Open.SmartRounding()} " +
707 $
"Ask: H: {Ask?.High.SmartRounding()} " +
708 $
"Ask: L: {Ask?.Low.SmartRounding()} " +
709 $
"Ask: C: {Ask?.Close.SmartRounding()} ";