in orderbook-core/src/main/java/com/epam/deltix/orderbook/core/impl/L3ConsolidatedQuoteProcessor.java [194:244]
public boolean handleReplace(final L3Processor<Quote> exchange,
final PackageHeaderInfo pck,
final L3EntryUpdateInfo msg) {
final QuoteSide side = msg.getSide();
final CharSequence quoteId = msg.getQuoteId();
final L3MarketSide<Quote> newSide = exchange.getMarketSide(side);
final L3MarketSide<Quote> consolidatedNewSide = getMarketSide(side);
final EntryValidationCode errorCode = newSide.isInvalidInsert(InsertType.ADD_BACK, msg.getQuoteId(), msg.getPrice(), msg.getSize(), side);
if (errorCode != null) {
subtractExchange(exchange);
exchange.processL3EntryUpdate(pck, msg);
}
final Quote quote = newSide.remove(quoteId);
if (quote != null) { // replace didn't change side
consolidatedNewSide.remove(quote);
quote.copyFrom(pck, msg);
newSide.add(quote);
consolidatedNewSide.add(quote);
return true;
}
final L3MarketSide<Quote> prevSide = exchange.getMarketSide(side == ASK ? BID : ASK);
final L3MarketSide<Quote> consolidatedPrevSide = getMarketSide(side == ASK ? BID : ASK);
final Quote removed = prevSide.remove(quoteId);
if (removed != null) { // replace changed side
consolidatedPrevSide.remove(removed);
Quote newQuote = removed;
if (newSide.isFull()) {
pool.release(removed);
final Quote worstQuote = newSide.getWorstQuote();
if (side == ASK && Decimal64Utils.isGreater(worstQuote.getPrice(), msg.getPrice()) ||
side == BID && Decimal64Utils.isGreater(msg.getPrice(), worstQuote.getPrice())) {
newQuote = newSide.remove(worstQuote.getQuoteId());
consolidatedNewSide.remove(newQuote);
} else {
return true;
}
}
newQuote.copyFrom(pck, msg);
newSide.add(newQuote);
consolidatedNewSide.add(newQuote);
return true;
}
if (validationOptions.isQuoteUpdate()) {
subtractExchange(exchange);
}
return exchange.processL3EntryUpdate(pck, msg);
}