/** * Returns the exchange of the given event or null. * * @param inEvent a <code>QuoteEvent</code> value * @return a <code>String</code> value */ private static String getExchange(QuoteEvent inEvent) { if(inEvent != null) { return inEvent.getExchange(); } return null; } /**
@Override public int compare(QuoteEvent inO1, QuoteEvent inO2) { if(inO1 == inO2) { return 0; } // the first key is price, either ascending or descending int result = inO1.getPrice().compareTo(inO2.getPrice()); if(result == 0) { // prices are equal // secondary sort should be on the timestamp long o1time = inO1.getTimeMillis(); long o2time = inO2.getTimeMillis(); if(o1time < o2time) { result = -1; } else if(o1time > o2time) { result = 1; } else { result = 0; } } // invert the result to be returned if necessary to get a descending sort return result * (mIsAscending ? 1 : -1); } }
quote.setMessageId(inQuoteEvent.getMessageId()); quote.setTimestamp(inTimestamp); quote.setInstrument(inQuoteEvent.getInstrument()); quote.setExchange(inQuoteEvent.getExchange()); quote.setPrice(inQuoteEvent.getPrice()); quote.setProcessedTimestamp(inQuoteEvent.getProcessedTimestamp()); quote.setReceivedTimestamp(inQuoteEvent.getReceivedTimestamp()); quote.setSize(inSize); quote.setExchangeTimestamp(inQuoteEvent.getExchangeTimestamp()); quote.setAction(inQuoteAction); quote.setSource(inQuoteEvent.getSource()); quote.setEventType(inQuoteEvent.getEventType()); quote.setLevel(inQuoteEvent.getLevel()); quote.setCount(inQuoteEvent.getCount()); quote.setIsEmpty(inQuoteEvent.isEmpty()); return quote;
try { if(!getCode().equals(event.getExchange())) { throw new IllegalArgumentException(SIMULATED_EXCHANGE_CODE_MISMATCH.getText(this, event, event.getExchange(), getCode())); PrivateInstrumentInfo book = getPrivateInstrumentInfo(event.getInstrument()); SLF4JLoggerProxy.debug(SimulatedExchange.class, "{} executing scripted event {}", //$NON-NLS-1$
if(inContent == Content.TOP_OF_BOOK) { if(quoteEvent.getAction() == QuoteAction.ADD) { if(latestTop != null) { QuoteEvent deleteEvent = null;
/** * Checks the given event to make sure it is appropriate to add to the <code>OrderBook</code>. * * @param inEvent a <code>QuoteEvent</code> value * @throws IllegalArgumentException if the event's symbol does not match the book's symbol */ private void checkEvent(QuoteEvent inEvent) { if(!lenient && !inEvent.getInstrument().equals(getInstrument())) { throw new IllegalArgumentException(Messages.INSTRUMENT_DOES_NOT_MATCH_ORDER_BOOK_INSTRUMENT.getText(inEvent.getInstrument(), getInstrument())); } } /**
/** * Returns the price of the given event as a <code>String</code>. * * @param inEvent a <code>QuoteEvent</code> value * @return a <code>String</code> value */ private static String getPriceAsString(QuoteEvent inEvent) { if(inEvent != null) { return inEvent.getPrice().toPlainString(); } return NO_QUANTITY; } /**
/** * Validates the contents of the given list. * * @param inQuotes a <code>List<? extends QuoteEvent></code> value * @param inInstrument an <code>Instrument</code> value * @throws IllegalArgumentException if any entry in the list is null * @throws IllegalArgumentException if an entry in the list is for a different instrument than the one given */ private static void validateList(List<? extends QuoteEvent> inQuotes, Instrument inInstrument) { for(QuoteEvent quote : inQuotes) { if(quote == null) { EventServices.error(new I18NBoundMessage1P(VALIDATION_LIST_CONTAINS_NULL, String.valueOf(inQuotes))); } if(!inInstrument.equals(quote.getInstrument())) { EventServices.error(new I18NBoundMessage2P(VALIDATION_LIST_INCORRECT_INSTRUMENT, quote, inInstrument)); } } } /**
ExchangeRequestBuilder topOfBookRequestBuilder = ExchangeRequestBuilder.newRequest().withInstrument(quoteEvent.getInstrument()); if(quoteEvent instanceof OptionEvent) { topOfBookRequestBuilder.withUnderlyingInstrument(((OptionEvent)quoteEvent).getUnderlyingInstrument()); "New top-of-book is {}", //$NON-NLS-1$ newTopOfBook); TopOfBook lastKnownTopOfBook = lastKnownTopsOfBook.get(quoteEvent.getInstrument()); SLF4JLoggerProxy.debug(SimulatedExchange.class, "Last-known top-of-book is {}", //$NON-NLS-1$ "New top-of-book is *not* different from last-known top-of-book, nothing to do"); //$NON-NLS-1$ lastKnownTopsOfBook.put(quoteEvent.getInstrument(), newTopOfBook);