11package com .alignmentsystems .matching ;
22
3+ import java .nio .ByteBuffer ;
4+
35/******************************************************************************
46 *
57 * Author : John Greenan
1315
1416import java .util .UUID ;
1517
18+ import org .apache .kafka .clients .consumer .ConsumerRecord ;
19+
20+ import com .alignmentsystems .fix44 .ExecutionReport ;
21+ import com .alignmentsystems .fix44 .field .AvgPx ;
22+ import com .alignmentsystems .fix44 .field .ClOrdID ;
23+ import com .alignmentsystems .fix44 .field .CumQty ;
24+ import com .alignmentsystems .fix44 .field .ExecID ;
25+ import com .alignmentsystems .fix44 .field .ExecType ;
26+ import com .alignmentsystems .fix44 .field .LeavesQty ;
27+ import com .alignmentsystems .fix44 .field .OrdStatus ;
28+ import com .alignmentsystems .fix44 .field .OrderID ;
29+ import com .alignmentsystems .fix44 .field .Side ;
1630import com .alignmentsystems .library .AlignmentOrder ;
1731import com .alignmentsystems .library .LibraryOrders ;
1832import com .alignmentsystems .library .LogEncapsulation ;
1933import com .alignmentsystems .library .constants .Constants ;
34+ import com .alignmentsystems .library .enumerations .Encodings ;
2035import com .alignmentsystems .library .enumerations .InstanceType ;
2136import com .alignmentsystems .library .enumerations .MessageDirection ;
37+ import com .alignmentsystems .library .enumerations .OperationEventType ;
2238import com .alignmentsystems .library .enumerations .OrderBookSide ;
39+ import com .alignmentsystems .library .interfaces .InterfaceMatch ;
2340import com .alignmentsystems .library .interfaces .InterfaceQueueNonSequenced ;
2441
2542import quickfix .DoNotSend ;
2946import quickfix .Message ;
3047import quickfix .MessageCracker ;
3148import quickfix .RejectLogon ;
49+ import quickfix .Session ;
3250import quickfix .SessionID ;
51+ import quickfix .SessionNotFound ;
3352import quickfix .UnsupportedMessageType ;
3453
3554/**
3655 * @author <a href="mailto:sales@alignment-systems.com">John Greenan</a>
3756 *
3857 */
39- public class FIXEngineExchange extends MessageCracker implements quickfix .Application {
58+ public class FIXEngineExchange extends MessageCracker implements quickfix .Application , KafkaMessageHandler {
59+ protected final static String CLASSNAME = FIXEngineExchange .class .getSimpleName ();
4060 private InterfaceQueueNonSequenced queueNonSequenced = null ;
61+ private final static Encodings encoding = Encodings .FIXSBELITTLEENDIAN ;
4162 private LogEncapsulation log = null ;
42- private final static String CLASSNAME = FIXEngineExchange .class .getSimpleName ();
4363 private InstanceType instanceType = null ;
4464
65+
66+
67+
68+
69+
4570 public FIXEngineExchange (LogEncapsulation log , InterfaceQueueNonSequenced queueNonSequenced ,
4671 InstanceType instanceType ) {
4772 this .log = log ;
@@ -276,4 +301,109 @@ public void onMessage(com.alignmentsystems.fix44.ExecutionReport message, Sessio
276301
277302 }
278303
304+ @ Override
305+ public void processMessage (String topicName , ConsumerRecord <String , byte []> message ) throws Exception {
306+ // TODO Auto-generated method stub
307+ //Here we receive a Kafka Message...
308+
309+ log .info (CLASSNAME + " received " + topicName );
310+ //topicName
311+
312+
313+ ByteBuffer bb = ByteBuffer .wrap (message .value ()).order (encoding .getByteOrder ());
314+ final short msgType = bb .getShort (); // buf.putShort(messageType);
315+ //When we get to here we know the message type that was used
316+
317+
318+
319+ }
320+
321+ private void sendExecutionReportsForMatch (InterfaceMatch match ) {
322+ final String methodName ="matchHappened" ;
323+
324+ log .infoMatchingEvent (OperationEventType .MATCHEVENT , match );
325+ Long executionQuantity = match .getMatchQuantity ();
326+
327+
328+ OrderID b_orderId = new OrderID (match .getBuyOrderId ().toString ());
329+ ClOrdID b_ClOrdId = new ClOrdID (match .getBuyClOrdId ().toString ());
330+ ExecID b_execID = new ExecID (UUID .randomUUID ().toString ());
331+ CumQty b_cumQty = new CumQty (match .getMatchQuantity ());
332+ AvgPx b_avgPx = new AvgPx (match .getMatchPrice ());
333+ Side b_side = new Side (Side .BUY );
334+
335+ ExecType b_execType = null ;
336+ OrdStatus b_ordStatus = null ;
337+ Long b_orderQty = match .getBuyOrderQty ();
338+ LeavesQty b_leavesQty = new LeavesQty ( match .getBuyOrderQty ()-match .getBuyCumQty ());
339+
340+ //int java.lang.Double.compareTo(Double anotherDouble)
341+ //the value 0 if anotherDouble is numerically equal to this Double;
342+ //a value less than 0 if this Double is numerically less than anotherDouble;
343+ //and a value greater than 0 if this Double is numerically greater than anotherDouble.
344+ //Therefore, if this is equal to zero then the execution quantity is equal to the order quantity
345+
346+ if (executionQuantity .compareTo (b_orderQty )==0 ) {
347+ b_execType = new ExecType (ExecType .FILL );
348+ b_ordStatus = new OrdStatus (OrdStatus .FILLED );
349+ }
350+
351+ ExecutionReport buyExecRpt = new ExecutionReport (
352+ b_orderId
353+ , b_execID
354+ , b_execType
355+ , b_ordStatus
356+ , b_side
357+ , b_leavesQty
358+ , b_cumQty
359+ , b_avgPx )
360+ ;
361+ buyExecRpt .set (b_ClOrdId );
362+
363+
364+
365+ //TODO - clean up the above
366+ //Repeat the same code with s_ instead of b_
367+ OrderID s_orderId = new OrderID (match .getSellOrderId ().toString ());
368+ ClOrdID s_ClOrdId = new ClOrdID (match .getBuyClOrdId ().toString ());
369+ ExecID s_execID = new ExecID (UUID .randomUUID ().toString ());
370+ CumQty s_cumQty = new CumQty (match .getMatchQuantity ());
371+ AvgPx s_avgPx = new AvgPx (match .getMatchPrice ());
372+ Side s_side = new Side (Side .SELL );
373+
374+ ExecType s_execType = null ;
375+ OrdStatus s_ordStatus = null ;
376+ Long s_orderQty = match .getSellOrderQty ();
377+ LeavesQty s_leavesQty = new LeavesQty (match .getSellOrderQty () - match .getSellCumQty () );
378+
379+ //int java.lang.Double.compareTo(Double anotherDouble)
380+ //the value 0 if anotherDouble is numerically equal to this Double;
381+ //a value less than 0 if this Double is numerically less than anotherDouble;
382+ //and a value greater than 0 if this Double is numerically greater than anotherDouble.
383+ //Therefore, if this is equal to zero then the execution quantity is equal to the order quantity
384+
385+ if (executionQuantity == s_orderQty ) {
386+ s_execType = new ExecType (ExecType .FILL );
387+ s_ordStatus = new OrdStatus (OrdStatus .FILLED );
388+ }
389+
390+ ExecutionReport sellExecRpt = new ExecutionReport (
391+ s_orderId
392+ , s_execID
393+ , s_execType
394+ , s_ordStatus
395+ , s_side
396+ , s_leavesQty
397+ , s_cumQty
398+ , s_avgPx )
399+ ;
400+ buyExecRpt .set (s_ClOrdId );
401+
402+ try {
403+ Session .sendToTarget (sellExecRpt , match .getSellSenderId (), match .getSellTargetId ());
404+ Session .sendToTarget (buyExecRpt , match .getBuySenderId () , match .getBuyTargetId ());
405+ } catch (SessionNotFound e ) {
406+ log .error (e .getMessage (), e );
407+ };
408+ }
279409}
0 commit comments