FIX Adapter Sample

This sample demonstrates the use of the TIBCO StreamBase® Input and Output Adapters for FIX. See FIX Adapter for details on the use and structure of these adapters.

About This Sample

This sample uses four FIX adapters (two Input-Output pairs) to simulate two separate counterparties communicating using the FIX protocol. The application uses one FIX Input adapter (FIXInput_1) and one FIX Output adapter (FIXOutput_1), linked to share their FIX connection, to act as the connection initiator. The second FIX adapter pair (FIXInput_2 and FIXOutput_2) acts as the connection acceptor.

Note

In a typical StreamBase application, both FIX counterparties would not be running in the same process as they do in this sample. A more likely scenario would have one or more FIX adapters connected to FIX venues outside your company. However, for the purpose of this sample, keeping everything in one application improves clarity and ease of use.

In the sample application, the FIXOutput_1 adapter periodically sends a New Order Single (MsgType="D") FIX message to the FIX target, FIXInput_2. On receiving this message, the target routes it to the appropriate output port based on the settings in its Message Routing Map. In this case, messages of MsgType g are routed to port 2.

Note

While this message is valid from a FIX protocol standpoint (that is, all required fields are set), it is not necessarily complete. This message is meant to demonstrate how to send messages and how to route them to specific ports on the receiving side.

When the New Order Single message is received, an Execution Report (MsgType="8") message is generated and sent back to FIXInput_1.

FIX engines supported by this sample

The sample application is configured to be run using the QuickFIX/J FIX engine, but you can easily use the StreamBaseFIX FIX engine to run it instead (provided you have the appropriate license to do so). To change the application to use this engine, follow these steps:

  1. Open fix.sbapp in StreamBase Studio.

  2. Click on the FIX Output Adapter named FIXOutput_1 in the EventFlow editor.

  3. In the StreamBase Properties view's Adapter Properties tab, in the FIX Engine drop-down control, select the StreamBaseFIX engine.

  4. In the FIX Configuration File control, select StreamBaseFIX-config-1.xml.

  5. Make the same changes for the FIX Output Adapter named FIXOutput_2, this time selecting StreamBaseFIX-config-2.xml as the FIX Configuration File.

  6. Save the fix.sbapp file before running.

Running This Sample in StreamBase Studio

  1. In the Package Explorer, double-click to open the sample application, fix.sbapp.

  2. Click the Run button. This opens the SB Test/Debug perspective and starts the application.

  3. In the SB Test/Debug Perspective, open the Application Output view.

  4. Look for tuples emitted on the AdminMsgFromFIXAdapter_1 and AdminMsgFromFIXAdapter_2 streams to indicate that Logon messages (MsgType=A) are exchanged.

  5. Also look for tuples being emitted every five seconds on the NOSMsgFromFixOutput_1 stream, indicating that FIX messages of type D are sent from FIXOutput_1 to FIXInput_2. The messages are routed to that port instead of the first port because the FIXInput_2 adapter is configured to route all application level messages of type D to the second port (and all others to port 1.)

  6. Once a New Order Single message has been generated, look for an Execution Report (MsgType='8') response to be sent back from FIXOutput_2. You will see this message being received by the ExecutionReportMsgFromFIXAdapter_2 stream.

  7. In the Manual Input view, select the Commands stream. Enter the following values and click Send Data:

    • Command: ResetSession

    • BeginString: FIX.4.2

    • SenderCompID: FIXAdapter_1

    • TargetCompID: FIXAdapter_2

  8. Observe the Logout and Logon messages in each adapter's admin-level message stream, signifying that the connection is being reset.

  9. When done, press F9 or click the Stop Running Application button.

Running This Sample in Terminal Windows

This section describes how to run the sample in UNIX terminal windows or Windows command prompt windows. On Windows, be sure to use the StreamBase Command Prompt from the Start menu as described in the Test/Debug Guide, not the default command prompt.

  1. Open three terminal windows on UNIX, or three StreamBase Command Prompts on Windows. In each window, navigate to the directory where the sample is installed, or to your workspace copy of the sample, as described above.

  2. In window 1, type:

    sbd fix.sbapp
  3. In window 2, type:

    sbc dequeue -v

    This window will display tuples dequeued from the adapter's output ports.

  4. Observe in window 2 that tuples are emitted from the NOSMsgFromFixOutput_1 stream.

  5. After a New Order Single message has been emitted from the NOSMsgFromFixOutput_1 stream, observe that an Execution Report tuple is emitted on the ExecutionReportMsgFromFIXAdapter_2 port.

  6. In window 3, type:

    echo ResetSession,FIX.4.2,FIXAdapter_1,FIXAdapter_2,null,null | sbc enqueue Commands
  7. Observe in window 2 that Logout and Logon tuples (MsgType=5 and MsgType=A, respectively) are emitted on the AdminMsgFromFIXAdapter_1 and AdminMsgFromFIXAdapter_2 streams, indicating that the session is being reset.

  8. In window 3, type the following command to terminate the server and dequeuer:

    sbadmin shutdown

Importing This Sample into StreamBase Studio

In StreamBase Studio, import this sample with the following steps:

  • From the top menu, select FileLoad StreamBase Sample.

  • In the search field, type fix to narrow the list of samples.

  • The FIX Adapter sample appears in more than one category. Select FIX adapter from any of its categories.

  • Click OK.

StreamBase Studio creates a project for this sample.

Sample Location

When you load the sample into StreamBase Studio, Studio copies the sample project's files to your Studio workspace, which is normally part of your home directory, with full access rights.

Important

Load this sample in StreamBase Studio, and thereafter use the Studio workspace copy of the sample to run and test it, even when running from the command prompt.

Using the workspace copy of the sample avoids permission problems. The default workspace location for this sample is:

studio-workspace/sample_adapter_embedded_fix

See Default Installation Directories for the default location of studio-workspace on your system.

In the default TIBCO StreamBase installation, this sample's files are initially installed in:

streambase-install-dir/sample/adapter/embedded/fix

See Default Installation Directories for the default location of studio-workspace on your system.