Class FIXEngineB2B

java.lang.Object
com.btobits.fixengine.FIXEngineB2B
All Implemented Interfaces:
FIXEngine

public class FIXEngineB2B extends Object implements FIXEngine
Implementation of interface FIXEngine.
  • Field Details

  • Constructor Details

    • FIXEngineB2B

      public FIXEngineB2B(String configFileName, boolean showMonitor) throws FIXEngineInitException
      Creates and starts a FIX Engine instance.
      Parameters:
      configFileName - the name of configuration file.
      showMonitor - the flag to show or not sessions browser.
      Throws:
      FIXEngineInitException - if the FIX Engine cannot be created or started.
    • FIXEngineB2B

      public FIXEngineB2B(Properties config, boolean showMonitor) throws FIXEngineInitException
      Creates and starts a FIX Engine instance.
      Parameters:
      config - the configuration properties.
      showMonitor - the flag to show or not sessions browser.
      Throws:
      FIXEngineInitException - if the FIX Engine cannot be created or started.
    • FIXEngineB2B

      public FIXEngineB2B(Application application, String configFileName, boolean showMonitor) throws FIXEngineInitException
      Creates and starts a FIX Engine instance.
      Parameters:
      application - the application implementation.
      configFileName - the name of configuration file.
      showMonitor - the flag to show or not sessions browser.
      Throws:
      FIXEngineInitException - if the FIX Engine cannot be created or started.
    • FIXEngineB2B

      public FIXEngineB2B(Application application, Properties config, boolean showMonitor) throws FIXEngineInitException
      Creates and starts a FIX Engine instance.
      Parameters:
      application - the application implementation.
      config - the configuration properties.
      showMonitor - the flag to show or not sessions browser.
      Throws:
      FIXEngineInitException - if the FIX Engine cannot be created or started.
    • FIXEngineB2B

      public FIXEngineB2B(Application application, Properties config, boolean showMonitor, String homePath) throws FIXEngineInitException
      Creates and starts a FIX Engine instance.
      Parameters:
      application - the application implementation.
      config - the configuration properties.
      showMonitor - the flag to show or not sessions browser.
      homePath - the absolute path to the FIXAJ installation directory or the relative path to the same directory from the launching directory.
      Throws:
      FIXEngineInitException
  • Method Details

    • closeEngine

      public void closeEngine() throws Exception
      Closes engine.
      Specified by:
      closeEngine in interface FIXEngine
      Throws:
      Exception - if the FIX Engine cannot be properly closed.
    • closeEngineSession

      public void closeEngineSession(String sessionID) throws SessionNotFoundException
      Closes session with specifed ID.
      Specified by:
      closeEngineSession in interface FIXEngine
      Parameters:
      sessionID - closing session ID
      Throws:
      SessionNotFoundException - if the session cannot be found or properly closed.
    • closeEngineSession

      public void closeEngineSession(String sessionID, String reason) throws SessionNotFoundException
      Closes session with specifed ID.
      Specified by:
      closeEngineSession in interface FIXEngine
      Parameters:
      reason - the reason string that will be sent as text field value (tag=58) of logout message.
      Throws:
      SessionNotFoundException - if the session cannot be found or properly closed.
    • connectToRemoteFIXEngine

      public String connectToRemoteFIXEngine(String connectionString) throws EngineNotFoundException
      Establishes connection with remote FIX Engine.

      Connection string must be formatted in the following way:
      < protocol > < subprotocol > :// < host > : < port >
      < protocol > ::= fix42
      < subprotocol > ::= tcp

      Specified by:
      connectToRemoteFIXEngine in interface FIXEngine
      Parameters:
      connectionString - the connection string.
      Returns:
      ID of created session.
      Throws:
      EngineNotFoundException - if connection cannot be created or logon respose is not received in pre-configured timeout interval.
    • connectToRemoteFIXEngine

      public String connectToRemoteFIXEngine(String connectionString, int heartBtInt, String senderCompID, String targetCompID, int encryptionType) throws EngineNotFoundException
      Establishes connection with remote FIX Engine. Connection string must be formatted in the following way:
      < protocol > < subprotocol > :// < host > : < port >
      < protocol > ::= fix42
      < subprotocol > ::= tcp
      Specified by:
      connectToRemoteFIXEngine in interface FIXEngine
      Parameters:
      heartBtInt - the value of Heartbeat interval in seconds, which will be placed in InitialProcess message
      senderCompID - the SenderCompID, which will be placed in messages headers
      targetCompID - the TargetCompID, which will be placed in messages headers
      encryptionType - the type of encryption.
      Returns:
      ID of created session
      Throws:
      EngineNotFoundException - if connection cannot be created or logon response is not received in pre-configured timeout interval.
    • connectToRemoteFIXEngine

      public String connectToRemoteFIXEngine(String connectionString, int heartBtInt, String senderCompID, String targetCompID, int encryptionType, int startFromSeqNum) throws EngineNotFoundException
      Establishes connection with remote FIX Engine. Connection string must be formatted in the following way:
      < protocol > < subprotocol > :// < host > : < port >
      < protocol > ::= fix42
      < subprotocol > ::= tcp
      Specified by:
      connectToRemoteFIXEngine in interface FIXEngine
      Parameters:
      heartBtInt - Value of Heartbeat interval in seconds, which will be placed in InitialProcess message
      senderCompID - the SenderCompID, which will be placed in messages headers
      targetCompID - the TargetCompID, which will be placed in messages headers
      encryptionType - the type of encryption.
      startFromSeqNum - the starting outgoing sequence number.
      Returns:
      ID of created session
      Throws:
      EngineNotFoundException - if connection cannot be created or logon response is not received in pre-configured timeout interval.
    • connectToRemoteFIXEngine

      public String connectToRemoteFIXEngine(String connectionString, int heartBtInt, String senderCompID, String targetCompID, int encryptionMode, int outgoingSeqNum, int incomingSeqNum) throws EngineNotFoundException
      Throws:
      EngineNotFoundException
    • connectToRemoteFIXEngine

      public String connectToRemoteFIXEngine(String connectionString, StdHdrParamStruct stdHdrParamStruct, LogonParamStruct logonParamStruct, int outgoingSeqNum) throws EngineNotFoundException
      Establishes connection with remote FIX Engine.
      Specified by:
      connectToRemoteFIXEngine in interface FIXEngine
      Parameters:
      stdHdrParamStruct - structure, which contains Standard Message Header parameters
      logonParamStruct - structure, which contains InitialProcess Message parameters
      Returns:
      ID of created session
      Throws:
      EngineNotFoundException - if connection cannot be created or logon response is not received in pre-configured timeout interval.
    • connectToRemoteFIXEngine

      public String connectToRemoteFIXEngine(String connectionString, StdHdrParamStruct stdHdrParamStruct, LogonParamStruct logonParamStruct, int outgoingSeqNum, int incomingSeqNum) throws EngineNotFoundException
      Throws:
      EngineNotFoundException
    • getConfig

      public Properties getConfig()
      Gets FIX Engine's properties
    • getSenderCompIDbySession

      public String getSenderCompIDbySession(String sessionID) throws SessionNotFoundException
      Gets SenderCompID of session with specified ID.
      Specified by:
      getSenderCompIDbySession in interface FIXEngine
      Parameters:
      sessionID - session ID
      Throws:
      SessionNotFoundException - if session cannot be found.
    • getSessionIDbyCompIDs

      public String getSessionIDbyCompIDs(String senderCompID, String targetCompID) throws SessionNotFoundException
      Gets session ID by senderCompID and targetCompID.
      Specified by:
      getSessionIDbyCompIDs in interface FIXEngine
      Parameters:
      senderCompID - senderCompID
      targetCompID - targetCompID
      Returns:
      session ID string
      Throws:
      SessionNotFoundException - if session cannot be found.
    • getSessionsNumber

      public int getSessionsNumber()
      Gets number of active sessions for current FIX Engine.
      Returns:
      active sessions number
    • getTargetCompIDbySession

      public String getTargetCompIDbySession(String sessionID) throws SessionNotFoundException
      Gets TargetCompID of session with specified ID.
      Specified by:
      getTargetCompIDbySession in interface FIXEngine
      Parameters:
      sessionID - the session ID string
      Throws:
      SessionNotFoundException - if session cannot be found.
    • registerApplication

      public void registerApplication(Application application)
      Registers application in FIX Engine instance.
      Specified by:
      registerApplication in interface FIXEngine
      Parameters:
      application - the application, which will process application messages from remote FIX Engine.
    • unregisterApplication

      public void unregisterApplication()
      Unregisters application in FIX Engine instance.
      Specified by:
      unregisterApplication in interface FIXEngine
    • sendMessage

      public void sendMessage(FIXMessage message, String sessionID) throws ApplMessageTransmitException
      Put FIX message message to queue for sending to remote FIX Engine.
      Specified by:
      sendMessage in interface FIXEngine
      Parameters:
      message - the message to be sent.
      sessionID - the ID of session in which message will be sent.
      Throws:
      ApplMessageTransmitException - if the message cannot be sent to the counterparty.
    • sendMessageOutOfTurn

      public void sendMessageOutOfTurn(FIXMessage message, String sessionID) throws ApplMessageTransmitException
      Send FIXMessage to remote FIX Engine right now.
      Specified by:
      sendMessageOutOfTurn in interface FIXEngine
      Parameters:
      message - the message to be sent in FIXMessage format
      sessionID - the ID of session in which message will be sent
      Throws:
      ApplMessageTransmitException - if the message cannot be sent to the counterparty.
    • getFIXVersionBySessionID

      public FIXVersion getFIXVersionBySessionID(String sessionID) throws Exception
      Gets the FIX Protocol version ID for specified session.
      Specified by:
      getFIXVersionBySessionID in interface FIXEngine
      Parameters:
      sessionID - the session ID.
      Returns:
      the connection protocol version id string: fix40, fix41, fix42, fix43 or fix44.
      Throws:
      Exception - if the version cannot be retrieved.
    • resetSequenceNumber

      public void resetSequenceNumber(String sessionID) throws Exception
      Resets SeqNumber to 1 for session with indicated sessionID.
      Parameters:
      sessionID - ID of session
      Throws:
      Exception
    • getHeartbeatIntervalBySessionID

      public int getHeartbeatIntervalBySessionID(String sessionID) throws Exception
      Gets the FIX Protocol version ID for specified session.
      Specified by:
      getHeartbeatIntervalBySessionID in interface FIXEngine
      Parameters:
      sessionID - the session ID.
      Returns:
      the heartbeat interval in seconds.
      Throws:
      Exception - if the heartbeat interval cannot be retrieved.
    • getIncomingSequenceBySessionID

      public int getIncomingSequenceBySessionID(String sessionID) throws Exception
      Gets incoming sequence number for session with indicated sessionID.
      Specified by:
      getIncomingSequenceBySessionID in interface FIXEngine
      Parameters:
      sessionID - the ID of session.
      Throws:
      Exception - if the incoming sequence number cannot be retrieved.
    • getOutgoingSequenceBySessionID

      public int getOutgoingSequenceBySessionID(String sessionID) throws Exception
      Gets outgoing sequence number for session with indicated sessionID.
      Specified by:
      getOutgoingSequenceBySessionID in interface FIXEngine
      Parameters:
      sessionID - the ID of session.
      Throws:
      Exception - if the outgoing sequence number cannot be retrieved.
    • setIncomingSequence4SessionBySessionID

      public void setIncomingSequence4SessionBySessionID(String sessionID, int inSeq) throws Exception
      Sets IncomingSequence interval for session with indicated sessionID.
      Parameters:
      sessionID - ID of session
      Throws:
      Exception
    • setOutgoingSequence4SessionBySessionID

      public void setOutgoingSequence4SessionBySessionID(String sessionID, int outSeq) throws Exception
      Sets OutgoingSequence interval for session with indicated sessionID.
      Parameters:
      sessionID - ID of session
      Throws:
      Exception
    • getSessionIDByTargetCompID2

      public String getSessionIDByTargetCompID2(String targetCompID)
    • getSessionIDBySenderAndTargetCompID2

      public String getSessionIDBySenderAndTargetCompID2(String senderCompID, String targetCompID)
    • getMessageFromMessageStore

      public FIXMessage getMessageFromMessageStore(MessageDirection messageType, long seqNum, String sessionID) throws Exception
      Retrieves FIX Message from the Message Storage.
      Specified by:
      getMessageFromMessageStore in interface FIXEngine
      Parameters:
      messageType - the type of message (1 - incoming, 2 - outgoing)
      seqNum - the sequence number of the message.
      sessionID - the ID of session, from which the message will be retrieved.
      Returns:
      the retrieved connection message.
      Throws:
      Exception - if message cannot be retrieved or parsed.
    • isSessionActive

      public boolean isSessionActive(String sessionID) throws Exception
      Checks if session is online.
      Specified by:
      isSessionActive in interface FIXEngine
      Parameters:
      sessionID - the session ID string.
      Returns:
      true if session is online.
      Throws:
      Exception - if session cannot be found.
    • addGlobalEventListener

      public void addGlobalEventListener(EventListener eventListener)
      Description copied from interface: FIXEngine
      Adds global event listener for listening all sessions.
      Specified by:
      addGlobalEventListener in interface FIXEngine
      Parameters:
      eventListener - the event listener implementation.
    • removeGlobalEventListener

      public boolean removeGlobalEventListener(EventListener eventListener)
      Description copied from interface: FIXEngine
      Removes global event listener for listening all session.
      Specified by:
      removeGlobalEventListener in interface FIXEngine
      Parameters:
      eventListener - the event listener implementation.
    • addEventListener

      public void addEventListener(String sessionID, EventListener eventListener)
      Description copied from interface: FIXEngine
      Adds event listener for listening specified session.
      Specified by:
      addEventListener in interface FIXEngine
      Parameters:
      sessionID - the ID of session, which will be listened.
      eventListener - the event listener implementation.
    • removeEventListener

      public boolean removeEventListener(String sessionID, EventListener eventListener)
      Description copied from interface: FIXEngine
      Removes event listener for listening specified session.
      Specified by:
      removeEventListener in interface FIXEngine
      Parameters:
      sessionID - the ID of session, which will be listened.
      eventListener - the event listener implementation.
    • getSessions

      public List<ExtendedFIXSession> getSessions()