TickLoader API
Writing Messages
Use TickLoader API to create loaders write into TimeBase streams.
- Pass
loadingOptions()
and callcreateLoader()
. Refer to public repository to learn more about loading options. - Use
loader.send()
method to send your messages to the loader. - Call
loader.close()
function once writing is completed.
- Java
- Python
LoadingOptions options = new LoadingOptions();
try (TickLoader<InstrumentMessage> loader = changeStream.createLoader(options)) {
loader.send(message);
}
# Create BestBidOffer message
barMessage = tbapi.InstrumentMessage()
# Define message type name according to the Timebase schema type name
barMessage.typeName = 'deltix.timebase.api.messages.BarMessage'
barMessage.symbol = 'AAPL'
barMessage.open = 10.0
barMessage.close = 20.0
#...
with stream.tryLoader(tbapi.LoadingOptions()) as loader:
loader.send(barMessage)
info
Refer to code samples to view more examples.
Writing Raw Data
Loaders can write messages already bound to native classes or raw messages (unbound).
options.raw = true;
info
Refer to Data Encoding for more information about encoding and decoding messages.
Writing Modes
TimeBase can be seen as a chronologically arranged pieces of data. In relation to that, TimeBase offers several different data writing modes that can be set in LoadingOptions.writeMode
when creating a new loader:
info
Stream truncation - operation that removes all messages with timestamps that are either equal or newer than the timestamp of the incoming message.
- REWRITE
- APPEND
- TRUNCATE
- INSERT
When you start writing, the stream is always truncated by the timestamp of the first incoming message (which may have an out of sequence timestamp).
To write all the following messages into a stream, they must go in a chronological order (e.g. T1, T2. T3 ...).
With all the following messages, stream is truncated if the incoming message has a timestamp that is older that the last recorded message.
Refer to Data Distribution.
- Java
- Python
//rewrite
options.writeMode = WriteMode.REWRITE;
//append
options.writeMode = WriteMode.APPEND;
//truncate
options.writeMode = WriteMode.TRUNCATE;
//insert
options.writeMode = WriteMode.INSERT;
#reqrite
options = tbapi.LoadingOptions()
options.writeMode = tbapi.WriteMode('REWRITE')
#append
options = tbapi.LoadingOptions()
options.writeMode = tbapi.WriteMode('APPEND')
#truncate
options = tbapi.LoadingOptions()
options.writeMode = tbapi.WriteMode('TRUNCATE')
#insert
options = tbapi.LoadingOptions()
options.writeMode = tbapi.WriteMode('INSERT')
Writing Into Spaces
In case you plan to work with data that is not chronologically arranged, you can create dedicated data partitions (spaces) to physically distribute TS files based on their time range or other criteria.
- Java
- Python
options.space = "mySpace";
options = tbapi.LoadingOptions()
options.space = 'myspace'
info
- Refer to Data Distribution for more information about working with spaces.
- Refer to TickCursor API for more information about reading from spaces.
- Refer to How To to learn more about spaces and how to work with them.
Event Listener
Loaders write messages asynchronously. loader.send()
will not therefore, tell whether a specific message has been recorded successfully or not. You can add an Event Listener to a loader to get (track) possible errors.
loader.addEventListener((e) -> System.out.println(e.getMessage()));
Use Error Actions to set a behavior for specific error types:
NotifyAndContinue
- throw exception in case of an error. Writing continues. Default behavior.NotifyAndAbort
- throw exception in case of an error. Writing is aborted.Continue
- continue writing in case of an error.
options.addErrorAction(LoadingError.class, LoadingOptions.ErrorAction.NotifyAndAbort);
options.addErrorAction(OutOfSequenceMessageException.class, LoadingOptions.ErrorAction.NotifyAndContinue);
options.addErrorAction(SkipMessageException.class, LoadingOptions.ErrorAction.Continue);
To remove event listener:
loader.removeEventListener(listener);
Subscription Listener
Subscription listener notifies loaders about changes in cursors' subscriptions on the specific stream the loader is writing into.
loader.addSubscriptionListener(listener);
loader.removeSubscriptionListener(listener);
info
Refer to Dynamic Subscription Change for more information about working with cursors' subscriptions.
On-Demand Data Flushing
In some rare cases, e.g. when data is written to a stream throughout an extensive time period, you can use loader.flush()
to save all written data on disk. Data flushing is a sync operation.