Search in sources :

Example 1 with NewOrderSingle

use of quickfix.fix41.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.fix41.NewOrderSingle in project wso2-synapse by wso2.

the class FIXOutgoingMessageHandlerTest method testSendMessage.

@Test
public void testSendMessage() throws Exception {
    int SEQ_NUM = 1;
    String SESSION_ID = "FIX.4.1:BANZAI->SYNAPSE";
    Message message = new NewOrderSingle();
    MessageContext msgCtx = new MessageContext();
    PowerMockito.when(sessionFactory.getApplication(anyString())).thenReturn(app);
    PowerMockito.mockStatic(Session.class);
    PowerMockito.when(Session.sendToTarget(any(Message.class), any(SessionID.class))).thenReturn(true);
    SessionID id = new SessionID(new BeginString("FIX.4.1"), new SenderCompID("SYNAPSE"), new TargetCompID("BANZAI"), "FIX.4.1:SYNAPSE->BANZAI");
    spy.sendMessage(message, id, SESSION_ID, SEQ_NUM, msgCtx, "fix://sample");
    PowerMockito.verifyStatic(times(1));
}
Also used : NewOrderSingle(quickfix.fix41.NewOrderSingle) BeginString(quickfix.field.BeginString) SenderCompID(quickfix.field.SenderCompID) Message(quickfix.Message) TargetCompID(quickfix.field.TargetCompID) BeginString(quickfix.field.BeginString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MessageContext(org.apache.axis2.context.MessageContext) SessionID(quickfix.SessionID) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with NewOrderSingle

use of quickfix.fix41.NewOrderSingle in project wso2-synapse by wso2.

the class MessageTest method testSimpleFIXMessage.

public void testSimpleFIXMessage() throws Exception {
    Message message = new NewOrderSingle();
    message.getHeader().setField(new BeginString(BEGIN_STRING));
    message.getHeader().setField(new SenderCompID(SENDER_ID));
    message.getHeader().setField(new TargetCompID(TARGET_ID));
    message.getHeader().setField(new MsgSeqNum(SEQ_NUM));
    message.setField(new Symbol(SYMBOL));
    message.setField(new ClOrdID(CLORD_ID));
    message.setField(new TradeOriginationDate(TX_DATE));
    message.getTrailer().setField(new CheckSum(CHECKSUM));
    MessageContext msgCtx = new MessageContext();
    FIXUtils.getInstance().setSOAPEnvelope(message, SEQ_NUM, SESSION_ID, msgCtx);
    String result = msgCtx.getEnvelope().getBody().getFirstElement().toString();
    String expected = "<message inSession=\"" + SESSION_ID + "\" counter=\"" + SEQ_NUM + "\">" + "<header>" + "<field id=\"" + BeginString.FIELD + "\">" + BEGIN_STRING + "</field>" + "<field id=\"" + MsgSeqNum.FIELD + "\">" + SEQ_NUM + "</field>" + "<field id=\"" + MsgType.FIELD + "\">" + NewOrderSingle.MSGTYPE + "</field>" + "<field id=\"" + SenderCompID.FIELD + "\">" + SENDER_ID + "</field>" + "<field id=\"" + TargetCompID.FIELD + "\">" + TARGET_ID + "</field>" + "</header>" + "<body>" + "<field id=\"" + ClOrdID.FIELD + "\">" + CLORD_ID + "</field>" + "<field id=\"" + Symbol.FIELD + "\">" + SYMBOL + "</field>" + "<field id=\"" + TradeOriginationDate.FIELD + "\">" + TX_DATE + "</field>" + "</body>" + "<trailer>" + "<field id=\"" + CheckSum.FIELD + "\">" + CHECKSUM + "</field>" + "</trailer>" + "</message>";
    assertXMLEqual(expected, AXIOMUtil.stringToOM(result).toString());
}
Also used : NewOrderSingle(quickfix.fix41.NewOrderSingle) Message(quickfix.Message) MessageContext(org.apache.axis2.context.MessageContext)

Example 4 with NewOrderSingle

use of quickfix.fix41.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)

Example 5 with NewOrderSingle

use of quickfix.fix41.NewOrderSingle in project wso2-synapse by wso2.

the class FIXTransportSenderTest method testFIXTransportSenderSendMessage.

@Test()
public void testFIXTransportSenderSendMessage() throws Exception {
    String BEGIN_STRING = "FIX.4.1";
    String SENDER_ID = "BANZAI";
    String TARGET_ID = "SYNAPSE";
    int SEQ_NUM = 5;
    String SYMBOL = "APACHE";
    String CLORD_ID = "12345";
    String CHECKSUM = "67890";
    String TX_DATE = new Date().toString();
    String SESSION_ID = "FIX.4.1:BANZAI->SYNAPSE";
    Message message = new NewOrderSingle();
    message.getHeader().setField(new BeginString(BEGIN_STRING));
    message.getHeader().setField(new SenderCompID(SENDER_ID));
    message.getHeader().setField(new TargetCompID(TARGET_ID));
    message.getHeader().setField(new MsgSeqNum(SEQ_NUM));
    message.setField(new Symbol(SYMBOL));
    message.setField(new ClOrdID(CLORD_ID));
    message.setField(new TradeOriginationDate(TX_DATE));
    message.getTrailer().setField(new CheckSum(CHECKSUM));
    MessageContext msgCtx = new MessageContext();
    msgCtx.setProperty(FIXConstants.FIX_SERVICE_NAME, "sampleService");
    Map trpHeaders = new HashMap();
    trpHeaders.put(FIXConstants.FIX_MESSAGE_APPLICATION, "sampleApplication");
    msgCtx.setProperty(MessageContext.TRANSPORT_HEADERS, trpHeaders);
    FIXUtils.getInstance().setSOAPEnvelope(message, SEQ_NUM, SESSION_ID, msgCtx);
    OutTransportInfo info = new FIXOutTransportInfo("fix://dummyEPR");
    FIXTransportSender spy = PowerMockito.spy(new FIXTransportSender());
    PowerMockito.doReturn(true).when(spy, "sendUsingEPR", anyString(), anyString(), any(), anyString(), anyInt(), any());
    spy.sendMessage(msgCtx, "fix://dummyEPR", info);
    PowerMockito.verifyPrivate(spy, times(1)).invoke("sendUsingEPR", anyString(), anyString(), any(), anyString(), anyInt(), any());
}
Also used : NewOrderSingle(quickfix.fix41.NewOrderSingle) BeginString(quickfix.field.BeginString) SenderCompID(quickfix.field.SenderCompID) Message(quickfix.Message) HashMap(java.util.HashMap) Symbol(quickfix.field.Symbol) TargetCompID(quickfix.field.TargetCompID) ClOrdID(quickfix.field.ClOrdID) TradeOriginationDate(quickfix.field.TradeOriginationDate) BeginString(quickfix.field.BeginString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MsgSeqNum(quickfix.field.MsgSeqNum) Date(java.util.Date) TradeOriginationDate(quickfix.field.TradeOriginationDate) OutTransportInfo(org.apache.axis2.transport.OutTransportInfo) CheckSum(quickfix.field.CheckSum) MessageContext(org.apache.axis2.context.MessageContext) HashMap(java.util.HashMap) Map(java.util.Map) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

Message (quickfix.Message)7 NewOrderSingle (quickfix.fix41.NewOrderSingle)7 Test (org.junit.Test)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 BeginString (quickfix.field.BeginString)5 SenderCompID (quickfix.field.SenderCompID)5 TargetCompID (quickfix.field.TargetCompID)5 MessageContext (org.apache.axis2.context.MessageContext)4 SessionID (quickfix.SessionID)4 MsgSeqNum (quickfix.field.MsgSeqNum)4 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)3 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)3 NativeWorkerPool (org.apache.axis2.transport.base.threads.NativeWorkerPool)3 WorkerPool (org.apache.axis2.transport.base.threads.WorkerPool)3 MsgType (quickfix.field.MsgType)3 Date (java.util.Date)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 ClOrdID (quickfix.field.ClOrdID)2 Symbol (quickfix.field.Symbol)2 NewOrderSingle (quickfix.fix42.NewOrderSingle)2