TickDB API
TickDB - a top-level API. TickDB API allows connecting to TimeBase, creating and managing streams, and running data queries.
info
Refer to code Samples.
Connect to TimeBase Server
Connect to either local or remote TimeBase Server to start working with TimeBase. We have a special dxtick
protocol that works on top of TCP to connect to TimeBase server.
- Java
- Python
//connection to TimeBase server
String connectionUrl = "dxtick://localhost:8011";
DXTickDB db = TickDBFactory.createFromUrl(connectionUrl);
//connection to TimeBase server with UAC
String connectionUrl = "dxtick://localhost:8011";
DXTickDB db = TickDBFactory.createFromUrl(connectionUrl, "username", "password");
#connection to TimeBase server
timebase = 'dxtick://localhost:8011'
db = dxapi.TickDb.createFromUrl(timebase)
db.open(False)
#connection to TimeBase server with UAC
timebase = 'dxtick://localhost:8011'
db = dxapi.TickDb.createFromUrl(timebase, 'user', 'password')
db.open(False)
Working with Streams
TickDB allows working with TimeBase as with a collection of streams and offers methods to manage them. You can get a stream or a list of streams by a unique stream key identifier:
- Java
- Python
//get stream
DXTickStream stream = db.getStream("ticks");
//get a list of streams"
DXTickStream[] streams = db.listStreams();
#get stream
stream = db.getStream('ticks')
#get a list of streams
streams = db.listStreams()
Let's now create a stream. To do that, invoke createStream()
and pass all the necessary parameters in StreamOptions
.
- Java
- Python
StreamOptions options = StreamOptions.fixedType(StreamScope.DURABLE, streamName, "My Bar Messages Stream", 0, descriptor);
TickStream stream = db.createStream("BarStreamKey", options);
options = dxapi.StreamOptions()
options.name = key
options.description = key
options.scope = dxapi.StreamScope('DURABLE')
options.metadata = schema # xml schema of stream
db.createStream(key, options)
Each stream has a unique schema (message class definitions), represented by a RecordClassDescriptor (descriptor
in the code example) class or a collection of RecordClassDescriptor classes in case of a polymorphic stream. Refer to RecordClassDescriptor to learn how to create and initialize descriptor.
info
- Refer to Basic Concepts for more information about TimeBase main concepts.
- Refer to Streams for more information about streams.
- Refer to Messages for more information about messages.
Data Queries
TickDB allows reading data from multiple streams, according to the specified options, using select()
. You can filter data by startTimestamp, types, entities, and streams. It is possible to change data filters on the fly. Refer to Dynamic Subscription Change to learn more.
- Java
- Python
try (TickCursor cursor = db.select(startTimestamp, selectionOptions, types, entities, streams)) {
// iterate cursor
}
with db.trySelect(timestamp, streams, options, types, entities) as cursor:
# iterate cursor
while cursor.next():
message = cursor.getMessage()
TickDB also allows running QQL queries using executeQuery()
method.
- Java
- Python
try (InstrumentMessageSource cursor = db.executeQuery("select * from bars")) {
// iterate cursor
}
with db.tryExecuteQuery('select * from bars1min') as cursor:
# iterate cursor
while cursor.next():
message = cursor.getMessage()
Both methods have a vast variety of overloaded versions with different parameters such as time, identities, message types filters and more.
info
- Refer to QQL Tutorial for more information about the TimeBase query language.
- Refer to Cursors for more information about
cursor
andInstrumentMessageSource
.