/// <summary> /// Adds a price quote to the <see cref="Book"/>. /// </summary> /// <param name="priceQuote">The price quote to add.</param> public void AddPriceQuote(PriceQuote priceQuote) { lock (this.lockMutex) { if (priceQuote == null) { throw new ArgumentNullException(nameof(priceQuote)); } if (this.priceQuotes.Contains(priceQuote)) { throw new InvalidOperationException(Localization.Localization.PRICE_QUOTE_ALREADY_IN_BOOK); } if (!this.securities.Contains(priceQuote.Security)) { throw new InvalidOperationException(Localization.Localization.PRICE_QUOTE_SECURITY_NOT_IN_BOOK); } if (!this.securities.Contains(priceQuote.Currency)) { throw new InvalidOperationException(Localization.Localization.PRICE_QUOTE_CURRENCY_NOT_IN_BOOK); } var duplicateIds = from q in this.priceQuotes where q.PriceQuoteId == priceQuote.PriceQuoteId select q; if (duplicateIds.Any()) { throw new InvalidOperationException(Localization.Localization.PRICE_QUOTE_ID_ALREADY_IN_BOOK); } var duplicateData = from q in this.priceQuotes where q.Security == priceQuote.Security where q.Currency == priceQuote.Currency where q.DateTime == priceQuote.DateTime where string.Equals(q.Source, priceQuote.Source, StringComparison.OrdinalIgnoreCase) select q; if (duplicateData.Any()) { throw new InvalidOperationException(Localization.Localization.PRICE_QUOTE_REDUNDANT_BY_SOURCE); } this.priceQuotes.Add(priceQuote); this.UpdateSaveTracks(st => st.AddPriceQuote(new PriceQuoteData(priceQuote))); } this.PriceQuoteAdded?.Invoke(this, new PriceQuoteAddedEventArgs(priceQuote)); }
public PriceQuoteData(PriceQuote priceQuote) { if (priceQuote == null) { throw new ArgumentNullException("priceQuote"); } this.PriceQuoteId = priceQuote.PriceQuoteId; this.DateTime = priceQuote.DateTime; this.SecuritySecurityId = priceQuote.Security.SecurityId; this.Quantity = priceQuote.Quantity; this.CurrencySecurityId = priceQuote.Currency.SecurityId; this.Price = priceQuote.Price; this.Source = priceQuote.Source; }
public PriceQuoteData(PriceQuote priceQuote) { if (priceQuote == null) { throw new ArgumentNullException(nameof(priceQuote)); } this.PriceQuoteId = priceQuote.PriceQuoteId; this.DateTime = priceQuote.DateTime; this.SecuritySecurityId = priceQuote.Security.SecurityId; this.Quantity = priceQuote.Quantity; this.CurrencySecurityId = priceQuote.Currency.SecurityId; this.Price = priceQuote.Price; this.Source = priceQuote.Source; }
/// <summary> /// Removes a price quote from the <see cref="Book"/>. /// </summary> /// <param name="priceQuote">The price quote to remove.</param> public void RemovePriceQuote(PriceQuote priceQuote) { lock (this.lockMutex) { if (priceQuote == null) { throw new ArgumentNullException(nameof(priceQuote)); } if (!this.priceQuotes.Contains(priceQuote)) { throw new InvalidOperationException(Localization.Localization.PRICE_QUOTE_NOT_IN_BOOK); } this.priceQuotes.Remove(priceQuote); this.UpdateSaveTracks(st => st.RemovePriceQuote(priceQuote.PriceQuoteId)); } this.PriceQuoteRemoved?.Invoke(this, new PriceQuoteRemovedEventArgs(priceQuote)); }
/// <inheritdoc/> public void AddPriceQuote(PriceQuoteData priceQuote) { lock (this) { var security = this.destinationBook.Securities.Where(s => s.SecurityId == priceQuote.SecuritySecurityId).Single(); var currency = this.destinationBook.Securities.Where(s => s.SecurityId == priceQuote.CurrencySecurityId).Single(); var newPriceQuote = new PriceQuote( priceQuote.PriceQuoteId, priceQuote.DateTime, security, priceQuote.Quantity, currency, priceQuote.Price, priceQuote.Source); this.destinationBook.AddPriceQuote( newPriceQuote); } }
public void AddPriceQuote(PriceQuoteData priceQuote) { lock (this) { var security = this.destinationBook.Securities.Where(s => s.SecurityId == priceQuote.SecuritySecurityId).Single(); var currency = this.destinationBook.Securities.Where(s => s.SecurityId == priceQuote.CurrencySecurityId).Single(); var newPriceQuote = new PriceQuote( priceQuote.PriceQuoteId, priceQuote.DateTime, security, priceQuote.Quantity, currency, priceQuote.Price, priceQuote.Source); this.destinationBook.AddPriceQuote( newPriceQuote); } }
/// <summary> /// Removes a price quote from the <see cref="Book"/>. /// </summary> /// <param name="priceQuote">The price quote to remove.</param> public void RemovePriceQuote(PriceQuote priceQuote) { lock (this.lockMutex) { if (priceQuote == null) { throw new ArgumentNullException("priceQuote"); } if (!this.priceQuotes.Contains(priceQuote)) { throw new InvalidOperationException("Could not remove the price quote from the book, because the price quote is not a member of the book."); } this.priceQuotes.Remove(priceQuote); this.UpdateSaveTracks(st => st.RemovePriceQuote(priceQuote.PriceQuoteId)); } this.PriceQuoteRemoved.SafeInvoke(this, new PriceQuoteRemovedEventArgs(priceQuote)); }
/// <summary> /// Adds a price quote to the <see cref="Book"/>. /// </summary> /// <param name="priceQuote">The price quote to add.</param> public void AddPriceQuote(PriceQuote priceQuote) { lock (this.lockMutex) { if (priceQuote == null) { throw new ArgumentNullException("priceQuote"); } if (this.priceQuotes.Contains(priceQuote)) { throw new InvalidOperationException("Could not add the price quote to the book, because the price quote already belongs to the book."); } if (!this.securities.Contains(priceQuote.Security)) { throw new InvalidOperationException("Could not add the price quote to the book, because the price quote's security has not been added."); } if (!this.securities.Contains(priceQuote.Currency)) { throw new InvalidOperationException("Could not add the price quote to the book, because the price quote's currency has not been added."); } var duplicateIds = from q in this.priceQuotes where q.PriceQuoteId == priceQuote.PriceQuoteId select q; if (duplicateIds.Any()) { throw new InvalidOperationException("Could not add the price quote to the book, because another price quote has already been added with the same Price Quote Id."); } var duplicateData = from q in this.priceQuotes where q.Security == priceQuote.Security where q.Currency == priceQuote.Currency where q.DateTime == priceQuote.DateTime where string.Equals(q.Source, priceQuote.Source, StringComparison.OrdinalIgnoreCase) select q; if (duplicateData.Any()) { throw new InvalidOperationException( "Could not add the price quote to the book, because another price quote has already been added with the same Security, Currency, Date, and Source."); } this.priceQuotes.Add(priceQuote); this.UpdateSaveTracks(st => st.AddPriceQuote(new PriceQuoteData(priceQuote))); } this.PriceQuoteAdded.SafeInvoke(this, new PriceQuoteAddedEventArgs(priceQuote)); }