in orderbook-core/src/main/java/com/epam/deltix/orderbook/core/impl/L3SingleExchangeQuoteProcessor.java [96:133]
public Quote processL3EntryNew(final PackageHeaderInfo pck, final L3EntryNewInfo msg) {
if (!validExchange(pck, msg.getExchangeId())) {
return null;
}
if (isWaitingForSnapshot()) {
return null;
}
final QuoteSide side = msg.getSide();
final L3MarketSide<Quote> marketSide = getMarketSide(side);
final EntryValidationCode errorCode = marketSide.isInvalidInsert(msg.getInsertType(), msg.getQuoteId(), msg.getPrice(), msg.getSize(), side);
if (errorCode != null) {
failInsert(pck, errorCode);
return null;
}
final Quote quote;
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());
} else {
return null;
}
} else {
quote = pool.borrow();
}
quote.copyFrom(pck, msg);
if (!marketSide.add(quote)) {
pool.release(quote);
failInsert(pck, EntryValidationCode.DUPLICATE_QUOTE_ID);
return null;
}
return quote;
}