Search in sources :

Example 1 with NewOrderSingle

use of quickfix.fix42.NewOrderSingle in project camel by apache.

the class TradeExecutorExample method createNewOrderMessage.

private NewOrderSingle createNewOrderMessage() {
    NewOrderSingle order = new NewOrderSingle(new ClOrdID("CLIENT_ORDER_ID"), new HandlInst('1'), new Symbol("GOOG"), new Side(Side.BUY), new TransactTime(new Date()), new OrdType(OrdType.LIMIT));
    order.set(new OrderQty(10));
    order.set(new Price(300.00));
    return order;
}
Also used : NewOrderSingle(quickfix.fix42.NewOrderSingle) Side(quickfix.field.Side) OrderQty(quickfix.field.OrderQty) Price(quickfix.field.Price) Symbol(quickfix.field.Symbol) OrdType(quickfix.field.OrdType) ClOrdID(quickfix.field.ClOrdID) HandlInst(quickfix.field.HandlInst) TransactTime(quickfix.field.TransactTime) Date(java.util.Date)

Example 2 with NewOrderSingle

use of quickfix.fix42.NewOrderSingle in project camel by apache.

the class TradeExecutorExample method sendMessage.

public void sendMessage() throws Exception {
    DefaultCamelContext context = new DefaultCamelContext();
    context.addComponent("trade-executor", new TradeExecutorComponent());
    final CountDownLatch logonLatch = new CountDownLatch(2);
    final CountDownLatch executionReportLatch = new CountDownLatch(2);
    RouteBuilder routes = new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            // Release latch when session logon events are received
            from("quickfix:examples/inprocess.cfg").filter(header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.SessionLogon)).bean(new CountDownLatchDecrementer("logon", logonLatch));
            from("quickfix:examples/inprocess.cfg?sessionID=FIX.4.2:MARKET->TRADER").filter(header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.AppMessageReceived)).to("trade-executor:market");
            from("trade-executor:market").to("quickfix:examples/inprocess.cfg");
            // Logger app messages as JSON
            from("quickfix:examples/inprocess.cfg").filter(PredicateBuilder.or(header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.AppMessageReceived), header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.AppMessageSent))).bean(new QuickfixjMessageJsonPrinter());
            // Release latch when trader receives execution report
            from("quickfix:examples/inprocess.cfg?sessionID=FIX.4.2:TRADER->MARKET").filter(PredicateBuilder.and(header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.AppMessageReceived), header(QuickfixjEndpoint.MESSAGE_TYPE_KEY).isEqualTo(MsgType.EXECUTION_REPORT))).bean(new CountDownLatchDecrementer("execution report", executionReportLatch));
        }
    };
    context.addRoutes(routes);
    LOG.info("Starting Camel context");
    context.start();
    // synchronization due to app messages being sent before being logged on
    if (!logonLatch.await(5, TimeUnit.SECONDS)) {
        throw new IllegalStateException("Logon did not complete");
    }
    String gatewayUri = "quickfix:examples/inprocess.cfg?sessionID=FIX.4.2:TRADER->MARKET";
    Endpoint gatewayEndpoint = context.getEndpoint(gatewayUri);
    Producer producer = gatewayEndpoint.createProducer();
    LOG.info("Sending order");
    NewOrderSingle order = createNewOrderMessage();
    Exchange exchange = producer.createExchange(ExchangePattern.InOnly);
    exchange.getIn().setBody(order);
    producer.process(exchange);
    if (!executionReportLatch.await(5, TimeUnit.SECONDS)) {
        throw new IllegalStateException("Did not receive execution reports");
    }
    LOG.info("Message received, shutting down Camel context");
    context.stop();
    LOG.info("Order execution example complete");
}
Also used : QuickfixjMessageJsonPrinter(org.apache.camel.component.quickfixj.examples.transform.QuickfixjMessageJsonPrinter) NewOrderSingle(quickfix.fix42.NewOrderSingle) Exchange(org.apache.camel.Exchange) RouteBuilder(org.apache.camel.builder.RouteBuilder) Endpoint(org.apache.camel.Endpoint) QuickfixjEndpoint(org.apache.camel.component.quickfixj.QuickfixjEndpoint) Producer(org.apache.camel.Producer) CountDownLatch(java.util.concurrent.CountDownLatch) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CountDownLatchDecrementer(org.apache.camel.component.quickfixj.examples.util.CountDownLatchDecrementer)

Aggregations

NewOrderSingle (quickfix.fix42.NewOrderSingle)2 Date (java.util.Date)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Endpoint (org.apache.camel.Endpoint)1 Exchange (org.apache.camel.Exchange)1 Producer (org.apache.camel.Producer)1 RouteBuilder (org.apache.camel.builder.RouteBuilder)1 QuickfixjEndpoint (org.apache.camel.component.quickfixj.QuickfixjEndpoint)1 QuickfixjMessageJsonPrinter (org.apache.camel.component.quickfixj.examples.transform.QuickfixjMessageJsonPrinter)1 CountDownLatchDecrementer (org.apache.camel.component.quickfixj.examples.util.CountDownLatchDecrementer)1 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)1 ClOrdID (quickfix.field.ClOrdID)1 HandlInst (quickfix.field.HandlInst)1 OrdType (quickfix.field.OrdType)1 OrderQty (quickfix.field.OrderQty)1 Price (quickfix.field.Price)1 Side (quickfix.field.Side)1 Symbol (quickfix.field.Symbol)1 TransactTime (quickfix.field.TransactTime)1