From c4c13f1330fc221d37e170a1d61658137ae96c2b Mon Sep 17 00:00:00 2001 From: Jussi Virtanen Date: Mon, 14 Aug 2017 15:58:35 +0200 Subject: [PATCH] Use integers as order entry identifiers in FIX gateway --- .../com/paritytrading/parity/fix/Order.java | 10 +++--- .../com/paritytrading/parity/fix/Orders.java | 8 ++--- .../com/paritytrading/parity/fix/Session.java | 33 +++++++++++-------- 3 files changed, 28 insertions(+), 23 deletions(-) diff --git a/applications/fix/src/main/java/com/paritytrading/parity/fix/Order.java b/applications/fix/src/main/java/com/paritytrading/parity/fix/Order.java index ed763818..cdaea947 100644 --- a/applications/fix/src/main/java/com/paritytrading/parity/fix/Order.java +++ b/applications/fix/src/main/java/com/paritytrading/parity/fix/Order.java @@ -7,7 +7,7 @@ class Order { - private byte[] orderEntryId; + private long orderEntryId; private long orderId; private String nextClOrdId; private String clOrdId; @@ -21,9 +21,9 @@ class Order { private double avgPx; private char cxlRejResponseTo; - public Order(String orderEntryId, String clOrdId, String account, char side, + public Order(long orderEntryId, String clOrdId, String account, char side, String symbol, double orderQty) { - this.orderEntryId = new byte[POE.ORDER_ID_LENGTH]; + this.orderEntryId = orderEntryId; this.orderId = 0; this.nextClOrdId = null; this.clOrdId = clOrdId; @@ -36,8 +36,6 @@ public Order(String orderEntryId, String clOrdId, String account, char side, this.cumQty = 0; this.avgPx = 0.0; this.cxlRejResponseTo = CxlRejResponseToValues.OrderCancelRequest; - - ASCII.putLeft(this.orderEntryId, orderEntryId); } public void orderAccepted(long orderNumber) { @@ -62,7 +60,7 @@ public void orderCanceled(double canceledQuantity) { nextClOrdId = null; } - public byte[] getOrderEntryID() { + public long getOrderEntryID() { return orderEntryId; } diff --git a/applications/fix/src/main/java/com/paritytrading/parity/fix/Orders.java b/applications/fix/src/main/java/com/paritytrading/parity/fix/Orders.java index fe5be068..d5dde7e9 100644 --- a/applications/fix/src/main/java/com/paritytrading/parity/fix/Orders.java +++ b/applications/fix/src/main/java/com/paritytrading/parity/fix/Orders.java @@ -27,22 +27,22 @@ public Order findByClOrdID(String clOrdId) { return null; } - public Order findByOrderEntryID(byte[] orderEntryId) { + public Order findByOrderEntryID(long orderEntryId) { for (int i = 0; i < orders.size(); i++) { Order order = orders.get(i); - if (Arrays.equals(orderEntryId, order.getOrderEntryID())) + if (orderEntryId == order.getOrderEntryID()) return order; } return null; } - public void removeByOrderEntryID(byte[] orderEntryId) { + public void removeByOrderEntryID(long orderEntryId) { for (int i = 0; i < orders.size(); i++) { Order order = orders.get(i); - if (Arrays.equals(orderEntryId, order.getOrderEntryID())) { + if (orderEntryId == order.getOrderEntryID()) { orders.remove(i); break; } diff --git a/applications/fix/src/main/java/com/paritytrading/parity/fix/Session.java b/applications/fix/src/main/java/com/paritytrading/parity/fix/Session.java index 3465e598..dc1fae2e 100644 --- a/applications/fix/src/main/java/com/paritytrading/parity/fix/Session.java +++ b/applications/fix/src/main/java/com/paritytrading/parity/fix/Session.java @@ -12,7 +12,6 @@ import com.paritytrading.parity.net.poe.POEClientListener; import com.paritytrading.parity.util.Instrument; import com.paritytrading.parity.util.Instruments; -import com.paritytrading.parity.util.OrderIDGenerator; import com.paritytrading.philadelphia.FIXConfig; import com.paritytrading.philadelphia.FIXField; import com.paritytrading.philadelphia.FIXMessage; @@ -42,7 +41,7 @@ class Session implements Closeable { private static ByteBuffer txBuffer = ByteBuffer.allocateDirect(POE.MAX_INBOUND_MESSAGE_LENGTH); - private OrderIDGenerator orderEntryIds; + private long nextOrderEntryId; private Orders orders; @@ -54,7 +53,7 @@ class Session implements Closeable { public Session(OrderEntryFactory orderEntry, SocketChannel fix, FIXConfig config, Instruments instruments) throws IOException { - this.orderEntryIds = new OrderIDGenerator(); + this.nextOrderEntryId = 1; this.orders = new Orders(); @@ -176,9 +175,9 @@ private void newOrderSingle(FIXMessage message) throws IOException { return; } - String orderEntryId = orderEntryIds.next(); + long orderEntryId = nextOrderEntryId++; - ASCII.putLeft(enterOrder.orderId, orderEntryId); + ASCII.putLongLeft(enterOrder.orderId, orderEntryId); String clOrdId = clOrdIdValue.asString(); @@ -342,7 +341,7 @@ private void orderCancel(FIXMessage message, char msgType) throws IOException { order.setNextClOrdID(clOrdId); order.setCxlRejResponseTo(cxlRejResponseTo); - System.arraycopy(order.getOrderEntryID(), 0, cancelOrder.orderId, 0, cancelOrder.orderId.length); + ASCII.putLongLeft(cancelOrder.orderId, order.getOrderEntryID()); cancelOrder.quantity = (long)(qty * config.getSizeFactor()); send(cancelOrder); @@ -657,7 +656,9 @@ private class OrderEntryListener implements POEClientListener, SoupBinTCPClientS @Override public void orderAccepted(POE.OrderAccepted message) throws IOException { - Order order = orders.findByOrderEntryID(message.orderId); + long orderEntryId = ASCII.getLong(message.orderId); + + Order order = orders.findByOrderEntryID(orderEntryId); if (order == null) return; @@ -668,7 +669,9 @@ public void orderAccepted(POE.OrderAccepted message) throws IOException { @Override public void orderRejected(POE.OrderRejected message) throws IOException { - Order order = orders.findByOrderEntryID(message.orderId); + long orderEntryId = ASCII.getLong(message.orderId); + + Order order = orders.findByOrderEntryID(orderEntryId); if (order == null) return; @@ -687,12 +690,14 @@ public void orderRejected(POE.OrderRejected message) throws IOException { break; } - orders.removeByOrderEntryID(message.orderId); + orders.removeByOrderEntryID(orderEntryId); } @Override public void orderExecuted(POE.OrderExecuted message) throws IOException { - Order order = orders.findByOrderEntryID(message.orderId); + long orderEntryId = ASCII.getLong(message.orderId); + + Order order = orders.findByOrderEntryID(orderEntryId); if (order == null) return; @@ -706,7 +711,7 @@ public void orderExecuted(POE.OrderExecuted message) throws IOException { sendOrderExecuted(order, lastQty, lastPx, config); if (order.getLeavesQty() == 0) { - orders.removeByOrderEntryID(message.orderId); + orders.removeByOrderEntryID(orderEntryId); if (order.isInPendingStatus()) sendOrderCancelReject(order); @@ -715,7 +720,9 @@ public void orderExecuted(POE.OrderExecuted message) throws IOException { @Override public void orderCanceled(POE.OrderCanceled message) throws IOException { - Order order = orders.findByOrderEntryID(message.orderId); + long orderEntryId = ASCII.getLong(message.orderId); + + Order order = orders.findByOrderEntryID(orderEntryId); if (order == null) return; @@ -726,7 +733,7 @@ public void orderCanceled(POE.OrderCanceled message) throws IOException { sendOrderCanceled(order, config); if (order.getLeavesQty() == 0) - orders.removeByOrderEntryID(message.orderId); + orders.removeByOrderEntryID(orderEntryId); } @Override