in orderbook-core/src/main/java/com/epam/deltix/orderbook/core/impl/L3ConsolidatedQuoteProcessor.java [146:192]
public Quote processL3EntryNew(final PackageHeaderInfo pck, final L3EntryNewInfo msg) {
final QuoteSide side = msg.getSide();
@Alphanumeric final long exchangeId = msg.getExchangeId();
final Option<MutableExchange<Quote, L3Processor<Quote>>> holder = getOrCreateExchange(exchangeId);
if (!holder.hasValue() || holder.get().getProcessor().isWaitingForSnapshot()) {
return null;
}
final L3Processor<Quote> exchange = holder.get().getProcessor();
final L3MarketSide<Quote> marketSide = exchange.getMarketSide(side);
final EntryValidationCode errorCode = marketSide.isInvalidInsert(msg.getInsertType(), msg.getQuoteId(), msg.getPrice(), msg.getSize(), side);
if (errorCode != null) {
if (validationOptions.isQuoteInsert()) {
subtractExchange(exchange);
}
exchange.processL3EntryNew(pck, msg);
return null;
}
final Quote quote;
final L3MarketSide<Quote> consolidatedMarketSide = getMarketSide(side);
if (marketSide.isFull()) { // CAREFUL! In this case we can't guarantee uniqueness of quoteIds
final Quote worstQuote = marketSide.getWorstQuote();
if (side == ASK && Decimal64Utils.isGreater(worstQuote.getPrice(), msg.getPrice()) ||
side == BID && Decimal64Utils.isGreater(msg.getPrice(), worstQuote.getPrice())) {
quote = marketSide.remove(worstQuote.getQuoteId());
consolidatedMarketSide.remove(quote);
} else {
return null;
}
} else {
quote = pool.borrow();
}
quote.copyFrom(pck, msg);
if (!marketSide.add(quote)) {
pool.release(quote);
if (validationOptions.isQuoteInsert()) {
subtractExchange(exchange);
}
exchange.processL3EntryNew(pck, msg);
return null;
}
consolidatedMarketSide.add(quote);
return quote;
}