Skip to content
This repository has been archived by the owner on Feb 10, 2022. It is now read-only.

Commit

Permalink
Use integers as order entry identifiers in FIX gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
jvirtanen committed Aug 14, 2017
1 parent 2ced042 commit c4c13f1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class Order {

private byte[] orderEntryId;
private long orderEntryId;
private long orderId;
private String nextClOrdId;
private String clOrdId;
Expand All @@ -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;
Expand All @@ -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) {
Expand All @@ -62,7 +60,7 @@ public void orderCanceled(double canceledQuantity) {
nextClOrdId = null;
}

public byte[] getOrderEntryID() {
public long getOrderEntryID() {
return orderEntryId;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -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();

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand All @@ -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;

Expand All @@ -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;

Expand All @@ -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);
Expand All @@ -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;

Expand All @@ -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
Expand Down

0 comments on commit c4c13f1

Please sign in to comment.