From 3620fbcb04461382c0dc7b4e11398614cce254f1 Mon Sep 17 00:00:00 2001 From: 7u83 <7u83@maiol.ru> Date: Tue, 31 Jan 2017 08:54:38 +0100 Subject: [PATCH] Some testing with zero volume orders --- src/main/java/gui/OrderBook.java | 6 ++++++ src/main/java/sesim/Exchange.java | 17 +++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/main/java/gui/OrderBook.java b/src/main/java/gui/OrderBook.java index 89601df..7c12c09 100644 --- a/src/main/java/gui/OrderBook.java +++ b/src/main/java/gui/OrderBook.java @@ -176,6 +176,12 @@ public abstract class OrderBook extends javax.swing.JPanel implements Exchange.B return dfm.format((double)o.getLimit()); case 2: + double v = o.getVolume(); + if(v<=0){ + System.out.printf("Order: %s %f %f\n",o.getType().toString(),o.getVolume(),o.getLimit()); + // System.exit(0); + } + return dfv.format((double)o.getVolume()); //return String.format("%f", o.getVolume()); } diff --git a/src/main/java/sesim/Exchange.java b/src/main/java/sesim/Exchange.java index 33984ac..431e125 100644 --- a/src/main/java/sesim/Exchange.java +++ b/src/main/java/sesim/Exchange.java @@ -376,10 +376,17 @@ public class Exchange { //extends Thread { ArrayList ret = new ArrayList<>(); Iterator it = book.iterator(); + + for (int i = 0; i < depth && it.hasNext(); i++) { - ret.add(it.next()); + Order o=it.next(); + // System.out.print(o.volume); + if (o.volume<=0) + System.exit(0); + ret.add(o); } + // System.out.println(); tradelock.unlock(); return ret; } @@ -521,13 +528,19 @@ public class Exchange { //extends Thread { if (a == null) { return -1; } - tradelock.lock(); Order o = new Order(a, type, volume, limit); + if (o.volume<=0 || o.limit<=0){ + System.out.print("binweg\n"); + return -1; + } + tradelock.lock(); + addOrderToBook(o); a.orders.put(o.id, o); this.executeOrders(); + tradelock.unlock(); this.updateBookReceivers(OrderType.ASK); this.updateBookReceivers(OrderType.BID);