CME iLink 3 Handler that connects to the the Order Entry Service Gateway. When the session is established, the ‘PartyDetailsDefinitionRequest’(MsgType=‘CX’) SBE message is sent to the counterparty.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | import biz.onixs.cme.ilink3.handler.ApplicationLayerMsgType; import biz.onixs.cme.ilink3.handler.CME; import biz.onixs.cme.ilink3.handler.Handler; import biz.onixs.cme.ilink3.handler.Session; import biz.onixs.cme.ilink3.handler.SessionState; import biz.onixs.cme.ilink3.handler.Tag; import biz.onixs.cme.ilink3.handler.session.*; import biz.onixs.sbe.ByteDecoder; import biz.onixs.sbe.IGroup; import biz.onixs.sbe.IMessage; import biz.onixs.util.Utils; import biz.onixs.util.settings.PropertyBasedSettings; import biz.onixs.util.settings.Settings; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.Arrays; /** * Order Entry Service Gateway sample. */ public class OrderEntryServiceGateway implements InboundSessionMessageListener, InboundApplicationMessageListener, OutboundSessionMessageListener, OutboundApplicationMessageListener, StateChangeListener, WarningListener, ErrorListener, Runnable { private static final Logger LOG = LoggerFactory.getLogger(OrderEntryServiceGateway. class ); private static final String SETTINGS_RESOURCE = "sample/OrderEntryServiceGateway.properties" ; private final int marketSegmentId; private final String host; private final int port; private final long partyDetailsListReqId; private Session session = null ; private Settings settings = null ; public OrderEntryServiceGateway( final int marketSegmentId, final String host, final int port, final long partyDetailsListReqId) { this .marketSegmentId = marketSegmentId; this .host = host; this .port = port; this .partyDetailsListReqId = partyDetailsListReqId; } public void run() { try { LOG.info( "Order Entry Service Gateway Sample" ); LOG.info( "The application is starting..." ); // LOG.info( "Loading settings from: {}" , SETTINGS_RESOURCE); settings = new PropertyBasedSettings(SETTINGS_RESOURCE); // LOG.info( "Starting the Handler..." ); final Handler handler = Handler.init(settings); // createSession(); // establishConnection(); // Utils.waitForEnter( "\nPress \"Enter\" to send the PartyDetailsDefinitionRequest message.\n" ); // final IMessage request = createPartyDetailsDefinitionRequest(session.getDecoder()); session.send(request); LOG.info( "The PartyDetailsDefinitionRequest message was sent." ); // Utils.waitForEnter( "\nPress \"Enter\" to disconnect the session and terminate the application.\n" ); session.terminate(); // LOG.info( "Handler shutdown..." ); handler.shutdown(); } catch ( final RuntimeException e) { LOG.error(e.getMessage(), e); } finally { LOG.info( "The application is stopped." ); } } private void createSession() { final SessionSettings sessionSettings = new SessionSettings(); sessionSettings.init(settings); session = new Session(sessionSettings, marketSegmentId); session.setOutboundApplicationMessageListener( this ); session.setInboundApplicationMessageListener( this ); } private void establishConnection() { LOG.info( "Establishing connection to {}:{} ..." , host, port); session.logon(host, port); } public IMessage createPartyDetailsDefinitionRequest( final ByteDecoder decoder) { final byte [] buffer = new byte [ 1024 ]; Arrays.fill(buffer, ( byte ) 0 ); final IMessage message = decoder.encode(buffer, 0 , buffer.length, ApplicationLayerMsgType.PartyDetailsDefinitionRequestId); message.setLong(Tag.PartyDetailsListReqID, partyDetailsListReqId); message.setInt(Tag.ListUpdateAction, CME.ListUpdAct.Add); message.setInt(Tag.CustOrderCapacity, CME.CustOrderCapacity.Allother); message.setInt(Tag.ClearingAccountType, CME.ClearingAcctType.Firm); message.setInt(Tag.CustOrderHandlingInst, CME.CustOrdHandlInst.AlgoEngine); message.setLong(Tag.Executor, 1L); message.setInt(Tag.CmtaGiveupCD, CME.CmtaGiveUpCD.GiveUp); message.reset(Tag.SelfMatchPreventionID); message.setLong(Tag.IDMShortCode, 0L); final int PartyDetailsGroupSize = 3 ; final IGroup partyDetails = message.getGroup(Tag.NoPartyDetails); partyDetails.setLength(PartyDetailsGroupSize); partyDetails.next(); partyDetails.setString(Tag.PartyDetailID, "004" ); partyDetails.setInt(Tag.PartyDetailRole, CME.PartyDetailRole.ExecutingFirm); partyDetails.next(); partyDetails.setString(Tag.PartyDetailID, "MST" ); partyDetails.setInt(Tag.PartyDetailRole, CME.PartyDetailRole.CustomerAccount); partyDetails.next(); partyDetails.setString(Tag.PartyDetailID, "004" ); partyDetails.setInt(Tag.PartyDetailRole, CME.PartyDetailRole.Operator); return message; } @Override public void onInboundSessionMessage( final Object sender, final InboundSessionMessageArgs args) { final IMessage message = args.getMsg(); LOG.info( "Incoming session-level message: {}" , message); // Processing of the incoming session-level message... } @Override public void onInboundApplicationMessage( final Object sender, final InboundApplicationMessageArgs args) { final IMessage message = args.getMsg(); LOG.info( "Incoming application-level message: {}" , message); // Processing of the incoming application-level message... } @Override public void onOutboundSessionMessage( final Object sender, final OutboundSessionMessageArgs args) { final IMessage message = args.getMsg(); LOG.info( "Outgoing session-level message: {}" , message); } @Override public void onOutboundApplicationMessage( final Object sender, final OutboundApplicationMessageArgs args) { final IMessage message = args.getMsg(); LOG.info( "Outgoing application-level message: {}" , message); } @Override public void onStateChange( final Object sender, final StateChangeArgs args) { final SessionState newState = args.getNewState(); final SessionState prevState = args.getPrevState(); LOG.info( "Session state changed from {} to {}" , prevState, newState); } @Override public void onWarning( final Object sender, final WarningArgs args) { LOG.warn( "{}" , args); } @Override public void onError( final Object sender, final ErrorArgs args) { LOG.error( "{}" , args); } public static void main( final String[] args) { if ( 4 > args.length) { LOG.error( "Usage: [MarketSegmentId] [Host] [Port] [PartyDetailsListReqId]" ); } else { final int marketSegmentId = Integer.parseInt(args[ 0 ]); final String host = args[ 1 ]; final int port = Integer.parseInt(args[ 2 ]); final long partyDetailsListReqId = Long.parseLong(args[ 3 ]); final OrderEntryServiceGateway messageQueue = new OrderEntryServiceGateway(marketSegmentId, host, port, partyDetailsListReqId); messageQueue.run(); } } } |