Alpha Trading System EMAPI Market Data Feed Adapter Sample

This sample demonstrates the use of the TIBCO StreamBase® Adapter for Alpha EMAPI Market Data Feed. See Alpha Trading Systems EMAPI Market Data Feed Adapter for details on the use and structure of this two-part adapter.

Running This Sample in StreamBase Studio

  1. Double-click to open the sample application, AlphaEMAPIMDFSample.sbapp.

  2. Select the Alpha MDF adapter and select the Adapter Properties tab. Fill in the required information with your user ID, Server address, and other information required to connect to your Alpha Systems Trading infrastructure.

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

  4. The adapter subscribes to all the symbols your account is configured with, and emits all public order book flows.

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

Recovery from Network or System Interruption

This sample demonstrates how the adapter and an application can be configured to recover from a system restart, or network interruption and replay all market data from the start of the day. The StreamBase application keeps a record of the sequenceNum for each flow and sequenceStream pair (all replayable Alpha streams have these fields included in their outputs). This sample keeps a complete copy of each public order flow tuple by using a CSV writer adapter in the OrderBookLog module. Note that the CSV Writer adapter in this module is configured to roll over once daily.

During normal operation as public order book data is received, the maximum sequenceNum for each flow and sequenceStream pair is kept in the in-memory Query Table named RecoveryTable.

If a network interruption occurs, the MDF adapter sends a status tuple of type CONNECTION and Action DISCONNECTED. When this occurs, the Recovery module reads all rows from the RecoveryTable and sends a ReplayFlow command for each row. When all rows have been sent, a connect command is sent. This places the adapter in a mode where it will continue to try to connect every Reconnect Wait Interval seconds. Once reconnected, it will request Alpha to send all market data messages since the last seen sequenceNum for each of the flow and sequenceStream pairs sent in the ReplayFlow commands. In this way, no market data messages are lost and no duplicate messages need be retransmitted from Alpha.

When the sample application starts, it reads all rows received from Alpha for the current trading day. The first start of the day, there will be no data present and the Recovery module just issues a connect command to the adapter. The adapter replays all market data messages from the beginning of the Alpha Trading Systems day.

If a system interruption occurs during the trading day, when the sample is restarted it reads each row of market data on start up and emits them on the PublicOrderBookFlow output. Once this is complete, it sends the appropriate ReplayFlow messages, followed by a connect message, to the adapter. In this way all messages of the day are resent, although it is possible there may be some duplicate messages. Messages that were received, but not yet persisted by the CSV writer adapter when the system interruption occurred will be resent from the Alpha Trading system. By configuring the CSV writer adapter to sync on each write, the likelihood of duplicate messages is very small. Note, however, the sync on write configuration has significant write performance implications.

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. Use StreamBase Studio to set up the Alpha MDF adapter properties as described in the previous section.

  2. Open two terminal windows on UNIX, or two StreamBase Command Prompt s on Windows. In each window, navigate to your workspace copy of the sample, as described above.

  3. In window 1, type:

    sbd AlphaEMAPIMDFSample.sbapp

  4. In window 2, type:

    sbc dequeue -v

    This window now displays the public order book flow tuples

  5. By starting the application suspended you can connect the dequeuer and see all tuples emitted from the application. By shutting down, or killing an sbd running the AlphaEMAPIMDFSample.sbapp and restarting the application suspended, you can connect the dequeuer and see all tuples emitted from the application. In this way, and using the businessSequenceNum for each businessSequenceStream, you can confirm no market data is lost or duplicated from a server restart.

Importing This Sample into StreamBase Studio

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

  • From the top menu, click FileLoad StreamBase Sample.

  • Select this sample from the Embedded Input Adapters list.

  • 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 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_alpha-emapi-mdf

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/alpha-emapi-mdf

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.