Contents
This document is for developers building StreamBase applications who want to add one or more input streams of Opentick data to the application. It presumes familiarity with using StreamBase embedded adapters and with the Opentick API.
The StreamBase Opentick adapter allows Opentick data to be brought into a StreamBase application. The adapter sends requests to an Opentick server, converts the resulting messages into StreamBase tuples, then sends those tuples downstream.
The Opentick adapter is set up and specified by means of a configuration file. Each instance of the adapter must be configured for its intended use with an instance-specific configuration file. You must configure:
-
How the adapter connects to an Opentick server.
-
One or more output ports, and the data format of each port.
-
At least one static data request or control stream input.
You can optionally configure:
-
One or more static data requests to be sent to the Opentick server.
-
One or more inputs for control streams, on which the adapter instance can accept dynamic requests.
A request is a specification for a particular type and format of data to be submitted by an instance of the Opentick adapter to an Opentick server.
The Opentick adapter can be configured to use static or dynamic data requests. Static requests are specified in the adapter's configuration file; they run when the adapter starts, and continue to run as long as the adapter is running. By contrast, dynamic requests are sent to a running adapter in an ad hoc fashion. To accept a dynamic request, the adapter must be configured to have one or more control streams, as described in Enabling Control Streams.
An instance of the Opentick adapter can be set up to use either static or dynamic requests, or both, according to the needs of your StreamBase application.
You can add more than one instance of the Opentick adapter to a StreamBase application. Each instance has its own set of input and output ports, and its own set of static and dynamic requests. Data that arrives as a result of a request is handled only by the adapter instance that initiated the request. Each instance of the adapter has its own configuration and behaves independently of other instances.
There is one exception to the independence of adapter instances: that only one connection to an Opentick server is created for all adapter instances in the same StreamBase application. One instance of the Opentick adapter creates this connection, and the other instances share it. This does not mean that adapter instances share requests, or the results of requests; only the Opentick connection is shared.
At some point in the running of a StreamBase application with multiple Opentick adapter instances, one of the adapter instances will open the connection to the server. This implies that the configuration file elements used to connect to the Opentick server must be identical in each instance of the adapter in the same StreamBase application, so that whichever instance happens to open the connection, it is opened the same way.
To use an Opentick adapter instance in StreamBase Studio, follow these steps:
-
Create a configuration file for your adapter instance as decribed in Configuring the StreamBase Opentick Adapter.
-
Test and validate your configured adapter instance independent of StreamBase Studio.
-
Import the tested configuration file into your StreamBase project.
-
Drag an icon for the Opentick adapter from the Global Adapters palette to the EventFlow canvas.
-
Click the new input adapter icon on the canvas to view its properties. In the Adapter Settings tab, specify the name of the imported configuration file.
The behavior of the Opentick adapter is controlled with a XML-based configuration file, which holds four types of configuration elements:
-
Server Connection Elements, which specify how to connect to an Opentick server.
-
Output Port Elements, which specify an adapter instance's set of output ports and their schemas.
-
Static Data Request Elements, which specify the format of static data requests sent to the Opentick server.
-
Enabling Control Streams, which set up an adapter instance to receive dynamic data requests.
The configuration file is a simple non-schema XML format with a top-level element
<sb-opentick-adapter-config> enclosing a number of
configuration elements. The four categories of configuration elements are discussed
in the following subsections.
Four elements in the Opentick configuration file set up the connection to an Opentick server:
| Configuration element | Attributes | Value |
|---|---|---|
<username>
|
None | Login name on the Opentick server. Go to www.opentick.com to sign up for an account. |
<password>
|
None |
Password for <username>
|
<hostAndPort>
|
hostName, port
|
hostName = fully qualified domain name for the
Opentick server. port = TCP port on that server
|
<loginTimeout>
|
None | Integer representing the number of milliseconds the Opentick adapter waits while attempting to log in to an Opentick server. |
All four elements are required in order to make a connection with an Opentick
server. There must be one and only one <username>
and <password> entry in each configuration file.
These elements are used as parameters in a call to OTGenericClient.login() in the Opentick API.
There must be at least one <hostAndPort> element;
there can be more than one, for example, to specify separate connections to the
same server on different ports, or to specify separate connections to different
servers. Each entry is used in a call to OTGenericClient.addHost().
The <loginTimeout> element is used to time out
attempts to log in to an Opentick server. If the timeout value is reached, the
Opentick adapter shuts down. In this case, the adapter can be restarted from the
command prompt using the command sbadmin restart
adapterName. There must be one <loginTimeout> element in the configuration file; there is no
default value.
When the Opentick adapter receives an Opentick message, it formats that message as a tuple, then sends it downstream. A tuple is sent downstream on a specific port that has a specific schema. The schema of the output port is predetermined by the type of Opentick message requested. This means there must be an output port type for each incoming request type.
Output ports are specified in the configuration file with the <outputSchema> element. The value of the element corresponds to
the Opentick message type supported by the Opentick adapter, as shown in the
following table:
| Opentick request message type | Value of <outputSchema> element |
|---|---|
| OTBBO |
BBO
|
| OTExchange |
EXCHANGE
|
| OTMMQuote |
MMQUOTE
|
| OTOHLC |
OHLC
|
| OTQuote |
QUOTE
|
| OTSymbol |
SYMBOL
|
| OTTodaysOHL |
OHL_TODAY
|
| OTTrade |
TRADE
|
For example, if the Opentick adapter receives an Opentick message of type OTTrade,
then it sends this data out on a port configured with the schema specified as
TRADE.
Specify one <outputSchema> element for each type of
Opentick data of interest. Note that this does not necessarily correspond to the
number of static and dynamic data requests, because you can have multiple data
requests for the same message type, and a single request can return data of more
than one type, depending on the mask specified for that request.
If data of a certain type is received, but there is no output port schema configured for that type, then the data is discarded. Thus, for example, if a request returns trade data, but there's no output port configured for trade data, the trade data is dropped.
StreamBase Studio draws one output port on the Opentick adapter's icon
for each <outputSchema> line in the configuration
file.
<outputSchema>QUOTE</outputSchema> <outputSchema>TRADE</outputSchema> <outputSchema>MMQUOTE</outputSchema>
A configuration file that includes these elements causes Studio to draw the Opentick adapter with three output ports, each with its appropriate schema. The adapter would then send data of types OTQuote, OTTrade, and OTMMQuote downstream on these ports. Data of other types would be discarded.
Output ports are created in the same order as they appear in the configuration file. So, for the example above, the schema for quotes is on port 0, the schema for trades on port 1, and the schema for MM quotes is on port 2.
A variety of Opentick data can be requested with the Opentick adapter. The adapter creates an Opentick client, then uses this client to send requests to Opentick. The set of requests included in the configuration file are sent to Opentick when the adapter starts up.
The Opentick adapter currently supports a subset of the available Opentick
requests. These correspond to the following requests available in the Opentick
API's OTGenericClient class:
-
requestListExchanges () -
requestListSymbols (String exchange) -
requestListSymbols (String exchange, String symbol, int options) -
requestTickStream (OTDataEntity entity, int mask) -
requestHistTicks (OTDataEntity entity, int startDate, int endDate, int mask) -
requestHistData (OTDataEntity entity, int startDate, int endDate, int dataType, int interval) -
requestTickSnapshot (OTDataEntity entity, int snapshotMask)
Use the following steps to translate any of the request formats above into an element to be used in the Opentick configuration file:
-
Use the method name as the element name, but move the initial "request" to an appended "Request", then lowercase the first letter. Thus,
requestListExchanges()becomes<listExchangesRequest>. Likewise,requestHistData()becomes<histDataRequest>. -
If the method takes arguments, use the same argument names above as attribute names for that element, with the same spelling.
-
Optionally include the
applicationIDattribute, which is specific to the Opentick adapter, as explained in the next paragraph.
The applicationID attribute can be optionally applied to
most <*Request> elements. Its value is an arbitrary string used as a tag to
identify data returned by that request. For example, if a request is given an
applicationID of localHistDataRequest, then each tuple that this request produces will
include a field named applicationID with a value of
localHistDataRequest. applicationID is not an available attribute for TickStreamRequests,
because there can be only one active tick stream per symbol, and the symbol name is
presumed to be a unique identifier for tuples produced from such requests.
Below is a set of static data requests, shown two ways:
-
As the request would appear in source code using the Opentick API.
-
As the same request should appear in the Opentick adapter's configuration file.
Each configuration file entry below is equivalent to the source code entry that precedes it. Long lines are shown broken for clarity, but the configuration line itself should be entered as an unbroken line in your configuration file.
| 1 |
OTGenericClient.requestListExchanges()
|
|
|
|
| 2 |
OTGenericClient.requestListSymbols("Q")
|
|
|
|
| 3 |
OTGenericClient.requestListSymbols("Q", "MS",
OTConstants.OT_LIST_SYMBOLS_ALL_TYPES)
|
|
|
|
| 4 |
OTGenericClient.requestTickStream(new
OTDataEntity("Q", "DELL"), OTConstants.OT_TICK_TYPE_ALL)
|
|
|
|
| 5 |
OTGenericClient.requestHistTicks(new OTDataEntity("Q",
"MSFT"), 1171461600, 1171462200, OTConstants.OT_TICK_TYPE_ALL)
|
|
|
|
| 6 |
OTGenericClient.requestHistData(new OTDataEntity("Q",
"GOOG"), 1171461600, 1171465200, OTConstants.OT_HIST_OHLC_TICK_BASED,
5)
|
|
|
|
| 7 |
OTGenericClient.requestTickSnapshot(new
OTDataEntity("Q", "DELL"), OTConstants.OT_TICK_TYPE_ALL)
|
|
|
Requests sent to an Opentick adapter while it is running are called dynamic requests. Dynamic requests are sent to the adapter by enqueuing them to streams. Streams created for this purpose are referred to as control streams. The use of control streams is discussed in the next section; this section describes how to enable control streams in the Opentick adapter's configuration file.
You can enable up to six different control streams in the Opentick adapter's configuration file. There is a separate control stream for each supported request type, as shown in the following table. Separate streams are necessary for each request type because each request takes a different set of arguments, which means each stream must have a different schema.
| Opentick request type | Configuration element to enable control stream |
|---|---|
<listExchangesRequest>
|
<controlStream>ListExchanges</controlStream>
|
<listSymbolsRequest>
|
<controlStream>ListSymbols</controlStream>
|
<tickStreamRequest>
|
<controlStream>TickStream</controlStream>
|
<historicalTickRequest>
|
<controlStream>HistTicks</controlStream>
|
<historicalDataRequest>
|
<controlStream>HistData</controlStream>
|
<tickSnapshotRequest>
|
<controlStream>TickSnapshot</controlStream>
|
If a control stream is enabled in the configuration file, then the Opentick adapter creates an input port for it. In StreamBase Studio, an input stream would be dragged onto the canvas and hooked up to this port, and a schema for each input stream needs to be created, using the schemas described below. The Opentick adapter verifies that the schema for a each control stream has the fields that it expects.
Control streams are created in the order that they appear in the configuration
file. For example, if the HistData control stream appears first in the
configuration file, then the Opentick adapter creates its port first. When an input
stream is hooked up to this port, the Opentick adapter validates that this input
stream has the schema expected for a HistData control stream, including fields
named command, applicationID,
exchange, symbol, startDate, endDate, interval and mask.
Dynamic requests are enqueued onto control streams using the sbc command. Each control stream must include the set of fields that can be used as arguments in the request type that it supports.
The tables in the following sections repeat the configuration lines in the long table
above that establish static data requests. These are followed by the sbc command line used to create the same request dynamically, along
with the schema of the control stream. (Note that the long table above has seven
numbered sections, but there are six numbered sections below. This is because
sections 2 and 3 above describe variations of the same element, <listSymbolsRequest>).
Three of the schemas in this section include a field named command. This occurs in control streams that support both adding and
cancelling a request of the specified type. In particular, HistoricalDataRequests,
HistoricalTickRequests, and TickStreamRequests can be cancelled as well as added. So
the add or cancel operation is
specified using the command field. add and cancel are the only valid commands.
Note
When you cancel an operation, you may notice that the data inside the queued tuples becomes null. This is normal: the null tuples mark the end of the tick data request.
The examples in the rest of this section presume the control streams are given the names shown in the second column:
| Configuration element to enable control stream | Control stream name |
|---|---|
| <controlStream>ListExchanges</controlStream> |
ListExchangesStream
|
| <controlStream>ListSymbols</controlStream> |
ListSymbolsStream
|
| <controlStream>TickStream</controlStream> |
TickRequestStream
|
| <controlStream>HistTicks</controlStream> |
HistoryTickRequestStream
|
| <controlStream>HistData</controlStream> |
HistoryDataRequestStream
|
| <controlStream>TickSnapshot</controlStream> |
SnapshotRequestStream
|
| 1 |
|
|
|
Where the control schema is:
| applicationID | string |
| 2 |
|
|
|
Where the control schema is:
| applicationID | string |
| exchange | string |
| symbol | string |
| options | string |
In this example, the values for symbol and options are specified as null, so that all
symbols in the Q exchange (NASDAQ) are returned.
| 4 |
|
|
|
Where the control schema is:
| command | string |
| exchange | string |
| symbol | string |
| mask | string |
| 5 |
|
|
|
Where the control schema is:
| command | string |
| applicationID | string |
| exchange | string |
| symbol | string |
| startDate | string |
| endDate | string |
| mask | string |
| 6 |
|
|
|
Where the control schema is:
| command | string |
| applicationID | string |
| exchange | string |
| symbol | string |
| startDate | string |
| endDate | string |
| mask | string |
| interval | string |
| 7 |
|
|
|
Where the control schema is:
| applicationID | string |
| exchange | string |
| symbol | string |
| mask | string |
