From ad3a5a7d32c70647be4cc4591679d321088c633c Mon Sep 17 00:00:00 2001 From: 7u83 <7u83@mail.ru> Date: Mon, 11 Dec 2017 23:23:03 +0100 Subject: [PATCH] refactoring ... --- nbproject/project.properties | 2 +- src/sesim/Exchange.java | 17 +++-------------- src/sesim/Stock.java | 10 +++------- 3 files changed, 7 insertions(+), 22 deletions(-) diff --git a/nbproject/project.properties b/nbproject/project.properties index 107322f..e17d811 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -1,4 +1,4 @@ -#Mon, 11 Dec 2017 16:05:46 +0100 +#Mon, 11 Dec 2017 23:22:26 +0100 annotation.processing.enabled=true annotation.processing.enabled.in.editor=false annotation.processing.processors.list= diff --git a/src/sesim/Exchange.java b/src/sesim/Exchange.java index 9a442b3..ae450f9 100644 --- a/src/sesim/Exchange.java +++ b/src/sesim/Exchange.java @@ -683,12 +683,10 @@ public class Exchange { Order o; -// System.out.printf("Getting executor %d\n", Thread.currentThread().getId()); synchronized (stock) { -// System.out.printf("Have executor %d\n", Thread.currentThread().getId()); o = a.orders.get(order_id); - // System.out.print("The Order:"+o.limit+"\n"); + if (o != null) { SortedSet ob = stock.order_books.get(o.type); @@ -709,7 +707,7 @@ public class Exchange { public boolean cancelOrder(double account_id, Order order) { - return cancelOrder(getDefaultStock(), account_id, order.getID()); + return cancelOrder(order.stock, account_id, order.getID()); } Random random; @@ -776,8 +774,6 @@ public class Exchange { s.type = OrderType.SELL; stock.addOrderToBook(s); - -// System.out.printf("Stoploss hit %f %f\n", s.volume, s.limit); } } @@ -825,7 +821,7 @@ public class Exchange { /** * */ - public void executeOrders(Stock stock) { + private void executeOrders(Stock stock) { SortedSet bid = stock.order_books.get(OrderType.BUYLIMIT); SortedSet ask = stock.order_books.get(OrderType.SELLLIMIT); @@ -854,8 +850,6 @@ public class Exchange { money_total += price * volume; this.checkSLOrders(price); - //System.out.printf("Cannot match two unlimited orders!\n"); - //System.exit(0); } while (!ul_buy.isEmpty() && !ask.isEmpty()) { @@ -902,7 +896,6 @@ public class Exchange { volume_total += volume; money_total += price * volume; -// num_trades++; statistics.trades++; this.checkSLOrders(price); @@ -918,10 +911,6 @@ public class Exchange { q.time = timer.currentTimeMillis(); addQuoteToHistory(q); - - //this.quoteHistory.add(q); - //this.updateOHLCData(q); - //this.updateQuoteReceivers(q); } long buy_orders = 0; diff --git a/src/sesim/Stock.java b/src/sesim/Stock.java index 93b767e..adbacf2 100644 --- a/src/sesim/Stock.java +++ b/src/sesim/Stock.java @@ -30,7 +30,6 @@ import java.util.HashMap; import java.util.Iterator; import java.util.SortedSet; import java.util.TreeSet; -import java.util.concurrent.ConcurrentLinkedQueue; /** * @@ -55,7 +54,7 @@ public class Stock { // Create an order book for each order type for (Order.OrderType type : Order.OrderType.values()) { - this.order_books.put(type, new TreeSet(new Exchange.OrderComparator(type))); + order_books.put(type, new TreeSet(new Exchange.OrderComparator(type))); } quoteHistory = new TreeSet(); @@ -132,9 +131,8 @@ public class Stock { } - /** + /** * - * @param stock * @param type * @param depth * @return @@ -154,7 +152,7 @@ public class Stock { for (int i = 0; i < depth && it.hasNext(); i++) { Order o = it.next(); - + if (o.volume <= 0) { // throw an exception here } @@ -164,6 +162,4 @@ public class Stock { return ret; } - - }