Contents
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.
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.
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:
-
Open
fix.sbapp
in StreamBase Studio. -
Click on the FIX Output Adapter named
FIXOutput_1
in the EventFlow editor. -
In the StreamBase Properties view's Adapter Properties tab, in the FIX Engine drop-down control, select the StreamBaseFIX engine.
-
In the FIX Configuration File control, select
StreamBaseFIX-config-1.xml
. -
Make the same changes for the FIX Output Adapter named
FIXOutput_2
, this time selectingStreamBaseFIX-config-2.xml
as the FIX Configuration File. -
Save the
fix.sbapp
file before running.
-
In the Package Explorer, double-click to open the sample application,
fix.sbapp
. -
Click the Run button. This opens the SB Test/Debug perspective and starts the application.
-
In the SB Test/Debug Perspective, open the Application Output view.
-
Look for tuples emitted on the
AdminMsgFromFIXAdapter_1
andAdminMsgFromFIXAdapter_2
streams to indicate that Logon messages (MsgType=A) are exchanged. -
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.)
-
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. -
In the Manual Input view, select the Commands stream. Enter the following values and click
:-
Command:
ResetSession
-
BeginString:
FIX.4.2
-
SenderCompID:
FIXAdapter_1
-
TargetCompID:
FIXAdapter_2
-
-
Observe the Logout and Logon messages in each adapter's admin-level message stream, signifying that the connection is being reset.
-
When done, press F9 or click the Stop Running Application button.
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.
-
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.
-
In window 1, type:
sbd fix.sbapp
-
In window 2, type:
sbc dequeue -v
This window will display tuples dequeued from the adapter's output ports.
-
Observe in window 2 that tuples are emitted from the
stream.NOSMsgFromFixOutput_1
-
After a New Order Single message has been emitted from the
NOSMsgFromFixOutput_1
stream, observe that an Execution Report tuple is emitted on theExecutionReportMsgFromFIXAdapter_2
port. -
In window 3, type:
echo ResetSession,FIX.4.2,FIXAdapter_1,FIXAdapter_2,null,null | sbc enqueue Commands
-
Observe in window 2 that Logout and Logon tuples (MsgType=5 and MsgType=A, respectively) are emitted on the
AdminMsgFromFIXAdapter_1
andAdminMsgFromFIXAdapter_2
streams, indicating that the session is being reset. -
In window 3, type the following command to terminate the server and dequeuer:
sbadmin shutdown
In StreamBase Studio, import this sample with the following steps:
-
From the top menu, select
→ . -
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.
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 the permission problems that can occur when trying to work with the initially installed location of the sample. The default workspace location for this sample is:
studio-workspace
/sample_adapter_embedded_fix
See Default Installation
Directories for the 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 location of streambase-install-dir
on your system. This location
may require administrator privileges for write access, depending on your platform.