/// <summary> /// Creates a new quote. /// The constructor doesn't copy quote entries, instead of it keeps them by reference. /// </summary> /// <param name="symbol">A symbol of the quote; can not be null.</param> /// <param name="creatingTime">A creating time of the quote.</param> /// <param name="bids">Bids should be sorted by price and can not be null.</param> /// <param name="asks">Asks should be sorted by price and can not be null.</param> /// <exception cref="System.ArgumentNullException">If symbol, bids or asks is null.</exception> public Quote(string symbol, DateTime creatingTime, QuoteEntry[] bids, QuoteEntry[] asks) { if (symbol == null) throw new ArgumentNullException(nameof(symbol), "Symbol can not be null."); if (bids == null) throw new ArgumentNullException(nameof(bids), "Bids can not be null."); if (asks == null) throw new ArgumentNullException(nameof(asks), "Asks can not be null."); this.Symbol = symbol; this.CreatingTime = creatingTime; this.Bids = bids; this.Asks = asks; }
static Level2Entry[] Level2EntriesFromQuoteEntries(QuoteEntry[] entries, double lot) { return entries.Select(o => new Level2Entry(o, lot)) .ToArray(); }
public Level2Entry(QuoteEntry entry, double lot) : this() { this.Price = entry.Price; this.Volume = entry.Volume / lot; }
static bool Equals(QuoteEntry[] first, QuoteEntry[] second) { if(ReferenceEquals(first,second)) { return true; } var count = first.Length; if (count != second.Length) return false; for (var index = 0; index < count; ++index) { var f = first[index]; var s = second[index]; if (f.Price != s.Price) return false; if (f.Volume != s.Volume) return false; } return true; }
static Quote Parse(string text) { var stream = new TextStream(); stream.Initialize(text); var lrpQuote = stream.ReadQuote("quote"); var bids = new QuoteEntry[lrpQuote.Bids.Length]; var asks = new QuoteEntry[lrpQuote.Asks.Length]; for (int index = 0; index < lrpQuote.Bids.Length; ++index) { bids[index] = new QuoteEntry(lrpQuote.Bids[index].Price, lrpQuote.Bids[index].Volume); } for (int index = 0; index < lrpQuote.Asks.Length; ++index) { asks[index] = new QuoteEntry(lrpQuote.Asks[index].Price, lrpQuote.Asks[index].Volume); } var result = new Quote(lrpQuote.Symbol, lrpQuote.CreatingTime, bids, asks); return result; }