Skip to content

Instantly share code, notes, and snippets.

@maxant
Last active August 29, 2015 14:12
Show Gist options
  • Save maxant/7a0325df268cdc2a19b1 to your computer and use it in GitHub Desktop.
Save maxant/7a0325df268cdc2a19b1 to your computer and use it in GitHub Desktop.
Relevant parts of the trading engine
public void run() {
while (running) {
prepareMarket();
List<Sale> sales = market.trade();
LOGGER.info("trading completed");
noteMarketPricesAndVolumes(sales);
persistSale(sales);
LOGGER.info("persisting completed, notifying involved parties...");
sales.stream().forEach(sale -> {
if (sale.getBuyer().listener != null)
sale.getBuyer().listener.onEvent(EventType.PURCHASE, sale);
if (sale.getSeller().listener != null)
sale.getSeller().listener.onEvent(EventType.SALE, sale);
});
...
try {
Thread.sleep(delay);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment