17 using System.Globalization;
19 using System.Runtime.CompilerServices;
31 [ProtoContract(SkipConstructor =
true)]
35 private const decimal _scaleFactor = 1 / 10000m;
68 if (
Bid !=
null &&
Ask !=
null)
100 if (
Bid !=
null &&
Ask !=
null)
132 if (
Bid !=
null &&
Ask !=
null)
164 if (
Bid !=
null &&
Ask !=
null)
192 public override DateTime
EndTime
210 Time =
new DateTime();
228 public QuoteBar(DateTime time,
Symbol symbol,
IBar bid, decimal lastBidSize,
IBar ask, decimal lastAskSize, TimeSpan? period =
null)
250 [MethodImpl(MethodImplOptions.AggressiveInlining)]
251 public override void Update(decimal lastTrade, decimal bidPrice, decimal askPrice, decimal volume, decimal bidSize, decimal askSize)
254 if (
Bid ==
null && bidPrice != 0)
Bid =
new Bar(bidPrice, bidPrice, bidPrice, bidPrice);
257 if (
Ask ==
null && askPrice != 0)
Ask =
new Bar(askPrice, askPrice, askPrice, askPrice);
271 if (lastTrade != 0)
Value = lastTrade;
272 else if (askPrice != 0)
Value = askPrice;
273 else if (bidPrice != 0)
Value = bidPrice;
299 return ParseCfd(config, stream, date);
311 catch (Exception err)
313 Log.
Error(Invariant($
"QuoteBar.Reader(): Error parsing stream, Symbol: {config.Symbol.Value}, SecurityType: {config.SecurityType}, ") +
314 Invariant($
"Resolution: {config.Resolution}, Date: {date.ToStringInvariant("yyyy-MM-dd
")}, Message: {err}")
348 return ParseCfd(config, line, date);
360 catch (Exception err)
362 Log.
Error(Invariant($
"QuoteBar.Reader(): Error parsing line: '{line}', Symbol: {config.Symbol.Value}, SecurityType: {config.SecurityType}, ") +
363 Invariant($
"Resolution: {config.Resolution}, Date: {date.ToStringInvariant("yyyy-MM-dd
")}, Message: {err}")
380 return ParseQuote(config, date, line,
false);
392 return ParseQuote(config, date, streamReader,
false);
429 return ParseQuote(config, date, line,
false);
441 return ParseQuote(config, date, streamReader,
false);
453 return ParseQuote(config, date, line,
false);
465 return ParseQuote(config, date, streamReader,
false);
477 return ParseQuote(config, date, line,
true);
489 return ParseQuote(config, date, streamReader,
true);
503 var scaleFactor = useScaleFactor
524 var open = streamReader.GetDecimal();
525 var high = streamReader.GetDecimal();
526 var low = streamReader.GetDecimal();
527 var close = streamReader.GetDecimal();
528 var lastSize = streamReader.GetDecimal();
530 if (open != 0 || high != 0 || low != 0 || close != 0)
533 quoteBar.Bid.Open = open * scaleFactor;
534 quoteBar.Bid.High = high * scaleFactor;
535 quoteBar.Bid.Low = low * scaleFactor;
536 quoteBar.Bid.Close = close * scaleFactor;
537 quoteBar.LastBidSize = lastSize;
544 open = streamReader.GetDecimal();
545 high = streamReader.GetDecimal();
546 low = streamReader.GetDecimal();
547 close = streamReader.GetDecimal();
548 lastSize = streamReader.GetDecimal();
550 if (open != 0 || high != 0 || low != 0 || close != 0)
553 quoteBar.Ask.Open = open * scaleFactor;
554 quoteBar.Ask.High = high * scaleFactor;
555 quoteBar.Ask.Low = low * scaleFactor;
556 quoteBar.Ask.Close = close * scaleFactor;
557 quoteBar.LastAskSize = lastSize;
564 quoteBar.
Value = quoteBar.Close;
577 private QuoteBar ParseQuote(SubscriptionDataConfig config, DateTime date,
string line,
bool useScaleFactor)
579 var scaleFactor = useScaleFactor
585 Period = config.Increment,
589 var csv = line.ToCsv(11);
593 quoteBar.Time = DateTime.ParseExact(csv[0], DateFormat.TwelveCharacter, CultureInfo.InvariantCulture).ConvertTo(config.DataTimeZone, config.ExchangeTimeZone);
598 quoteBar.Time = date.Date.AddMilliseconds((
double)csv[0].ToDecimal()).ConvertTo(config.DataTimeZone, config.ExchangeTimeZone);
602 if (csv[1].Length != 0 || csv[2].Length != 0 || csv[3].Length != 0 || csv[4].Length != 0)
605 quoteBar.Bid.Open = csv[1].ToDecimal() * scaleFactor;
606 quoteBar.Bid.High = csv[2].ToDecimal() * scaleFactor;
607 quoteBar.Bid.Low = csv[3].ToDecimal() * scaleFactor;
608 quoteBar.Bid.Close = csv[4].ToDecimal() * scaleFactor;
609 quoteBar.LastBidSize = csv[5].ToDecimal();
617 if (csv[6].Length != 0 || csv[7].Length != 0 || csv[8].Length != 0 || csv[9].Length != 0)
620 quoteBar.Ask.Open = csv[6].ToDecimal() * scaleFactor;
621 quoteBar.Ask.High = csv[7].ToDecimal() * scaleFactor;
622 quoteBar.Ask.Low = csv[8].ToDecimal() * scaleFactor;
623 quoteBar.Ask.Close = csv[9].ToDecimal() * scaleFactor;
624 quoteBar.LastAskSize = csv[10].ToDecimal();
631 quoteBar.Value = quoteBar.Close;
696 return $
"{Symbol}: " +
697 $
"Bid: O: {Bid?.Open.SmartRounding()} " +
698 $
"Bid: H: {Bid?.High.SmartRounding()} " +
699 $
"Bid: L: {Bid?.Low.SmartRounding()} " +
700 $
"Bid: C: {Bid?.Close.SmartRounding()} " +
701 $
"Ask: O: {Ask?.Open.SmartRounding()} " +
702 $
"Ask: H: {Ask?.High.SmartRounding()} " +
703 $
"Ask: L: {Ask?.Low.SmartRounding()} " +
704 $
"Ask: C: {Ask?.Close.SmartRounding()} ";