private boolean isOrderExecutable(Message order, Price price) throws FieldNotFound { if (order.getChar(OrdType.FIELD) == OrdType.LIMIT) { BigDecimal limitPrice = new BigDecimal(order.getString(Price.FIELD)); char side = order.getChar(Side.FIELD); BigDecimal thePrice = new BigDecimal("" + price.getValue()); return (side == Side.BUY && thePrice.compareTo(limitPrice) <= 0) || ((side == Side.SELL || side == Side.SELL_SHORT) && thePrice.compareTo(limitPrice) >= 0); } return true; }
private OrderEntry convertToOrderEntry(NewOrderSingle orderSingle, String broker) throws FieldNotFound { OrderSide side = orderSingle.getSide().getValue() == Side.BUY ? OrderSide.Buy : OrderSide.Sell; OrderType orderType = null; switch (orderSingle.getOrdType().getValue()) { case OrdType.MARKET: orderType = new Market(); break; case OrdType.LIMIT: orderType = new Limit(orderSingle.getPrice().getValue()); break; } return new OrderEntry( side, broker, (int) orderSingle.getOrderQty().getValue(), orderType); }
@Override public void onMessage(ExecutionReport message, SessionID sessionId) throws FieldNotFound { log.info("[ExecutionReport] ClOrdID: {}, orderID: {}, {} {}@{}, avgPx: {}, cumQty: {}, ordStatus: {}", message.getClOrdID().getValue(), message.getOrderID().getValue(), message.getSide().getValue() == Side.BUY ? "buy" : "sell", message.isSetOrderQty() ? message.getOrderQty().getValue() : null, message.isSetPrice() ? message.getPrice().getValue() : null, message.isSetAvgPx() ? message.getAvgPx().getValue() : null, message.isSetCumQty() ? message.getCumQty().getValue() : null, message.isSetOrdStatus() ? message.getOrdStatus().getValue() : null); if (!TradeClient.this.oneOrderDemoed) { TradeClient.this.oneOrderDemoed = true; log.info("Requesting one order status..."); app.requestOrderStatus( message.getOrderID().getValue(), message.getSide().getValue(), "btccny", sessionId); } }
@Override public void onMessage(HuobiOrderInfoResponse message, SessionID sessionId) throws FieldNotFound, UnsupportedMessageType, IncorrectTagValue { log.info("[HuobiOrderInfoResponse] Symbol: {}, orderID: {}, side: {}, price: {}," + " ordStatus: {}, quantity: {}," + " processedPrice: {}, processedAmount: {}," + " vot: {}, fee: {}, total: {}", message.getSymbol().getValue(), message.getOrderID().getValue(), message.getSide(), message.getPrice().getValue(), message.getOrdStatus().getValue(), message.getQuantity().getValue(), message.getProcessedPrice().getValue(), message.getProcessedAmount().getValue(), message.getVot().getValue(), message.getFee().getValue(), message.getTotal().getValue()); }
public void onMessage(quickfix.fix40.NewOrderSingle order, SessionID sessionID) throws FieldNotFound, UnsupportedMessageType, IncorrectTagValue { try { validateOrder(order); OrderQty orderQty = order.getOrderQty(); Price price = getPrice(order); quickfix.fix40.ExecutionReport accept = new quickfix.fix40.ExecutionReport(genOrderID(), genExecID(), new ExecTransType(ExecTransType.NEW), new OrdStatus(OrdStatus.NEW), order.getSymbol(), order.getSide(), orderQty, new LastShares(0), new LastPx(0), new CumQty(0), new AvgPx(0)); accept.set(order.getClOrdID()); sendMessage(sessionID, accept); if (isOrderExecutable(order, price)) { quickfix.fix40.ExecutionReport fill = new quickfix.fix40.ExecutionReport(genOrderID(), genExecID(), new ExecTransType(ExecTransType.NEW), new OrdStatus(OrdStatus.FILLED), order.getSymbol(), order .getSide(), orderQty, new LastShares(orderQty.getValue()), new LastPx(price.getValue()), new CumQty(orderQty.getValue()), new AvgPx(price.getValue())); fill.set(order.getClOrdID()); sendMessage(sessionID, fill); } } catch (RuntimeException e) { LogUtil.logThrowable(sessionID, e.getMessage(), e); } }
public void onMessage(quickfix.fix50.NewOrderSingle order, SessionID sessionID) throws FieldNotFound, UnsupportedMessageType, IncorrectTagValue { try { validateOrder(order); OrderQty orderQty = order.getOrderQty(); Price price = getPrice(order); quickfix.fix50.ExecutionReport accept = new quickfix.fix50.ExecutionReport( genOrderID(), genExecID(), new ExecType(ExecType.FILL), new OrdStatus( OrdStatus.NEW), order.getSide(), new LeavesQty(order.getOrderQty() .getValue()), new CumQty(0)); accept.set(order.getClOrdID()); accept.set(order.getSymbol()); sendMessage(sessionID, accept); if (isOrderExecutable(order, price)) { quickfix.fix50.ExecutionReport executionReport = new quickfix.fix50.ExecutionReport( genOrderID(), genExecID(), new ExecType(ExecType.FILL), new OrdStatus( OrdStatus.FILLED), order.getSide(), new LeavesQty(0), new CumQty( orderQty.getValue())); executionReport.set(order.getClOrdID()); executionReport.set(order.getSymbol()); executionReport.set(orderQty); executionReport.set(new LastQty(orderQty.getValue())); executionReport.set(new LastPx(price.getValue())); executionReport.set(new AvgPx(price.getValue())); sendMessage(sessionID, executionReport); } } catch (RuntimeException e) { LogUtil.logThrowable(sessionID, e.getMessage(), e); } }
public void onMessage(quickfix.fix42.NewOrderSingle order, SessionID sessionID) throws FieldNotFound, UnsupportedMessageType, IncorrectTagValue { try { validateOrder(order); OrderQty orderQty = order.getOrderQty(); Price price = getPrice(order); quickfix.fix42.ExecutionReport accept = new quickfix.fix42.ExecutionReport(genOrderID(), genExecID(), new ExecTransType(ExecTransType.NEW), new ExecType(ExecType.FILL), new OrdStatus(OrdStatus.NEW), order .getSymbol(), order.getSide(), new LeavesQty(0), new CumQty(0), new AvgPx(0)); accept.set(order.getClOrdID()); sendMessage(sessionID, accept); if (isOrderExecutable(order, price)) { quickfix.fix42.ExecutionReport executionReport = new quickfix.fix42.ExecutionReport(genOrderID(), genExecID(), new ExecTransType(ExecTransType.NEW), new ExecType(ExecType.FILL), new OrdStatus( OrdStatus.FILLED), order.getSymbol(), order.getSide(), new LeavesQty(0), new CumQty( orderQty.getValue()), new AvgPx(price.getValue())); executionReport.set(order.getClOrdID()); executionReport.set(orderQty); executionReport.set(new LastShares(orderQty.getValue())); executionReport.set(new LastPx(price.getValue())); sendMessage(sessionID, executionReport); } } catch (RuntimeException e) { LogUtil.logThrowable(sessionID, e.getMessage(), e); } }
public void onMessage(quickfix.fix44.NewOrderSingle order, SessionID sessionID) throws FieldNotFound, UnsupportedMessageType, IncorrectTagValue { try { validateOrder(order); OrderQty orderQty = order.getOrderQty(); Price price = getPrice(order); quickfix.fix44.ExecutionReport accept = new quickfix.fix44.ExecutionReport( genOrderID(), genExecID(), new ExecType(ExecType.FILL), new OrdStatus( OrdStatus.NEW), order.getSide(), new LeavesQty(order.getOrderQty() .getValue()), new CumQty(0), new AvgPx(0)); accept.set(order.getClOrdID()); accept.set(order.getSymbol()); sendMessage(sessionID, accept); if (isOrderExecutable(order, price)) { quickfix.fix44.ExecutionReport executionReport = new quickfix.fix44.ExecutionReport(genOrderID(), genExecID(), new ExecType(ExecType.FILL), new OrdStatus(OrdStatus.FILLED), order.getSide(), new LeavesQty(0), new CumQty(orderQty.getValue()), new AvgPx(price.getValue())); executionReport.set(order.getClOrdID()); executionReport.set(order.getSymbol()); executionReport.set(orderQty); executionReport.set(new LastQty(orderQty.getValue())); executionReport.set(new LastPx(price.getValue())); sendMessage(sessionID, executionReport); } } catch (RuntimeException e) { LogUtil.logThrowable(sessionID, e.getMessage(), e); } }
public void onMessage(quickfix.fix43.NewOrderSingle order, SessionID sessionID) throws FieldNotFound, UnsupportedMessageType, IncorrectTagValue { try { validateOrder(order); OrderQty orderQty = order.getOrderQty(); Price price = getPrice(order); quickfix.fix43.ExecutionReport accept = new quickfix.fix43.ExecutionReport( genOrderID(), genExecID(), new ExecType(ExecType.FILL), new OrdStatus( OrdStatus.NEW), order.getSide(), new LeavesQty(order.getOrderQty() .getValue()), new CumQty(0), new AvgPx(0)); accept.set(order.getClOrdID()); accept.set(order.getSymbol()); sendMessage(sessionID, accept); if (isOrderExecutable(order, price)) { quickfix.fix43.ExecutionReport executionReport = new quickfix.fix43.ExecutionReport(genOrderID(), genExecID(), new ExecType(ExecType.FILL), new OrdStatus(OrdStatus.FILLED), order.getSide(), new LeavesQty(0), new CumQty(orderQty.getValue()), new AvgPx(price.getValue())); executionReport.set(order.getClOrdID()); executionReport.set(order.getSymbol()); executionReport.set(orderQty); executionReport.set(new LastQty(orderQty.getValue())); executionReport.set(new LastPx(price.getValue())); sendMessage(sessionID, executionReport); } } catch (RuntimeException e) { LogUtil.logThrowable(sessionID, e.getMessage(), e); } }
public void onMessage(quickfix.fix41.NewOrderSingle order, SessionID sessionID) throws FieldNotFound, UnsupportedMessageType, IncorrectTagValue { try { validateOrder(order); OrderQty orderQty = order.getOrderQty(); Price price = getPrice(order); quickfix.fix41.ExecutionReport accept = new quickfix.fix41.ExecutionReport(genOrderID(), genExecID(), new ExecTransType(ExecTransType.NEW), new ExecType(ExecType.FILL), new OrdStatus(OrdStatus.NEW), order .getSymbol(), order.getSide(), orderQty, new LastShares(0), new LastPx(0), new LeavesQty(0), new CumQty(0), new AvgPx(0)); accept.set(order.getClOrdID()); sendMessage(sessionID, accept); if (isOrderExecutable(order, price)) { quickfix.fix41.ExecutionReport executionReport = new quickfix.fix41.ExecutionReport(genOrderID(), genExecID(), new ExecTransType(ExecTransType.NEW), new ExecType(ExecType.FILL), new OrdStatus( OrdStatus.FILLED), order.getSymbol(), order.getSide(), orderQty, new LastShares(orderQty .getValue()), new LastPx(price.getValue()), new LeavesQty(0), new CumQty(orderQty .getValue()), new AvgPx(price.getValue())); executionReport.set(order.getClOrdID()); sendMessage(sessionID, executionReport); } } catch (RuntimeException e) { LogUtil.logThrowable(sessionID, e.getMessage(), e); } }