Skip to content

Instantly share code, notes, and snippets.

@ricston-git
Last active December 12, 2015 04:19
Show Gist options
  • Save ricston-git/4713692 to your computer and use it in GitHub Desktop.
Save ricston-git/4713692 to your computer and use it in GitHub Desktop.
public Object createNewOrder(Object payload) {
quickfix.fix41.NewOrderSingle newOrder = new quickfix.fix41.NewOrderSingle(
new ClOrdID(Long.valueOf(System.currentTimeMillis()+(nextOrder++)).toString()), new HandlInst('1'), new Symbol("LNX"), new Side(Side.BUY), new OrdType(OrdType.MARKET));
newOrder.set(new OrderQty(1));
return newOrder;
}
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:vm="http://www.mulesoft.org/schema/mule/vm"
xmlns:fix="http://www.mulesource.org/schema/mule/fix/3.3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.3/mule.xsd
http://www.mulesource.org/schema/mule/fix/3.3 http://www.mulesource.org/schema/mule/fix/3.3/mule-fix.xsd
http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/3.3/mule-vm.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/3.3/mule-http.xsd">
<fix:connector name="serverConnector" config="./examples/src/test/resources/blog/server.cfg"/>
<fix:endpoint name="serverEndpoint" connector-ref="serverConnector" sessionID="FIX.4.1:SERVER-CLIENT" />
<fix:connector name="clientConnector" config="./examples/src/test/resources/blog/client.cfg"/>
<fix:endpoint name="clientEndpoint" connector-ref="clientConnector" sessionID="FIX.4.1:CLIENT-SERVER" />
<flow name="client_invoke">
<http:inbound-endpoint exchange-pattern="one-way" host="localhost" port="5552" />
<component class="org.mule.transport.fix.examples.blog.NewOrderComponent" />
<fix:outbound-endpoint ref="clientEndpoint" />
</flow>
<flow name="server_flow">
<fix:inbound-endpoint ref="serverEndpoint" />
<component class="org.mule.transport.fix.examples.mock.Executor">
<binding interface="org.mule.transport.fix.examples.mock.FixDispatcherInterface">
<fix:outbound-endpoint ref="serverEndpoint" />
</binding>
</component>
<logger level="ERROR" message="Received message from client" />
</flow>
</mule>
public void processMessage(quickfix.fix41.NewOrderSingle order)
throws FieldNotFound, UnsupportedMessageType, IncorrectTagValue {
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());
dispatcher.dispatch(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());
dispatcher.dispatch(executionReport);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment